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

@@ -0,0 +1,58 @@
//
// BeepConfigCommand.swift
// OmniKit
//
// Created by Joseph Moran on 5/12/19.
// Copyright © 2019 Pete Schwamb. All rights reserved.
//
import Foundation

public struct BeepConfigCommand : MessageBlock {
// https://github.com/openaps/openomni/wiki/Command-1E-Beep-Config
public let blockType: MessageBlockType = .beepConfig
public let length: UInt8 = 4
public let beepType: UInt8
This conversation was marked as resolved by ps2

This comment has been minimized.

Copy link
@ps2

ps2 May 13, 2019

Owner

UInt8 -> BeepType

This comment has been minimized.

Copy link
@itsmojo

This comment has been minimized.

Copy link
@ps2

ps2 May 14, 2019

Owner

Thanks Joe!

public let basalCompletionBeep: Bool
public let basalIntervalBeep: TimeInterval
public let tempBasalCompletionBeep: Bool
public let tempBasalIntervalBeep: TimeInterval
public let bolusCompletionBeep: Bool
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.basalCompletionBeep = basalCompletionBeep
self.basalIntervalBeep = basalIntervalBeep
self.tempBasalCompletionBeep = tempBasalCompletionBeep
self.tempBasalIntervalBeep = tempBasalIntervalBeep
self.bolusCompletionBeep = bolusCompletionBeep
self.bolusIntervalBeep = bolusIntervalBeep
}

public init(encodedData: Data) throws {
if encodedData.count < 6 {
throw MessageBlockError.notEnoughData
}
self.beepType = encodedData[2]
self.basalCompletionBeep = encodedData[3] & (1<<6) != 0
self.basalIntervalBeep = TimeInterval(minutes: Double(encodedData[3] & 0x3f))
self.tempBasalCompletionBeep = encodedData[4] & (1<<6) != 0
self.tempBasalIntervalBeep = TimeInterval(minutes: Double(encodedData[4] & 0x3f))
self.bolusCompletionBeep = encodedData[5] & (1<<6) != 0
self.bolusIntervalBeep = TimeInterval(minutes: Double(encodedData[5] & 0x3f))
}

