Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Toybox.WatchUi as Ui;
- using Toybox.Application as App;
- using Toybox.Background;
- using Toybox.System as Sys;
- using Toybox.Communications as Comm;
- using Toybox.FitContributor as fit;
- class glucose_datafieldView extends Ui.SimpleDataField {
- private const TAG = "glucose_datafieldView";
- hidden var mFitContributor = null;
- // Variables for computing averages:
- hidden var lapAverage = 0.0;
- hidden var sessionAverage = 0.0;
- hidden var lapRecordCount = 0;
- hidden var sessionRecordCount = 0;
- hidden var tempSgv = null;
- var tempFlag = null;
- hidden var sgvString = "-";
- hidden var mTimerRunning = false;
- // Set the label of the data field here.
- function initialize() {
- Sys.println(TAG + "->initialize");
- SimpleDataField.initialize();
- //------------------------FIT-----------------------
- mFitContributor = new SGVFitContributor(self);
- //--------------------------------------------------
- Sys.println("FIT contributor initialized");
- label = "Blood glucose";
- App.getApp().setProperty(OSDATA, null);
- App.getApp().setProperty(FLAG,null);
- }
- function compute(info) {
- //Read object store:
- tempSgv = App.getApp().getProperty(OSDATA);
- //Check the flag:
- tempFlag = App.getApp().getProperty(FLAG);
- Sys.println(TAG + "-> compute: tempFlag = " + tempFlag + ", tempSgv = " + tempSgv + ", sessionRunning = " + mTimerRunning);
- //Check for temporal event and if the session is running:
- if(tempFlag && mTimerRunning){
- if (tempSgv != null){
- //Reset the fit contributor:
- mFitContributor = null;
- //Initialize the FIT contributor:
- mFitContributor = new SGVFitContributor(self);
- //Update session averages:
- lapRecordCount++;
- sessionRecordCount++;
- lapAverage += tempSgv.toFloat();
- sessionAverage += tempSgv.toFloat();
- mFitContributor.updateAverages(lapAverage, sessionAverage, lapRecordCount, sessionRecordCount);
- //Log new data:
- Sys.println("tempSgv = " + tempSgv);
- mFitContributor.compute(tempSgv.toFloat());
- }
- }
- //Reset the flag so that nothing happens until another temporal event occurs:
- App.getApp().setProperty(FLAG,false);
- //Return the value to be displayed in the datafield:
- if (tempSgv == "0.00" || tempSgv == null){
- sgvString = "-";
- }
- return sgvString;
- }
- function onTimerStart() {
- Sys.println(TAG + "-> onTimerStart: Session started");
- mTimerRunning = true;
- }
- function onTimerStop() {
- Sys.println(TAG + "-> onTimerStop.");
- mTimerRunning = false;
- }
- function onTimerPause() {
- Sys.println(TAG + "-> onTimerPause.");
- mTimerRunning = false;
- }
- function onTimerResume() {
- Sys.println(TAG + "-> onTimerResume.");
- mTimerRunning = true;
- }
- function onTimerLap() {
- Sys.println(TAG + "-> onTimerLap.");
- lapRecordCount = 0;
- lapAverage = 0.0;
- }
- function onTimerReset() {
- Sys.println(TAG + "-> onTimerReset: Session stopped");
- sessionRecordCount = 0;
- sessionAverage = 0.0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment