-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLEDResource.swift
39 lines (33 loc) · 988 Bytes
/
LEDResource.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// LEDResource.swift
// Boost
//
// Created by Dan Appel on 8/6/18.
// Copyright © 2018 Dan Appel. All rights reserved.
//
import CoreBluetooth
struct LED: GenericResourceDescription {
typealias Value = State
enum State: UInt8, DataConvertible {
case off = 0
case on = 1
var flipped: State {
switch self {
case .on: return .off
case .off: return .on
}
}
var asData: Data {
return Data([rawValue])
}
init(from data: Data) throws {
guard data.count == 1, data[0] == 0 || data[0] == 1 else {
throw DataConvertibleError.invalidData
}
self.init(rawValue: data[0])!
}
}
static let serviceId = CBUUID(string: "70DA7AB7-4FE2-4614-B092-2E8EC60290BB")
static let characteristicId = CBUUID(string: "6962CDC6-DCB1-465B-8AA4-23491CAF4840")
static let wantsNotificationsEnabled = false
}