public var data: Data {
var data = Data(bytes: [
blockType.rawValue,
length
])
data.append(beepType)
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))
return data
}
}
@@ -30,6 +30,7 @@ public enum MessageBlockType: UInt8 {
case setInsulinSchedule = 0x1a
case deactivatePod = 0x1c
case statusResponse = 0x1d
case beepConfig = 0x1e
case cancelDelivery = 0x1f

public var blockType: MessageBlock.Type {
@@ -62,6 +63,8 @@ public enum MessageBlockType: UInt8 {
return StatusResponse.self
case .tempBasalExtra:
return TempBasalExtraCommand.self
case .beepConfig:
return BeepConfigCommand.self
case .cancelDelivery:
return CancelDeliveryCommand.self
case .faultConfig:
@@ -25,17 +25,6 @@ public enum BeepRepeat: UInt8 {
case every5Minutes = 8
}

public enum BeepType: UInt8 {
case noBeep = 0
case beepBeepBeepBeep = 1
case bipBeepBipBeepBipBeepBipBeep = 2
case bipBip = 3
case beep = 4
case beepBeepBeep = 5
case beeeeeep = 6
case bipBipBipbipBipBip = 7
case beeepBeeep = 8
} // Reused in CancelDeliveryCommand

public struct AlertConfiguration {

@@ -58,8 +47,6 @@ public struct AlertConfiguration {
self.beepRepeat = beepRepeat
self.beepType = beepType
}


}

public enum PodAlert: CustomStringConvertible, RawRepresentable, Equatable {
@@ -0,0 +1,28 @@
//
// BeepType.swift
// OmniKit
//
// Created by Joseph Moran on 5/12/19.
// Copyright © 2019 Pete Schwamb. All rights reserved.
//
import Foundation

// BeepType is used for the $11 Acknowledge Alerts, $19 Configure Alerts, $1E Beep Configure, and $1F Cancel Commands
public enum BeepType: UInt8 {
case noBeep = 0x0
case beepBeepBeepBeep = 0x1
case bipBeepBipBeepBipBeepBipBeep = 0x2
case bipBip = 0x3
case beep = 0x4
case beepBeepBeep = 0x5
case beeeeeep = 0x6
case bipBipBipbipBipBip = 0x7
case beeepBeeep = 0x8
// 0x9 and 0xA always return an error
case beepBeep = 0xB
case beeep = 0xC
case bipBeeeeep = 0xD
case fiveSecondBeep = 0xE // 5 second alarm beep *if* Pod is currently suspended
case beepConfig_NoBeep = 0xF // For Beep Config Command no beep, else fatal Pod fault $37
}
@@ -61,7 +61,8 @@ public struct FaultEventCode: CustomStringConvertible, Equatable {
case badValueStartupTest = 0x32
case connectedPodCommandTimeout = 0x33
case resetFromUnknownCause = 0x34
case errorFlashInitialisiation = 0x36
case errorFlashInitialization = 0x36
case badPiezoValue = 0x37
case unexpectedValueByte358 = 0x38
case problemWithLoad1and2 = 0x39
case aGreaterThan7inMessage = 0x3A
@@ -242,8 +243,10 @@ public struct FaultEventCode: CustomStringConvertible, Equatable {
return "Connected Pod command timeout"
case .resetFromUnknownCause:
return "Reset from unknown cause"
case .errorFlashInitialisiation:
case .errorFlashInitialization:
return "Flash initialization error"
case .badPiezoValue:
return "Bad piezo value"
case .unexpectedValueByte358:
return "Unexpected byte_358 value"
case .problemWithLoad1and2:
@@ -1,5 +1,5 @@
//
// eventErrorCode.swift
// LogEventErrorCode.swift
// OmniKit
//
// Created by Eelke Jager on 22/10/2018.
@@ -490,6 +490,8 @@ public class PodCommsSession {

public func testingCommands() throws {
let _ = try getStatus()
// uncomment the next line to enable pod check alarms
// let _ = try checkAlarms()
}

public func setTime(timeZone: TimeZone, basalSchedule: BasalSchedule, date: Date) throws -> StatusResponse {
@@ -536,7 +538,18 @@ public class PodCommsSession {
podState.updateFromStatusResponse(response)
return response
}


public func checkAlarms() throws -> StatusResponse {
var response: StatusResponse

response = try send([BeepConfigCommand(beepType: .bipBeepBipBeepBipBeepBipBeep)])
podState.updateFromStatusResponse(response)
// Could use .fiveSecondBeep for PDM style "Check alarms", but this can only be successfully used if pod is suspended
response = try send([BeepConfigCommand(beepType: .beeeeeep)])
podState.updateFromStatusResponse(response)
return response
}

public func deactivatePod() throws {

if podState.fault == nil && !podState.suspended {
@@ -587,6 +600,3 @@ extension PodCommsSession: MessageTransportDelegate {
podState.messageTransportState = state
}
}



@@ -614,6 +614,8 @@
C1FFB02421343EC200C50C1D /* OmniKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C1FFAF78213323CC00C50C1D /* OmniKit.framework */; };
C1FFB02521343F0300C50C1D /* LoopKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43FB610B20DDF55F002B996B /* LoopKit.framework */; };
C1FFB02621343F0600C50C1D /* LoopKitUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43FB610A20DDF55E002B996B /* LoopKitUI.framework */; };
D807D7D82289135D006BCDF0 /* BeepType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D807D7D72289135D006BCDF0 /* BeepType.swift */; };
D807D7DA228913EC006BCDF0 /* BeepConfigCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = D807D7D9228913EC006BCDF0 /* BeepConfigCommand.swift */; };
E95D0660215D76E40072157B /* PodInfoFlashLogRecent.swift in Sources */ = {isa = PBXBuildFile; fileRef = E95D065F215D76E40072157B /* PodInfoFlashLogRecent.swift */; };
E993D18C217E455000E489BF /* LogEventErrorCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = E993D18B217E455000E489BF /* LogEventErrorCode.swift */; };
E9C06B262150371700B602AD /* PodInfoConfiguredAlerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9C06B252150371700B602AD /* PodInfoConfiguredAlerts.swift */; };
@@ -1512,6 +1514,8 @@
C1FFB0072133242C00C50C1D /* OmniKitUI.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = OmniKitUI.xcassets; sourceTree = "<group>"; };
C1FFB0082133242C00C50C1D /* OmnipodSettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OmnipodSettingsViewController.swift; sourceTree = "<group>"; };
C1FFB00C2133242C00C50C1D /* OmnipodPumpManagerSetupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OmnipodPumpManagerSetupViewController.swift; sourceTree = "<group>"; };
D807D7D72289135D006BCDF0 /* BeepType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeepType.swift; sourceTree = "<group>"; };
D807D7D9228913EC006BCDF0 /* BeepConfigCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeepConfigCommand.swift; sourceTree = "<group>"; };
E95D065F215D76E40072157B /* PodInfoFlashLogRecent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PodInfoFlashLogRecent.swift; sourceTree = "<group>"; };
E993D18B217E455000E489BF /* LogEventErrorCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogEventErrorCode.swift; sourceTree = "<group>"; };
E9C06B252150371700B602AD /* PodInfoConfiguredAlerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PodInfoConfiguredAlerts.swift; sourceTree = "<group>"; };
@@ -2224,6 +2228,7 @@
C13FD2F5215E743C005FC495 /* PodProgressStatus.swift */,
E993D18B217E455000E489BF /* LogEventErrorCode.swift */,
C11166AD2180D834000EEAAB /* AlertSlot.swift */,
D807D7D72289135D006BCDF0 /* BeepType.swift */,
);
path = Model;
sourceTree = "<group>";
@@ -2568,6 +2573,7 @@
C1FFAFA6213323E800C50C1D /* TempBasalExtraCommand.swift */,
C1FFAFA4213323E800C50C1D /* VersionResponse.swift */,
C11F6B7D21C9646300752BBC /* FaultConfigCommand.swift */,
D807D7D9228913EC006BCDF0 /* BeepConfigCommand.swift */,
);
path = MessageBlocks;
sourceTree = "<group>";
@@ -3875,6 +3881,7 @@
C13BD643214033E5006D7F19 /* UnfinalizedDose.swift in Sources */,
C1FFAFD1213323E900C50C1D /* ConfigureAlertsCommand.swift in Sources */,
C1FFAFBE213323E900C50C1D /* CRC16.swift in Sources */,
D807D7DA228913EC006BCDF0 /* BeepConfigCommand.swift in Sources */,
C1FFAFCD213323E900C50C1D /* ConfigurePodCommand.swift in Sources */,
E9EE3370214ED01200888876 /* PodInfoFaultEvent.swift in Sources */,
E9E54AB421542E8A00E319B8 /* PodInfoResetStatus.swift in Sources */,
@@ -3883,6 +3890,7 @@
C1FFB01921332A7100C50C1D /* IdentifiableClass.swift in Sources */,
C1FFAFC1213323E900C50C1D /* Notification.swift in Sources */,
C1FFAFC0213323E900C50C1D /* CRC8.swift in Sources */,
D807D7D82289135D006BCDF0 /* BeepType.swift in Sources */,
E9EDD477215BED3500A103D1 /* PodInfoTester.swift in Sources */,
C1FFAFCB213323E900C50C1D /* BasalScheduleExtraCommand.swift in Sources */,
C1CB13A521383F1E00F9EEDA /* LocalizedString.swift in Sources */,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.