Skip to content

Commit 640e45f

Browse files
authored
Fixing the watch description (#103)
1 parent 2be6d40 commit 640e45f

File tree

9 files changed

+116
-48
lines changed

9 files changed

+116
-48
lines changed

Loop.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
43E2D9191D222759004DA55F /* LoopKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43F78D4B1C914197002152D1 /* LoopKit.framework */; };
125125
43E3449F1B9D68E900C85C07 /* StatusTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43E3449E1B9D68E900C85C07 /* StatusTableViewController.swift */; };
126126
43E344A41B9E1B1C00C85C07 /* NSUserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43E344A31B9E1B1C00C85C07 /* NSUserDefaults.swift */; };
127+
43EA285F1D50ED3D001BC233 /* GlucoseTrend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA285E1D50ED3D001BC233 /* GlucoseTrend.swift */; };
128+
43EA28601D50ED4D001BC233 /* GlucoseTrend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA285E1D50ED3D001BC233 /* GlucoseTrend.swift */; };
129+
43EA28621D517E42001BC233 /* SensorDisplayable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EA28611D517E42001BC233 /* SensorDisplayable.swift */; };
127130
43EB40861C82646A00472A8C /* StatusChartManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43EB40851C82646A00472A8C /* StatusChartManager.swift */; };
128131
43EDDBF31C361C75007D89B5 /* xDripG5.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 43EDDBF11C361C75007D89B5 /* xDripG5.framework */; };
129132
43F41C331D3A17AA00C11ED6 /* ChartAxisValueDoubleUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F41C321D3A17AA00C11ED6 /* ChartAxisValueDoubleUnit.swift */; };
@@ -339,6 +342,8 @@
339342
43E2D90F1D20C581004DA55F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
340343
43E3449E1B9D68E900C85C07 /* StatusTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = StatusTableViewController.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
341344
43E344A31B9E1B1C00C85C07 /* NSUserDefaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSUserDefaults.swift; sourceTree = "<group>"; };
345+
43EA285E1D50ED3D001BC233 /* GlucoseTrend.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlucoseTrend.swift; sourceTree = "<group>"; };
346+
43EA28611D517E42001BC233 /* SensorDisplayable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SensorDisplayable.swift; sourceTree = "<group>"; };
342347
43EB40851C82646A00472A8C /* StatusChartManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusChartManager.swift; sourceTree = "<group>"; };
343348
43EDDBF01C361C75007D89B5 /* CommonCrypto.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CommonCrypto.framework; path = Carthage/Build/iOS/CommonCrypto.framework; sourceTree = "<group>"; };
344349
43EDDBF11C361C75007D89B5 /* xDripG5.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = xDripG5.framework; path = Carthage/Build/iOS/xDripG5.framework; sourceTree = "<group>"; };
@@ -457,6 +462,7 @@
457462
438849ED1D2A1EBB003B3F23 /* MLabService.swift */,
458463
430DA58F1D4B0E4C0097D1CA /* MySentryPumpStatusMessageBody.swift */,
459464
438849E91D297CB6003B3F23 /* NightscoutService.swift */,
465+
43EA28611D517E42001BC233 /* SensorDisplayable.swift */,
460466
437CCADF1D285C7B0075D2C3 /* ServiceAuthentication.swift */,
461467
434F54601D28859B002A9274 /* ServiceCredential.swift */,
462468
43C418B41CE0575200405B6A /* ShareGlucose+GlucoseKit.swift */,
@@ -550,6 +556,7 @@
550556
children = (
551557
435400301C9F744E00D5819C /* BolusSuggestionUserInfo.swift */,
552558
43DE92581C5479E4001FFDE1 /* CarbEntryUserInfo.swift */,
559+
43EA285E1D50ED3D001BC233 /* GlucoseTrend.swift */,
553560
435400331C9F878D00D5819C /* SetBolusUserInfo.swift */,
554561
43DE925B1C547A20001FFDE1 /* WatchContext.swift */,
555562
);
@@ -987,6 +994,7 @@
987994
43E344A41B9E1B1C00C85C07 /* NSUserDefaults.swift in Sources */,
988995
43649A631C7A347F00523D7F /* CollectionType.swift in Sources */,
989996
437CEEBE1CD6E0CB003C8C80 /* LoopCompletionHUDView.swift in Sources */,
997+
43EA28621D517E42001BC233 /* SensorDisplayable.swift in Sources */,
990998
435400321C9F745500D5819C /* BolusSuggestionUserInfo.swift in Sources */,
991999
43E3449F1B9D68E900C85C07 /* StatusTableViewController.swift in Sources */,
9921000
43DBF0531C93EC8200B3C386 /* DeviceDataManager.swift in Sources */,
@@ -1032,6 +1040,7 @@
10321040
436FACEE1D0BA636004E2427 /* InsulinDataSource.swift in Sources */,
10331041
439897371CD2F80600223065 /* AnalyticsManager.swift in Sources */,
10341042
4346D1F61C78501000ABAFE3 /* ChartPoint.swift in Sources */,
1043+
43EA28601D50ED4D001BC233 /* GlucoseTrend.swift in Sources */,
10351044
438849EE1D2A1EBB003B3F23 /* MLabService.swift in Sources */,
10361045
43F4EF1D1BA2A57600526CE1 /* DiagnosticLogger.swift in Sources */,
10371046
432E73CB1D24B3D6009AD15D /* RemoteDataManager.swift in Sources */,
@@ -1059,6 +1068,7 @@
10591068
4328E02B1CFBE2C500E199AA /* WKAlertAction.swift in Sources */,
10601069
4328E0281CFBE2C500E199AA /* CLKComplicationTemplate.swift in Sources */,
10611070
4328E01E1CFBE25F00E199AA /* AddCarbsInterfaceController.swift in Sources */,
1071+
43EA285F1D50ED3D001BC233 /* GlucoseTrend.swift in Sources */,
10621072
4328E0261CFBE2C500E199AA /* IdentifiableClass.swift in Sources */,
10631073
43DE925A1C5479E4001FFDE1 /* CarbEntryUserInfo.swift in Sources */,
10641074
4328E0301CFBFAEB00E199AA /* NSTimeInterval.swift in Sources */,

