GithubHelp home page GithubHelp logo

colormeterkit's Introduction

ColorMeterKit: ColorMeter SDK For Swift

English

封装了 ColorMeter 设备的蓝牙命令, 如: 测量, 校准, 读取仪器信息, 设置仪器的显示参数和容差参数等. 同时也提供了简单色彩模式转换的功能, 提供 RGB, Lab, XYZ 模式相互转换的方法

由于蓝牙通信是较为复杂的异步操作, 相关的蓝牙命令都使用 RxSwift 库封装成了可观察对象, 便于操作

Requirements

  • Xcode 12.x

  • Swift 5.x

Installation

目前只支持 Swift Package Manager 的安装方式

usage

import UIKit
import ColorMeterKit
import RxSwift
import CoreBluetooth

class ViewController: UIViewController {
	let cm = CMKit()
	var scanDisposable: Disposable?
	var peripherals: [CBPeripheral] = []
	
	// 扫描设备并将发现的设备添加到 peripherals 数组中
	func scan() {
		if !cm.isScanning {
			peripherals = []
			cm.startScan()
			scanDisposable = cm.observeScanned().subscribe(onNext: { [weak self] state in
      	if let strongSelf = self, let peripheral = state.peripheral {
      		// 发现设备
      		strongSelf.peripherals.append(peripheral)
      	}
      })
		}
	}
	
	// 停止扫描
	func stopScan() {
		if cm.isScanning {
			scanDisposable?.dispose()
			cm.stopScan()
		}
	}
	
	// 连接指定设备
	func connect(index: Int) {
		_ = cm.connect(peripherals[index]).subscribe(onNext: { state in
    	// todo 连接成功
    })
	}
	
	func measure() {
		_ = cm.measureWithResponse().subscribe { data in
			if let data = data {
				// todo 测量成功
			}
		} onError: { error in
			// todo 测量失败
		}
	}
}

查看 Demo: ColorMeterKitDemo

colormeterkit's People

Contributors

chenlongming avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.