Skip to content

Commit adf306c

Browse files
authored
Merge pull request loopandlearn#393 from loopandlearn/charging-indicator
Display charging indicator
2 parents 3d1f6a8 + 887494a commit adf306c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

LoopFollow/Controllers/Nightscout/DeviceStatus.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension MainViewController {
3636
self.evaluateNotLooping()
3737
}
3838
}
39-
39+
4040
func evaluateNotLooping() {
4141
guard let statusStackView = LoopStatusLabel.superview as? UIStackView else { return }
4242

@@ -88,10 +88,10 @@ extension MainViewController {
8888
TaskScheduler.shared.rescheduleTask(id: .deviceStatus, to: Date().addingTimeInterval(5 * 60))
8989
return
9090
}
91-
91+
9292
//Process the current data first
9393
let lastDeviceStatus = jsonDeviceStatus[0] as [String : AnyObject]?
94-
94+
9595
//pump and uploader
9696
let formatter = ISO8601DateFormatter()
9797
formatter.formatOptions = [.withFullDate,
@@ -110,10 +110,16 @@ extension MainViewController {
110110

111111
if let uploader = lastDeviceStatus?["uploader"] as? [String: AnyObject],
112112
let upbat = uploader["battery"] as? Double {
113-
infoManager.updateInfoData(type: .battery, value: String(format: "%.0f", upbat) + "%")
113+
let batteryText: String
114+
if let isCharging = uploader["isCharging"] as? Bool, isCharging {
115+
batteryText = "⚡️ " + String(format: "%.0f", upbat) + "%"
116+
} else {
117+
batteryText = String(format: "%.0f", upbat) + "%"
118+
}
119+
infoManager.updateInfoData(type: .battery, value: batteryText)
114120
UserDefaultsRepository.deviceBatteryLevel.value = upbat
115-
let timestamp = uploader["timestamp"] as? Date ?? Date()
116121

122+
let timestamp = uploader["timestamp"] as? Date ?? Date()
117123
let currentBattery = DataStructs.batteryStruct(batteryLevel: upbat, timestamp: timestamp)
118124
deviceBatteryData.append(currentBattery)
119125

@@ -162,7 +168,7 @@ extension MainViewController {
162168
// Start the timer based on the timestamp
163169
let now = dateTimeUtils.getNowTimeIntervalUTC()
164170
let secondsAgo = now - UserDefaultsRepository.alertLastLoopTime.value
165-
171+
166172
DispatchQueue.main.async {
167173
if secondsAgo >= (20 * 60) {
168174
TaskScheduler.shared.rescheduleTask(

0 commit comments

Comments
 (0)