Skip to content
Closed
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
28 changes: 27 additions & 1 deletion Loop/Managers/WatchDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ final class WatchDataManager: NSObject, WCSessionDelegate {
context.recommendedBolusDose = state.recommendedBolus?.recommendation.amount
context.maxBolus = manager.settings.maximumBolus

let updateGroup = DispatchGroup()

updateGroup.enter()
manager.doseStore.insulinOnBoard(at: Date()) {(result) in
// This function completes asynchronously, so below
// is a completion that returns a value after eventual
// function completion.
switch result {
case .success(let iobValue):
context.IOB = iobValue.value
case .failure:
context.IOB = nil
}
updateGroup.leave()
}

if let cobValue = state.carbsOnBoard {
context.COB = cobValue.quantity.doubleValue(for: HKUnit.gram())
} else {
// we expect state.carbsOnBoard to be nil if value is zero:
context.COB = 0.0
}

if let glucoseTargetRangeSchedule = manager.settings.glucoseTargetRangeSchedule {
if let override = glucoseTargetRangeSchedule.override {
context.glucoseRangeScheduleOverride = GlucoseRangeScheduleOverrideUserInfo(
Expand All @@ -146,7 +169,10 @@ final class WatchDataManager: NSObject, WCSessionDelegate {
context.glucoseTrendRawValue = trend.rawValue
}

completion(context)
updateGroup.notify(queue: DispatchQueue.global(qos: .background)) {
completion(context)
}

}
}
}
Expand Down
39 changes: 39 additions & 0 deletions WatchApp Extension/Controllers/StatusInterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,46 @@ final class StatusInterfaceController: WKInterfaceController, ContextUpdatable {
}

// TODO: Other elements
let insulinFormatter: NumberFormatter = {
let numberFormatter = NumberFormatter()

numberFormatter.numberStyle = .decimal
numberFormatter.minimumFractionDigits = 1
numberFormatter.maximumFractionDigits = 1

return numberFormatter
}()

statusLabel.setHidden(true)
var statusLabelText = ""

if let activeInsulin = context?.IOB, let valueStr = insulinFormatter.string(from:NSNumber(value:activeInsulin))
{
statusLabelText = String(format: NSLocalizedString(
"IOB %1$@ U",
comment: "The subtitle format describing units of active insulin. (1: localized insulin value description)"),
valueStr)
}

if let carbsOnBoard = context?.COB
{
let carbFormatter = NumberFormatter()
carbFormatter.numberStyle = .decimal
carbFormatter.maximumFractionDigits = 0
let valueStr = carbFormatter.string(from:NSNumber(value:carbsOnBoard))

if statusLabelText != "" { // Not empty - add carriage return
statusLabelText += "\n"
}
statusLabelText += String(format: NSLocalizedString(
"COB %1$@ g",
comment: "The subtitle format describing grams of active carbs. (1: localized carb value description)"),
valueStr!)
}

statusLabel.setText(statusLabelText)
statusLabel.setHidden(false)

}

private func updateForOverrideContext(_ context: GlucoseRangeScheduleOverrideUserInfo.Context?) {
Expand Down
14 changes: 6 additions & 8 deletions WatchApp/Base.lproj/Interface.storyboard
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="13771" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="rNf-Mh-tID">
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14109" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="rNf-Mh-tID">
<device id="watch38" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="watchOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="13756"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14031"/>
</dependencies>
<scenes>
<!--AddCarbsInterfaceController-->
Expand Down Expand Up @@ -149,16 +149,14 @@
</items>
<variation key="device=watch42mm" height="29"/>
</group>
<label width="1" alignment="center" verticalAlignment="bottom" textAlignment="center" id="PI8-dB-Ykw">
<label alignment="center" verticalAlignment="bottom" textAlignment="left" numberOfLines="0" id="PI8-dB-Ykw">
<fontDescription key="font" style="UICTFontTextStyleCaption1"/>
</label>
</items>
</group>
</items>
</group>
<group width="1" height="0.080000000000000002" alignment="left" id="rSt-1g-97T">
<variation key="device=watch42mm" height="0.10000000000000001"/>
</group>
<group width="1" height="7" alignment="left" id="rSt-1g-97T"/>
<group width="1" height="0.59999999999999998" alignment="center" verticalAlignment="bottom" id="VU2-MR-CSd">
<items>
<group width="0.5" alignment="left" layout="vertical" id="wJu-fl-xhv">
Expand Down Expand Up @@ -267,7 +265,7 @@
</connections>
</controller>
</objects>
<point key="canvasLocation" x="235" y="345"/>
<point key="canvasLocation" x="235" y="347.5"/>
</scene>
<!--BolusInterfaceController-->
<scene sceneID="vCl-Xb-hzF">
Expand Down