Created
July 9, 2020 02:28
-
-
Save AminPlusPlus/e23def8f8aa80f668b2239fe87ce96d7 to your computer and use it in GitHub Desktop.
WriteValue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate var ledMask: UInt8 = 0 | |
fileprivate let digitalBits = 2 | |
func setDigitalOutput(_ index: Int, on: Bool, characteristic :CBCharacteristic) { | |
let shift = UInt(index) * UInt(digitalBits) | |
var mask = ledMask | |
if on { | |
mask = mask | UInt8(1 << shift) | |
} | |
else { | |
mask = mask & ~UInt8(1 << shift) | |
} | |
let data = Data(bytes: [mask]) | |
self.peripheral?.writeValue(data, for: characteristic, type: .withResponse) | |
ledMask = mask | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment