Guest User

Untitled

a guest
Dec 19th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. using Toybox.WatchUi as Ui;
  2. using Toybox.Application as App;
  3. using Toybox.Background;
  4. using Toybox.System as Sys;
  5. using Toybox.Communications as Comm;
  6. using Toybox.FitContributor as fit;
  7.  
  8.  
  9.  
  10. class glucose_datafieldView extends Ui.SimpleDataField {
  11. private const TAG = "glucose_datafieldView";
  12.  
  13. hidden var mFitContributor = null;
  14.  
  15. // Variables for computing averages:
  16. hidden var lapAverage = 0.0;
  17. hidden var sessionAverage = 0.0;
  18. hidden var lapRecordCount = 0;
  19. hidden var sessionRecordCount = 0;
  20.  
  21. hidden var tempSgv = null;
  22. var tempFlag = null;
  23. hidden var sgvString = "-";
  24. hidden var mTimerRunning = false;
  25.  
  26. // Set the label of the data field here.
  27. function initialize() {
  28. Sys.println(TAG + "->initialize");
  29. SimpleDataField.initialize();
  30.  
  31. //------------------------FIT-----------------------
  32. mFitContributor = new SGVFitContributor(self);
  33.  
  34. //--------------------------------------------------
  35. Sys.println("FIT contributor initialized");
  36. label = "Blood glucose";
  37. App.getApp().setProperty(OSDATA, null);
  38. App.getApp().setProperty(FLAG,null);
  39.  
  40. }
  41.  
  42.  
  43. function compute(info) {
  44. //Read object store:
  45. tempSgv = App.getApp().getProperty(OSDATA);
  46.  
  47. //Check the flag:
  48. tempFlag = App.getApp().getProperty(FLAG);
  49.  
  50. Sys.println(TAG + "-> compute: tempFlag = " + tempFlag + ", tempSgv = " + tempSgv + ", sessionRunning = " + mTimerRunning);
  51.  
  52.  
  53. //Check for temporal event and if the session is running:
  54. if(tempFlag && mTimerRunning){
  55. if (tempSgv != null){
  56. //Reset the fit contributor:
  57. mFitContributor = null;
  58. //Initialize the FIT contributor:
  59. mFitContributor = new SGVFitContributor(self);
  60.  
  61. //Update session averages:
  62. lapRecordCount++;
  63. sessionRecordCount++;
  64. lapAverage += tempSgv.toFloat();
  65. sessionAverage += tempSgv.toFloat();
  66. mFitContributor.updateAverages(lapAverage, sessionAverage, lapRecordCount, sessionRecordCount);
  67.  
  68. //Log new data:
  69. Sys.println("tempSgv = " + tempSgv);
  70. mFitContributor.compute(tempSgv.toFloat());
  71. }
  72. }
  73.  
  74.  
  75. //Reset the flag so that nothing happens until another temporal event occurs:
  76. App.getApp().setProperty(FLAG,false);
  77. //Return the value to be displayed in the datafield:
  78. if (tempSgv == "0.00" || tempSgv == null){
  79. sgvString = "-";
  80. }
  81.  
  82. return sgvString;
  83. }
  84.  
  85. function onTimerStart() {
  86. Sys.println(TAG + "-> onTimerStart: Session started");
  87. mTimerRunning = true;
  88.  
  89. }
  90.  
  91. function onTimerStop() {
  92. Sys.println(TAG + "-> onTimerStop.");
  93. mTimerRunning = false;
  94. }
  95.  
  96. function onTimerPause() {
  97. Sys.println(TAG + "-> onTimerPause.");
  98. mTimerRunning = false;
  99. }
  100.  
  101. function onTimerResume() {
  102. Sys.println(TAG + "-> onTimerResume.");
  103. mTimerRunning = true;
  104. }
  105.  
  106. function onTimerLap() {
  107. Sys.println(TAG + "-> onTimerLap.");
  108. lapRecordCount = 0;
  109. lapAverage = 0.0;
  110. }
  111.  
  112. function onTimerReset() {
  113. Sys.println(TAG + "-> onTimerReset: Session stopped");
  114. sessionRecordCount = 0;
  115. sessionAverage = 0.0;
  116. }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment