Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Loop/Managers/WatchDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ final class WatchDataManager: NSObject, WCSessionDelegate {

let glucose = deviceDataManager.glucoseStore?.latestGlucose
let reservoir = deviceDataManager.doseStore.lastReservoirValue
let maxBolus = deviceDataManager.maximumBolus

deviceDataManager.loopManager.getLoopStatus { (predictedGlucose, recommendedTempBasal, lastTempBasal, lastLoopCompleted, insulinOnBoard, error) in

Expand All @@ -115,6 +116,7 @@ final class WatchDataManager: NSObject, WCSessionDelegate {

context.loopLastRunDate = lastLoopCompleted
context.recommendedBolusDose = units
context.maxBolus = maxBolus

if let trend = self.deviceDataManager.sensorInfo?.trendType {
context.glucoseTrend = trend
Expand Down Expand Up @@ -155,7 +157,7 @@ final class WatchDataManager: NSObject, WCSessionDelegate {
switch message["name"] as? String {
case CarbEntryUserInfo.name?:
addCarbEntryFromWatchMessage(message) { (units) in
replyHandler(BolusSuggestionUserInfo(recommendedBolus: units ?? 0).rawValue)
replyHandler(BolusSuggestionUserInfo(recommendedBolus: units ?? 0, maxBolus: self.deviceDataManager.maximumBolus).rawValue)
}
case SetBolusUserInfo.name?:
if let bolus = SetBolusUserInfo(rawValue: message) {
Expand Down
18 changes: 13 additions & 5 deletions WatchApp Extension/Controllers/BolusInterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ final class BolusInterfaceController: WKInterfaceController, IdentifiableClass {
}
}

private var maxBolusValue: Double = 15

private func pickerValueFromBolusValue(bolusValue: Double) -> Int {
switch bolusValue {
case let bolus where bolus > 10:
Expand Down Expand Up @@ -71,15 +69,25 @@ final class BolusInterfaceController: WKInterfaceController, IdentifiableClass {
super.awakeWithContext(context)

let maxPickerValue: Int
var maxBolusValue: Double = 15
let pickerValue: Int

if let context = context as? BolusSuggestionUserInfo {
maxPickerValue = pickerValueFromBolusValue(context.recommendedBolus)
let recommendedBolus = context.recommendedBolus

if let maxBolus = context.maxBolus {
maxBolusValue = maxBolus
} else if recommendedBolus > 0 {
maxBolusValue = recommendedBolus
}

maxPickerValue = pickerValueFromBolusValue(maxBolusValue)
let recommendedPickerValue = pickerValueFromBolusValue(recommendedBolus)
maxBolusValue = bolusValueFromPickerValue(maxPickerValue)
pickerValue = Int(Double(maxPickerValue) * 0.75)
pickerValue = Int(Double(recommendedPickerValue) * 0.75)
bolusValue = bolusValueFromPickerValue(pickerValue)

if let valueString = formatter.stringFromNumber(maxBolusValue) {
if let valueString = formatter.stringFromNumber(recommendedBolus) {
recommendedValueLabel.setText(String(format: NSLocalizedString("Rec: %@ U", comment: "The label and value showing the recommended bolus"), valueString).localizedUppercaseString)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ final class StatusInterfaceController: ContextInterfaceController {
}

@IBAction func setBolus() {
presentControllerWithName(BolusInterfaceController.className, context: nil)
presentControllerWithName(BolusInterfaceController.className, context: dataManager.lastContextData?.bolusSuggestion)
}

}
13 changes: 11 additions & 2 deletions WatchApp Extension/Models/BolusSuggestionUserInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import Foundation

final class BolusSuggestionUserInfo: RawRepresentable {
let recommendedBolus: Double
let maxBolus: Double?

init(recommendedBolus: Double) {
init(recommendedBolus: Double, maxBolus: Double? = nil) {
self.recommendedBolus = recommendedBolus
self.maxBolus = maxBolus
}

// MARK: - RawRepresentable
Expand All @@ -30,13 +32,20 @@ final class BolusSuggestionUserInfo: RawRepresentable {
}

self.recommendedBolus = recommendedBolus
self.maxBolus = rawValue["mb"] as? Double
}

var rawValue: RawValue {
return [
var raw: RawValue = [
"v": self.dynamicType.version,
"name": BolusSuggestionUserInfo.name,
"br": recommendedBolus
]

if let maxBolus = maxBolus {
raw["mb"] = maxBolus
}

return raw
}
}
11 changes: 10 additions & 1 deletion WatchApp Extension/Models/WatchContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import HealthKit
final class WatchContext: NSObject, RawRepresentable {
typealias RawValue = [String: AnyObject]

private let version = 2
private let version = 3

var preferredGlucoseUnit: HKUnit?
var maxBolus: Double?

var glucose: HKQuantity?
var glucoseTrend: GlucoseTrend?
Expand All @@ -27,6 +28,12 @@ final class WatchContext: NSObject, RawRepresentable {
var lastNetTempBasalDate: NSDate?
var recommendedBolusDose: Double?

var bolusSuggestion: BolusSuggestionUserInfo? {
guard let recommended = recommendedBolusDose else { return nil }

return BolusSuggestionUserInfo(recommendedBolus: recommended, maxBolus: maxBolus)
}

var COB: Double?
var IOB: Double?
var reservoir: Double?
Expand Down Expand Up @@ -72,6 +79,7 @@ final class WatchContext: NSObject, RawRepresentable {
lastNetTempBasalDate = rawValue["bad"] as? NSDate
recommendedBolusDose = rawValue["rbo"] as? Double
COB = rawValue["cob"] as? Double
maxBolus = rawValue["mb"] as? Double
}

var rawValue: RawValue {
Expand All @@ -94,6 +102,7 @@ final class WatchContext: NSObject, RawRepresentable {
raw["gd"] = glucoseDate
raw["iob"] = IOB
raw["ld"] = loopLastRunDate
raw["mb"] = maxBolus
raw["r"] = reservoir
raw["rbo"] = recommendedBolusDose
raw["rp"] = reservoirPercentage
Expand Down