Skip to content

Commit 8dd6243

Browse files
committed
Added Inits for ToggleByte
Nibble washable
1 parent b89d28f commit 8dd6243

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Sources/DataDecoder/Types/ANTToggleByte.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,27 @@ public struct ANTToggleByte {
3030
public var pageNumber: UInt8
3131
public var toggle: Bool
3232

33+
public var uint8Value: UInt8 {
34+
var value: UInt8 = pageNumber
35+
value |= UInt8(toggle == true ? 1 : 0) << 7
36+
37+
return UInt8(value)
38+
}
39+
3340
public init(_ value: UInt8) {
3441
self.pageNumber = (value & 0x7F)
3542
self.toggle = ((value >> 7) & 0x7F).boolValue
3643
}
44+
45+
public init(pageNumber: UInt8, toggled: Bool) {
46+
self.pageNumber = pageNumber
47+
self.toggle = toggled
48+
}
3749
}
3850

3951

4052
internal extension UInt8 {
53+
4154
var boolValue: Bool {
4255
switch self {
4356
case 0x01:

Sources/DataDecoder/Types/Nibble.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ extension Nibble: Equatable {
5151
}
5252
}
5353

54+
extension Nibble: Hashable {
55+
56+
public var hashValue: Int {
57+
return uint8Value.hashValue
58+
}
59+
}
60+
5461

5562
///MARK: - UInt8 Extension
5663
public extension UInt8 {

Tests/DataDecoderTests/DataDecoderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class DataDecoderTests: XCTestCase {
9797
("testUInt24", testUInt24),
9898
("testUInt48", testUInt48),
9999
("testIPAddress", testIPAddress),
100-
("testMACADdress", testMACADdress),
100+
("testMACADdress", testMACAddress),
101101
]
102102
}
103103
}

0 commit comments

Comments
 (0)