Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BeepConfig command support, miscellaneous beep related cleanup #524

Merged
merged 2 commits into from May 14, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

Changed byteType from UInt8 to BeepType, remove unneeded length, impr…

…oved commenting
  • Loading branch information...
itsmojo committed May 14, 2019
commit 76affe01ab16fab1531c75fcf8dda9d30d09a78a
@@ -9,11 +9,11 @@
import Foundation

public struct BeepConfigCommand : MessageBlock {
// https://github.com/openaps/openomni/wiki/Command-1E-Beep-Config
// OFF 1 2 3 4 5
// 1e 04 AABBCCDD
public let blockType: MessageBlockType = .beepConfig
public let length: UInt8 = 4
public let beepType: UInt8
public let beepType: BeepType
public let basalCompletionBeep: Bool
public let basalIntervalBeep: TimeInterval
public let tempBasalCompletionBeep: Bool
@@ -22,7 +22,7 @@ public struct BeepConfigCommand : MessageBlock {
public let bolusIntervalBeep: TimeInterval

public init(beepType: BeepType, basalCompletionBeep: Bool = false, basalIntervalBeep: TimeInterval = 0, tempBasalCompletionBeep: Bool = false, tempBasalIntervalBeep: TimeInterval = 0, bolusCompletionBeep: Bool = false, bolusIntervalBeep: TimeInterval = 0) {
self.beepType = beepType.rawValue
self.beepType = beepType
self.basalCompletionBeep = basalCompletionBeep
self.basalIntervalBeep = basalIntervalBeep
self.tempBasalCompletionBeep = tempBasalCompletionBeep
@@ -35,7 +35,11 @@ public struct BeepConfigCommand : MessageBlock {
if encodedData.count < 6 {
throw MessageBlockError.notEnoughData
}
self.beepType = encodedData[2]
if let beepType = BeepType.init(rawValue: encodedData[2]) {
self.beepType = beepType
} else {
throw MessageBlockError.parseError
}
self.basalCompletionBeep = encodedData[3] & (1<<6) != 0
self.basalIntervalBeep = TimeInterval(minutes: Double(encodedData[3] & 0x3f))
self.tempBasalCompletionBeep = encodedData[4] & (1<<6) != 0
@@ -47,9 +51,9 @@ public struct BeepConfigCommand : MessageBlock {
public var data: Data {
var data = Data(bytes: [
blockType.rawValue,
length
4,
])
data.append(beepType)
data.append(beepType.rawValue)
data.append((basalCompletionBeep ? (1<<6) : 0) + (UInt8(basalIntervalBeep.minutes) & 0x3f))
data.append((tempBasalCompletionBeep ? (1<<6) : 0) + (UInt8(tempBasalIntervalBeep.minutes) & 0x3f))
data.append((bolusCompletionBeep ? (1<<6) : 0) + (UInt8(bolusIntervalBeep.minutes) & 0x3f))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.