To run the example project, clone the repo, and run pod install
from the Example directory first.
Swift 4.0, Probably iOS 10+
SBrick-iOS is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SBrick-iOS"
var manager = SBrickManager(delegate: self)
manager.startDiscovery()
func sbrickManager(_ sbrickManager: SBrickManager, didDiscover sbrick: SBrick) {
//connect
sbrick.delegate = self
sbrickManager.connect(to: sbrick)
}
func sbrickReady(_ sbrick: SBrick) {
//send a command
sbrick.send(command: .drive(channelId: 0, cw: true, power: 0xFF))
//use managed ports for simple control
sbrick.port1.drive(power: 0x80, isCW: true)
//get wedo sensor data
sbrick.send(command: .enableSensor(port: .port2))
sbrick.send(command: .querySensor(port: .port2)) { [weak self] (bytes) in
if let sensorData = SBrickSensorData(bytes: bytes) {
print("sensor type: \(sensorData.sensorType) value:\(sensorData.sensorValue)")
}
}
}
Barak Harel
SBrick-iOS is available under the MIT license. See the LICENSE file for more info.