Skip to content

Instantly share code, notes, and snippets.

@douglasjunior
Created May 21, 2015 15:02
Show Gist options
  • Save douglasjunior/0eb67d01f35516e16ad6 to your computer and use it in GitHub Desktop.
Save douglasjunior/0eb67d01f35516e16ad6 to your computer and use it in GitHub Desktop.
Exemplo de código Swift
import Foundation
import CoreBluetooth
class BluetoothWriter : NSObject {
private weak var peripheral: CBPeripheral!;
private weak var characteristic: CBCharacteristic!;
init(peripheral : CBPeripheral, characteristic:CBCharacteristic) {
self.peripheral = peripheral;
self.characteristic = characteristic;
}
func writeData(value :NSData){
if (self.peripheral != nil && self.characteristic != nil) {
self.peripheral.writeValue(value, forCharacteristic: self.characteristic, type: CBCharacteristicWriteType.WithoutResponse);
}
}
func writeString(value : NSString){
self.writeData(value.dataUsingEncoding(NSUTF8StringEncoding)!);
}
func writeColorWithRed(red : Int, green: Int, blue:Int){
self.writeString(NSString(format:"c%d,%d,%d\n",red,green,blue));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment