Skip to content

Commit f6f9c5b

Browse files
authored
Add pump battery to info display and alarm options (#496)
1 parent 4d90996 commit f6f9c5b

16 files changed

Lines changed: 93 additions & 13 deletions

File tree

LoopFollow.xcodeproj/project.pbxproj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@
197197
DDC7E5472DBD8A1600EB1127 /* AlarmEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC7E5402DBD8A1600EB1127 /* AlarmEditor.swift */; };
198198
DDC7E5CF2DC77C2000EB1127 /* SnoozerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC7E5CE2DC77C2000EB1127 /* SnoozerViewModel.swift */; };
199199
DDCC3A4B2DDBB5E4006F1C10 /* BatteryCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC3A4A2DDBB5E4006F1C10 /* BatteryCondition.swift */; };
200-
DDCC3A4D2DDBB77C006F1C10 /* BatteryAlarmEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC3A4C2DDBB77C006F1C10 /* BatteryAlarmEditor.swift */; };
200+
DDCC3A502DDED000006F1C10 /* PumpBatteryCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC3A512DDED000006F1C10 /* PumpBatteryCondition.swift */; };
201+
DDCC3A4D2DDBB77C006F1C10 /* PhoneBatteryAlarmEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC3A4C2DDBB77C006F1C10 /* PhoneBatteryAlarmEditor.swift */; };
202+
DDCC3A5B2DDE2000006F1C10 /* PumpBatteryAlarmEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC3A5C2DDE2000006F1C10 /* PumpBatteryAlarmEditor.swift */; };
201203
DDCC3A4F2DDC5B54006F1C10 /* BatteryDropCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC3A4E2DDC5B54006F1C10 /* BatteryDropCondition.swift */; };
202204
DDCC3A542DDC5D62006F1C10 /* BatteryDropAlarmEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC3A532DDC5D62006F1C10 /* BatteryDropAlarmEditor.swift */; };
203205
DDCC3A562DDC9617006F1C10 /* MissedBolusCondition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCC3A552DDC9617006F1C10 /* MissedBolusCondition.swift */; };
@@ -597,7 +599,9 @@
597599
DDC7E5402DBD8A1600EB1127 /* AlarmEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmEditor.swift; sourceTree = "<group>"; };
598600
DDC7E5CE2DC77C2000EB1127 /* SnoozerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnoozerViewModel.swift; sourceTree = "<group>"; };
599601
DDCC3A4A2DDBB5E4006F1C10 /* BatteryCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryCondition.swift; sourceTree = "<group>"; };
600-
DDCC3A4C2DDBB77C006F1C10 /* BatteryAlarmEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryAlarmEditor.swift; sourceTree = "<group>"; };
602+
DDCC3A512DDED000006F1C10 /* PumpBatteryCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PumpBatteryCondition.swift; sourceTree = "<group>"; };
603+
DDCC3A4C2DDBB77C006F1C10 /* PhoneBatteryAlarmEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneBatteryAlarmEditor.swift; sourceTree = "<group>"; };
604+
DDCC3A5C2DDE2000006F1C10 /* PumpBatteryAlarmEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PumpBatteryAlarmEditor.swift; sourceTree = "<group>"; };
601605
DDCC3A4E2DDC5B54006F1C10 /* BatteryDropCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryDropCondition.swift; sourceTree = "<group>"; };
602606
DDCC3A532DDC5D62006F1C10 /* BatteryDropAlarmEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryDropAlarmEditor.swift; sourceTree = "<group>"; };
603607
DDCC3A552DDC9617006F1C10 /* MissedBolusCondition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MissedBolusCondition.swift; sourceTree = "<group>"; };
@@ -886,6 +890,7 @@
886890
DDCC3A552DDC9617006F1C10 /* MissedBolusCondition.swift */,
887891
DDCC3A4E2DDC5B54006F1C10 /* BatteryDropCondition.swift */,
888892
DDCC3A4A2DDBB5E4006F1C10 /* BatteryCondition.swift */,
893+
DDCC3A512DDED000006F1C10 /* PumpBatteryCondition.swift */,
889894
DDB9FC7A2DDB573F00EFAA76 /* IOBCondition.swift */,
890895
DDC6CA482DD8E47A0060EE25 /* PumpVolumeCondition.swift */,
891896
DDC6CA442DD8D8E60060EE25 /* PumpChangeCondition.swift */,
@@ -1130,7 +1135,8 @@
11301135
children = (
11311136
DDCC3A572DDC9655006F1C10 /* MissedBolusAlarmEditor.swift */,
11321137
DDCC3A532DDC5D62006F1C10 /* BatteryDropAlarmEditor.swift */,
1133-
DDCC3A4C2DDBB77C006F1C10 /* BatteryAlarmEditor.swift */,
1138+
DDCC3A4C2DDBB77C006F1C10 /* PhoneBatteryAlarmEditor.swift */,
1139+
DDCC3A5C2DDE2000006F1C10 /* PumpBatteryAlarmEditor.swift */,
11341140
DDB9FC7C2DDB575300EFAA76 /* IOBAlarmEditor.swift */,
11351141
DDC6CA4A2DD8E4960060EE25 /* PumpVolumeAlarmEditor.swift */,
11361142
DDC6CA462DD8D9010060EE25 /* PumpChangeAlarmEditor.swift */,
@@ -1950,6 +1956,7 @@
19501956
DDC7E5152DBCFA7900EB1127 /* SnoozerViewController.swift in Sources */,
19511957
DD7F4C072DD5042F00D449E9 /* OverrideStartAlarmEditor.swift in Sources */,
19521958
DDCC3A4B2DDBB5E4006F1C10 /* BatteryCondition.swift in Sources */,
1959+
DDCC3A502DDED000006F1C10 /* PumpBatteryCondition.swift in Sources */,
19531960
DDDF6F492D479AF000884336 /* NoRemoteView.swift in Sources */,
19541961
656F8C142E49F3D20008DC1D /* RemoteCommandSettings.swift in Sources */,
19551962
DD12D4872E1705E6004E0112 /* AlarmsContainerView.swift in Sources */,
@@ -2065,7 +2072,8 @@
20652072
DDCC3A542DDC5D62006F1C10 /* BatteryDropAlarmEditor.swift in Sources */,
20662073
DD13BC772C3FD64E0062313B /* InfoData.swift in Sources */,
20672074
DD13BC752C3FD6210062313B /* InfoType.swift in Sources */,
2068-
DDCC3A4D2DDBB77C006F1C10 /* BatteryAlarmEditor.swift in Sources */,
2075+
DDCC3A4D2DDBB77C006F1C10 /* PhoneBatteryAlarmEditor.swift in Sources */,
2076+
DDCC3A5B2DDE2000006F1C10 /* PumpBatteryAlarmEditor.swift in Sources */,
20692077
DDC6CA492DD8E47A0060EE25 /* PumpVolumeCondition.swift in Sources */,
20702078
DD9ACA0A2D33095600415D8A /* MinAgoTask.swift in Sources */,
20712079
DD9ED0CC2D35526E000D2A63 /* SearchBar.swift in Sources */,

LoopFollow/Alarm/Alarm.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ struct Alarm: Identifiable, Codable, Equatable {
318318
case .pump:
319319
soundFile = .marimbaDescend
320320
threshold = 20
321+
case .pumpBattery:
322+
soundFile = .machineCharge
323+
threshold = 20
321324
case .battery:
322325
soundFile = .machineCharge
323326
threshold = 20
@@ -363,7 +366,7 @@ extension AlarmType {
363366
return .glucose
364367
case .iob, .cob, .missedBolus, .recBolus:
365368
return .insulin
366-
case .battery, .batteryDrop, .pump, .pumpChange,
369+
case .battery, .batteryDrop, .pump, .pumpBattery, .pumpChange,
367370
.sensorChange, .notLooping, .buildExpire:
368371
return .device
369372
case .overrideStart, .overrideEnd, .tempTargetStart, .tempTargetEnd:
@@ -385,6 +388,7 @@ extension AlarmType {
385388
case .battery: return "battery.25"
386389
case .batteryDrop: return "battery.100.bolt"
387390
case .pump: return "drop"
391+
case .pumpBattery: return "powermeter"
388392
case .pumpChange: return "arrow.triangle.2.circlepath"
389393
case .sensorChange: return "sensor.tag.radiowaves.forward"
390394
case .notLooping: return "circle.slash"
@@ -411,6 +415,7 @@ extension AlarmType {
411415
case .battery: return "Phone battery low."
412416
case .batteryDrop: return "Battery drops quickly."
413417
case .pump: return "Reservoir level low."
418+
case .pumpBattery: return "Pump battery low."
414419
case .pumpChange: return "Pump change due."
415420
case .sensorChange: return "Sensor change due."
416421
case .notLooping: return "Loop hasn’t completed."
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// LoopFollow
2+
// PumpBatteryCondition.swift
3+
4+
import Foundation
5+
6+
struct PumpBatteryCondition: AlarmCondition {
7+
static let type: AlarmType = .pumpBattery
8+
init() {}
9+
10+
func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
11+
guard let limit = alarm.threshold, limit > 0 else { return false }
12+
guard let level = data.latestPumpBattery else { return false }
13+
14+
return level <= limit
15+
}
16+
}

LoopFollow/Alarm/AlarmData.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct AlarmData: Codable {
2020
let IOB: Double?
2121
let recentBoluses: [BolusEntry]
2222
let latestBattery: Double?
23+
let latestPumpBattery: Double?
2324
let batteryHistory: [DataStructs.batteryStruct]
2425
let recentCarbs: [CarbSample]
2526
}

LoopFollow/Alarm/AlarmEditing/AlarmEditor.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ struct AlarmEditor: View {
7777
case .sensorChange: SensorAgeAlarmEditor(alarm: $alarm)
7878
case .pumpChange: PumpChangeAlarmEditor(alarm: $alarm)
7979
case .pump: PumpVolumeAlarmEditor(alarm: $alarm)
80+
case .pumpBattery: PumpBatteryAlarmEditor(alarm: $alarm)
8081
case .iob: IOBAlarmEditor(alarm: $alarm)
81-
case .battery: BatteryAlarmEditor(alarm: $alarm)
82+
case .battery: PhoneBatteryAlarmEditor(alarm: $alarm)
8283
case .batteryDrop: BatteryDropAlarmEditor(alarm: $alarm)
8384
case .missedBolus: MissedBolusAlarmEditor(alarm: $alarm)
8485
}

LoopFollow/Alarm/AlarmEditing/Editors/BatteryAlarmEditor.swift renamed to LoopFollow/Alarm/AlarmEditing/Editors/PhoneBatteryAlarmEditor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// LoopFollow
2-
// BatteryAlarmEditor.swift
2+
// PhoneBatteryAlarmEditor.swift
33

44
import SwiftUI
55

6-
struct BatteryAlarmEditor: View {
6+
struct PhoneBatteryAlarmEditor: View {
77
@Binding var alarm: Alarm
88

99
var body: some View {
1010
Group {
1111
InfoBanner(
12-
text: "This warns you when the phones battery gets low, based on the percentage you choose.",
12+
text: "This warns you when the phone's battery gets low, based on the percentage you choose.",
1313
alarmType: alarm.type
1414
)
1515

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// LoopFollow
2+
// PumpBatteryAlarmEditor.swift
3+
4+
import SwiftUI
5+
6+
struct PumpBatteryAlarmEditor: View {
7+
@Binding var alarm: Alarm
8+
9+
var body: some View {
10+
Group {
11+
InfoBanner(
12+
text: "This warns you when the pump's battery gets low, based on the percentage you choose.",
13+
alarmType: alarm.type
14+
)
15+
16+
AlarmGeneralSection(alarm: $alarm)
17+
18+
AlarmStepperSection(
19+
header: "Pump Battery Level",
20+
footer: "This alerts you when the pump battery drops below this level.",
21+
title: "Battery Below",
22+
range: 0 ... 100,
23+
step: 5,
24+
unitLabel: "%",
25+
value: $alarm.threshold
26+
)
27+
28+
AlarmActiveSection(alarm: $alarm)
29+
AlarmAudioSection(alarm: $alarm)
30+
AlarmSnoozeSection(alarm: $alarm)
31+
}
32+
}
33+
}

LoopFollow/Alarm/AlarmManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class AlarmManager {
2929
SensorAgeCondition.self,
3030
PumpChangeCondition.self,
3131
PumpVolumeCondition.self,
32+
PumpBatteryCondition.self,
3233
IOBCondition.self,
3334
BatteryCondition.self,
3435
BatteryDropCondition.self,

LoopFollow/Alarm/AlarmType/AlarmType+Snooze.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension AlarmType {
1616
.tempTargetEnd:
1717
return .minute
1818
case .battery, .batteryDrop, .sensorChange, .pumpChange, .cob, .iob,
19-
.pump:
19+
.pump, .pumpBattery:
2020
return .hour
2121
case .temporary:
2222
return .none

LoopFollow/Alarm/AlarmType/AlarmType+canAcknowledge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extension AlarmType {
1212
return true
1313
// These are alarms without memory, if they only are acknowledged - they would alarm again immediately
1414
case
15-
.batteryDrop, .missedReading, .notLooping, .battery, .buildExpire, .iob, .sensorChange, .pumpChange, .pump:
15+
.batteryDrop, .missedReading, .notLooping, .battery, .pumpBattery, .buildExpire, .iob, .sensorChange, .pumpChange, .pump:
1616
return false
1717
}
1818
}

0 commit comments

Comments
 (0)