Loop/Managers/WatchDataManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class WatchDataManager: NSObject, WCSessionDelegate {
107107
context.loopLastRunDate = lastLoopCompleted
108108
context.recommendedBolusDose = units
109109

110-
if let trend = self.deviceDataManager.sensorInfo?.trendDescription {
110+
if let trend = self.deviceDataManager.sensorInfo?.trendType {
111111
context.glucoseTrend = trend
112112
}
113113

Loop/Models/GlucoseG4.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,11 @@ extension GlucoseG4: SensorDisplayable {
3939
}
4040
}
4141

42+
var trendType: GlucoseTrend? {
43+
return GlucoseTrend(rawValue: Int(trend))
44+
}
45+
4246
var trendDescription: String {
43-
switch trend {
44-
case 1: return ""
45-
case 2: return ""
46-
case 3: return ""
47-
case 4: return ""
48-
case 5: return ""
49-
case 6: return ""
50-
case 7: return ""
51-
default: return ""
52-
}
47+
return trendType?.description ?? ""
5348
}
5449
}

Loop/Models/GlucoseRxMessage.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@ import Foundation
1010
import xDripG5
1111

1212

13-
protocol SensorDisplayable {
14-
// Describes the state of the sensor in the current localization
15-
var stateDescription: String { get }
16-
17-
// Describes the trend of the sensor values in the current localization
18-
var trendDescription: String { get }
19-
}
20-
21-
2213
extension GlucoseRxMessage: SensorDisplayable {
2314
var stateDescription: String {
2415
let status: String
@@ -34,25 +25,34 @@ extension GlucoseRxMessage: SensorDisplayable {
3425
return String(format: "%1$02x %2$@", state, status)
3526
}
3627

37-
var trendDescription: String {
28+
var trendType: GlucoseTrend? {
3829
guard trend < Int8.max else {
39-
return ""
30+
return nil
4031
}
4132

42-
let direction: String
4333
switch trend {
44-
case let x where x < -10:
45-
direction = ""
46-
case let x where x < 0:
47-
direction = ""
48-
case let x where x > 10:
49-
direction = ""
50-
case let x where x > 0:
51-
direction = ""
34+
case let x where x <= -30:
35+
return .DownDownDown
36+
case let x where x <= -20:
37+
return .DownDown
38+
case let x where x <= -10:
39+
return .Down
40+
case let x where x < 10:
41+
return .Flat
42+
case let x where x < 20:
43+
return .Up
44+
case let x where x < 30:
45+
return .UpUp
5246
default:
53-
direction = ""
47+
return .UpUpUp
48+
}
49+
}
50+
51+
var trendDescription: String {
52+
guard let trendType = trendType else {
53+
return ""
5454
}
5555

56-
return String(format: NSLocalizedString("%1$d %2$@", comment: "The format string describing the G5 sensor trend (1: The raw trend value)(2: The direction arrow)"), trend, direction)
56+
return String(format: NSLocalizedString("%1$d %2$@", comment: "The format string describing the G5 sensor trend (1: The raw trend value)(2: The direction arrow)"), trend, trendType.description)
5757
}
5858
}

Loop/Models/MySentryPumpStatusMessageBody.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,26 @@ extension MySentryPumpStatusMessageBody: SensorDisplayable {
2222
}
2323
}
2424

25-
var trendDescription: String {
25+
var trendType: GlucoseTrend? {
2626
guard case .Active = glucose else {
27-
return ""
27+
return nil
2828
}
2929

3030
switch glucoseTrend {
31-
case .Flat:
32-
return ""
33-
case .Up:
34-
return ""
35-
case .UpUp:
36-
return ""
3731
case .Down:
38-
return ""
32+
return .Down
3933
case .DownDown:
40-
return ""
34+
return .DownDown
35+
case .Up:
36+
return .Up
37+
case .UpUp:
38+
return .UpUp
39+
case .Flat:
40+
return .Flat
4141
}
4242
}
43+
44+
var trendDescription: String {
45+
return trendType?.description ?? ""
46+
}
4347
}

Loop/Models/SensorDisplayable.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// SensorDisplayable.swift
3+
// Loop
4+
//
5+
// Created by Nate Racklyeft on 8/2/16.
6+
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
7+
//
8+
9+
10+
protocol SensorDisplayable {
11+
// Describes the state of the sensor in the current localization
12+
var stateDescription: String { get }
13+
14+
/// Enumerates the trend of the sensor values
15+
var trendType: GlucoseTrend? { get }
16+
17+
// Describes the trend of the sensor values in the current localization
18+
var trendDescription: String { get }
19+
}

WatchApp Extension/Controllers/StatusInterfaceController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class StatusInterfaceController: ContextInterfaceController {
5050
dispatch_async(dispatch_get_main_queue()) {
5151
if let glucose = context?.glucose, unit = context?.preferredGlucoseUnit {
5252
let glucoseValue = glucose.doubleValueForUnit(unit)
53-
let trend = context?.glucoseTrend ?? ""
53+
let trend = context?.glucoseTrend?.description ?? ""
5454

5555
self.glucoseLabel.setText((numberFormatter.stringFromNumber(glucoseValue) ?? "") + trend)
5656
self.glucoseLabel.setHidden(false)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// GlucoseTrend.swift
3+
// Loop
4+
//
5+
// Created by Nate Racklyeft on 8/2/16.
6+
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
7+
//
8+
9+
10+
enum GlucoseTrend: Int {
11+
case UpUpUp = 1
12+
case UpUp = 2
13+
case Up = 3
14+
case Flat = 4
15+
case Down = 5
16+
case DownDown = 6
17+
case DownDownDown = 7
18+
19+
var description: String {
20+
switch self {
21+
case UpUpUp:
22+
return ""
23+
case UpUp:
24+
return ""
25+
case Up:
26+
return ""
27+
case Flat:
28+
return ""
29+
case Down:
30+
return ""
31+
case DownDown:
32+
return ""
33+
case DownDownDown:
34+
return ""
35+
}
36+
}
37+
}

WatchApp Extension/Models/WatchContext.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WatchContext: NSObject, RawRepresentable {
1818
var preferredGlucoseUnit: HKUnit?
1919

2020
var glucose: HKQuantity?
21-
var glucoseTrend: String?
21+
var glucoseTrend: GlucoseTrend?
2222
var eventualGlucose: HKQuantity?
2323
var glucoseDate: NSDate?
2424

@@ -56,7 +56,10 @@ class WatchContext: NSObject, RawRepresentable {
5656
eventualGlucose = HKQuantity(unit: unit, doubleValue: glucoseValue)
5757
}
5858
}
59-
glucoseTrend = rawValue["gt"] as? String
59+
60+
if let rawTrend = rawValue["gt"] as? Int {
61+
glucoseTrend = GlucoseTrend(rawValue: rawTrend)
62+
}
6063
glucoseDate = rawValue["gd"] as? NSDate
6164

6265
IOB = rawValue["iob"] as? Double
@@ -87,7 +90,7 @@ class WatchContext: NSObject, RawRepresentable {
8790
raw["gv"] = glucose?.doubleValueForUnit(unit)
8891
}
8992

90-
raw["gt"] = glucoseTrend
93+
raw["gt"] = glucoseTrend?.rawValue
9194
raw["gd"] = glucoseDate
9295
raw["iob"] = IOB
9396
raw["ld"] = loopLastRunDate
@@ -97,4 +100,4 @@ class WatchContext: NSObject, RawRepresentable {
97100

98101
return raw
99102
}
100-
}
103+
}

0 commit comments

Comments
 (0)