Просмотр исходного кода

add (suggested) ISF display option on the Apple Watch.

Pierre L 3 лет назад
Родитель
Сommit
6fc743e6f7

+ 3 - 0
FreeAPS/Sources/Modules/WatchConfig/WatchConfigStateModel.swift

@@ -6,6 +6,7 @@ enum AwConfig: String, JSON, CaseIterable, Identifiable, Codable {
     case HR
     case BGTarget
     case steps
+    case isf
 
     var displayName: String {
         switch self {
@@ -15,6 +16,8 @@ enum AwConfig: String, JSON, CaseIterable, Identifiable, Codable {
             return "Heart Rate"
         case .steps:
             return "Steps"
+        case .isf:
+            return "ISF"
         }
     }
 }

+ 2 - 0
FreeAPS/Sources/Services/WatchManager/WatchManager.swift

@@ -100,6 +100,8 @@ final class BaseWatchManager: NSObject, WatchManager, Injectable {
             self.state.eventualBG = eBG.map { "⇢ " + $0 }
             self.state.eventualBGRaw = eBG
 
+            self.state.isf = self.suggestion?.isf
+
             self.sendState()
         }
     }

+ 1 - 0
FreeAPSWatch WatchKit Extension/DataFlow.swift

@@ -21,6 +21,7 @@ struct WatchState: Codable {
     var eventualBG: String?
     var eventualBGRaw: String?
     var displayOnWatch: AwConfig?
+    var isf: Decimal?
 }
 
 struct TempTargetWatchPreset: Codable, Identifiable {

+ 10 - 0
FreeAPSWatch WatchKit Extension/Views/MainView.swift

@@ -169,6 +169,16 @@ struct MainView: View {
                             .foregroundColor(.white)
                             .minimumScaleFactor(0.5)
                     }
+                case .isf:
+                    Spacer()
+                    HStack {
+                        Text("💉" + " \(state.isf ?? 0)")
+                            .fontWeight(.regular)
+                            .font(.caption2)
+                            .scaledToFill()
+                            .foregroundColor(.white)
+                            .minimumScaleFactor(0.5)
+                    }
                 }
             }
             Spacer()

+ 4 - 0
FreeAPSWatch WatchKit Extension/WatchStateModel.swift

@@ -8,6 +8,7 @@ enum AwConfig: String, CaseIterable, Identifiable, Codable {
     case HR
     case BGTarget
     case steps
+    case isf
 }
 
 class WatchStateModel: NSObject, ObservableObject {
@@ -52,6 +53,8 @@ class WatchStateModel: NSObject, ObservableObject {
     @Published var timerDate = Date()
     @Published var pendingBolus: Double?
 
+    @Published var isf: Decimal?
+
     private var lifetime = Set<AnyCancellable>()
     private var confirmationTimeout: AnyCancellable?
     let timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
@@ -168,6 +171,7 @@ class WatchStateModel: NSObject, ObservableObject {
         lastUpdate = Date()
         eventualBG = state.eventualBG ?? ""
         displayOnWatch = state.displayOnWatch ?? .BGTarget
+        isf = state.isf
     }
 }