Skip to content

Display a glucose chart on the Watch#772

Closed
bharat wants to merge 62 commits into
LoopKit:devfrom
bharat:dev-watch-sk
Closed

Display a glucose chart on the Watch#772
bharat wants to merge 62 commits into
LoopKit:devfrom
bharat:dev-watch-sk

Conversation

@bharat
Copy link
Copy Markdown

@bharat bharat commented Aug 5, 2018

This is a collaboration with Eric Jensen (@elnjensen).

This change introduces a glucose chart in the Loop watch app. It preserves the existing interface but allows the user to swipe between two different experiences - the original one that is action-oriented and allows the user to add carbs and trigger a bolus, and a new one that shows the glucose chart.

The user can adjust the y-axis (blood glucose) using the crown, and the x-axis (hours of visible data) by using 3D touch on the chart. Here are a couple of videos to demo the experience:

Y-axis: https://www.youtube.com/watch?v=pD0UrJlqB5o
X-axis: https://www.youtube.com/watch?v=mRudZmTTQyM&feature=youtu.be

Implementation notes:

  • Load glucose data from GlucoseKit on the watch
  • If there's a gap in data, backfill with data from the phone
  • Refactor common interface support into HUDInterfaceController base class
  • Pause the SpriteKit scene when there's no new data or running animations
  • The size of the scene is hardcoded in the Storyboard and in the code

Open questions:

  • See the note in ChartHUDController.awake - any thoughts on the root cause issue here?
  • GlucoseChartScene relies on a bunch of new extensions to create more readable code. Most of these could be private to the file but would appreciate some guidance on whether these should move out into their own files
  • Are the new image assets added correctly?
  • Is there a better way to go about determining the size of the scene? It appears that you cannot get any details back from a WKInterfaceSKScene, would appreciate guidance here.

@elnjensen did I miss anything?

Bharat Mediratta and others added 30 commits June 29, 2018 15:56
This incorporates a ton of fine work by Eric Jensen, but I've squashed
it down into a single commit for ease of management.

The watch now has two discrete pages, one which is the standard actions
based interface, the second is an information interface which shows the
IOB, COB, basal rate and a glucose chart.

Glucose data is read from HealthKit on the watch. Sometimes this lags
behind so we also make requests to backfill glucose data as
necessary. We're also minimizing the amount of data sent over BLE as
much as possible since BLE is slow and less reliable.
@elnjensen
Copy link
Copy Markdown
Contributor

elnjensen commented Aug 6, 2018

One other small open question - the code that implements the actions from the force-touch menu is quite redundant, but I can't see a way to make it simpler. The menu items don't appear to be able to pass any information to the corresponding action function, e.g. there's no equivalent of the tag property of a UIButton that can let a single function know which button was pressed. Not a big deal, but let us know if you see a better way to do this.

Another question - Loop returns nil for the case of zero COB. Is best practice to display "COB 0 g", or to remove the COB label entirely in that case?

@jlucasvt
Copy link
Copy Markdown
Contributor

jlucasvt commented Aug 7, 2018

screen shot 2018-08-07 at 11 00 22 am

Not sure of the details just yet but I am getting this error when running the updated watch code and it kills the loop app when it's hit. I am going to uninstall the watch app and reinstall to see if there is some bad previous data.

-Just Uninstalled Watch app and Reinstalled same issue is present. when watch tries to update predicted glucose the values throw fatal exception and poof. Loop quits. :)

@elnjensen
Copy link
Copy Markdown
Contributor

elnjensen commented Aug 7, 2018

@jlucasvt You might be hitting that error when it's trying to convert a negative value to an unsigned integer. Unlike real glucose values, predicted glucose can be negative... Try changing both instances of UInt16 in that file to Int16 and see if that fixes the problem. Do you think your forecast was dipping negative when you got that error?

@jlucasvt
Copy link
Copy Markdown
Contributor

jlucasvt commented Aug 7, 2018

Makes sense Loop thinks Im on a crash course to -bg.. (Just had a Cannula Change and Needed to enter some fake carbs and a bolus to get the site wet..) BG is dropping and loop predicts a fast and hard landing.. (i got glucose tabs if it gets rough)

  • That fixed it. (good to check for those - values)
    1

@bharat
Copy link
Copy Markdown
Author

bharat commented Aug 8, 2018

ha! that never occurred to me. thank you for beta testing!! I just pushed Eric's suggested fix which should resolve this.

@shanselman
Copy link
Copy Markdown
Contributor

Is this in a good place where I could merge it into my own build? Is this getting merged anytime soon?

@elnjensen
Copy link
Copy Markdown
Contributor

@shanselman You can merge from my branch dev-watch-sk-ej, which is based on Loop 1.9.1 but not yet updated for 1.9.2 changes. No idea about timescale on this PR.

@ps2 ps2 mentioned this pull request Oct 5, 2018
@ps2
Copy link
Copy Markdown
Collaborator

ps2 commented Oct 5, 2018

Accepting this, and adding some tweaks as #824

@ps2 ps2 closed this Oct 5, 2018
@bharat bharat deleted the dev-watch-sk branch October 12, 2018 23:07
@Kdisimone Kdisimone mentioned this pull request Oct 17, 2018
loopkitdev pushed a commit to loopkitdev/Loop that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants