|
16 | 16 | function writeProfile() { |
17 | 17 | require('Storage').writeJSON(FILE, myprofile); |
18 | 18 | } |
19 | | - |
| 19 | + |
20 | 20 | function finishRHRReading() { |
21 | 21 | Bangle.setHRMPower(0); |
22 | 22 | Bangle.removeListener('HRM', onRHRHrm); |
23 | 23 | if (rhrData.length > 0) { |
24 | 24 | // Calculate average, ignoring outliers |
25 | 25 | let avgRHR = Math.round(rhrData.reduce((a, b) => a + b) / rhrData.length); |
26 | | - |
27 | | - E.showPrompt(" ",{ |
28 | | - buttonHeight:35, |
29 | | - buttons:{"Yes":true,"No":false} |
30 | | - }).then(function(v){ |
31 | | - if(v){ |
| 26 | + |
| 27 | + E.showPrompt(" ", { |
| 28 | + buttonHeight: 35, |
| 29 | + buttons: { "Yes": true, "No": false } |
| 30 | + }).then(function (v) { |
| 31 | + if (v) { |
32 | 32 | myprofile.minHrm = avgRHR; |
33 | 33 | writeProfile(); |
34 | | - |
35 | | - E.showPrompt(" ",{ |
36 | | - buttonHeight:35, |
37 | | - buttons:{"Back":true} |
38 | | - }).then(function(v){ |
| 34 | + |
| 35 | + E.showPrompt(" ", { |
| 36 | + buttonHeight: 35, |
| 37 | + buttons: { "Back": true } |
| 38 | + }).then(function (v) { |
39 | 39 | mainMenu(); |
40 | 40 | }) |
41 | | - |
42 | | - g.clearRect(0,Bangle.appRect.y,g.getWidth(),g.getHeight()-40) |
| 41 | + |
| 42 | + g.clearRect(0, Bangle.appRect.y, g.getWidth(), g.getHeight() - 40) |
43 | 43 | .setColor("#f00") |
44 | | - .drawImage(atob("Mi2BAAAAAAAAAAAP4AAf4AAf/wAf/gAP/+Af/+AH//wP//wD//+H//+B///z///w///+///8P///////n///////5///////+f///////3///////9////////f///////3///////9////////f///////j///////4///////+P///////B///////wf//////4D//////+Af//////AH//////gA//////4AH/////8AA/////+AAH/////AAB/////gAAP////wAAA////4AAAH///8AAAA///+AAAAH///AAAAA///AAAAAH//gAAAAAf/wAAAAAD/4AAAAAAf4AAAAAAB8AAAAAAAOAAAAAAAAAAAAAAAAAAAAAA=="),g.getWidth()-80,70) |
| 44 | + .drawImage(atob("Mi2BAAAAAAAAAAAP4AAf4AAf/wAf/gAP/+Af/+AH//wP//wD//+H//+B///z///w///+///8P///////n///////5///////+f///////3///////9////////f///////3///////9////////f///////j///////4///////+P///////B///////wf//////4D//////+Af//////AH//////gA//////4AH/////8AA/////+AAH/////AAB/////gAAP////wAAA////4AAAH///8AAAA///+AAAAH///AAAAA///AAAAAH//gAAAAAf/wAAAAAD/4AAAAAAf4AAAAAAB8AAAAAAAOAAAAAAAAAAAAAAAAAAAAAA=="), g.getWidth() - 80, 70) |
45 | 45 | .setColor(g.theme.fg) |
46 | | - .setFont("Vector", 25).setFontAlign(0,0) |
47 | | - .drawString("Saved!", g.getWidth()/2, 35) |
48 | | - .setFont("Vector", 30).setFontAlign(0,0) |
49 | | - .drawString(avgRHR, g.getWidth()/2-30, g.getHeight()/2) |
50 | | - .setFont("Vector", 18).setFontAlign(0,0) |
51 | | - .drawString("RHR", g.getWidth()/2-30, g.getHeight()/2+20); |
52 | | - |
53 | | - }else{ |
| 46 | + .setFont("Vector", 25).setFontAlign(0, 0) |
| 47 | + .drawString("Saved!", g.getWidth() / 2, 35) |
| 48 | + .setFont("Vector", 30).setFontAlign(0, 0) |
| 49 | + .drawString(avgRHR, g.getWidth() / 2 - 30, g.getHeight() / 2) |
| 50 | + .setFont("Vector", 18).setFontAlign(0, 0) |
| 51 | + .drawString("RHR", g.getWidth() / 2 - 30, g.getHeight() / 2 + 20); |
| 52 | + |
| 53 | + } else { |
54 | 54 | mainMenu(); |
55 | 55 | } |
56 | | - }) |
57 | | - |
58 | | - g.clearRect(0,Bangle.appRect.y,g.getWidth(),g.getHeight()-40) |
59 | | - .setColor("#f00") |
60 | | - .drawImage(atob("Mi2BAAAAAAAAAAAP4AAf4AAf/wAf/gAP/+Af/+AH//wP//wD//+H//+B///z///w///+///8P///////n///////5///////+f///////3///////9////////f///////3///////9////////f///////j///////4///////+P///////B///////wf//////4D//////+Af//////AH//////gA//////4AH/////8AA/////+AAH/////AAB/////gAAP////wAAA////4AAAH///8AAAA///+AAAAH///AAAAA///AAAAAH//gAAAAAf/wAAAAAD/4AAAAAAf4AAAAAAB8AAAAAAAOAAAAAAAAAAAAAAAAAAAAAA=="),g.getWidth()-80,70-15) |
61 | | - .setColor(g.theme.fg) |
62 | | - .setFont("Vector", 25).setFontAlign(0,0) |
63 | | - .drawString("Finished!", g.getWidth()/2, 35) |
64 | | - .setFont("Vector", 30).setFontAlign(0,0) |
65 | | - .drawString(avgRHR, g.getWidth()/2-30, g.getHeight()/2-15) |
66 | | - .setFont("Vector", 18).setFontAlign(0,0) |
67 | | - .drawString("RHR", g.getWidth()/2-30, g.getHeight()/2+20-15) |
68 | | - .drawString("Save?", g.getWidth()/2, g.getHeight()/2+30) |
69 | | - |
70 | | - } |
| 56 | + }) |
| 57 | + |
| 58 | + g.clearRect(0, Bangle.appRect.y, g.getWidth(), g.getHeight() - 40) |
| 59 | + .setColor("#f00") |
| 60 | + .drawImage(atob("Mi2BAAAAAAAAAAAP4AAf4AAf/wAf/gAP/+Af/+AH//wP//wD//+H//+B///z///w///+///8P///////n///////5///////+f///////3///////9////////f///////3///////9////////f///////j///////4///////+P///////B///////wf//////4D//////+Af//////AH//////gA//////4AH/////8AA/////+AAH/////AAB/////gAAP////wAAA////4AAAH///8AAAA///+AAAAH///AAAAA///AAAAAH//gAAAAAf/wAAAAAD/4AAAAAAf4AAAAAAB8AAAAAAAOAAAAAAAAAAAAAAAAAAAAAA=="), g.getWidth() - 80, 70 - 15) |
| 61 | + .setColor(g.theme.fg) |
| 62 | + .setFont("Vector", 25).setFontAlign(0, 0) |
| 63 | + .drawString("Finished!", g.getWidth() / 2, 35) |
| 64 | + .setFont("Vector", 30).setFontAlign(0, 0) |
| 65 | + .drawString(avgRHR, g.getWidth() / 2 - 30, g.getHeight() / 2 - 15) |
| 66 | + .setFont("Vector", 18).setFontAlign(0, 0) |
| 67 | + .drawString("RHR", g.getWidth() / 2 - 30, g.getHeight() / 2 + 20 - 15) |
| 68 | + .drawString("Save?", g.getWidth() / 2, g.getHeight() / 2 + 30) |
| 69 | + |
| 70 | + } |
71 | 71 | } |
72 | 72 |
|
73 | 73 | function onRHRHrm(hrm) { |
74 | 74 | // Only record if the watch is confident in the reading |
75 | 75 | if (hrm.confidence > 80) { |
76 | 76 | rhrData.push(hrm.bpm); |
77 | 77 | } |
78 | | - |
| 78 | + |
79 | 79 | // Update UI |
80 | 80 | g.clearRect(Bangle.appRect) |
81 | 81 | .setColor(g.theme.fg) |
82 | | - .setFont("Vector", 20).setFontAlign(0,0) |
83 | | - .drawString("Measuring...", g.getWidth()/2, 40) |
| 82 | + .setFont("Vector", 20).setFontAlign(0, 0) |
| 83 | + .drawString("Measuring...", g.getWidth() / 2, 40) |
84 | 84 | .setFont("Vector", 40) |
85 | | - .drawString(hrm.bpm, g.getWidth()/2-30, g.getHeight()/2-5) |
| 85 | + .drawString(hrm.bpm, g.getWidth() / 2 - 30, g.getHeight() / 2 - 5) |
86 | 86 | .setColor("#f00") |
87 | | - .drawImage(atob("Mi2BAAAAAAAAAAAP4AAf4AAf/wAf/gAP/+Af/+AH//wP//wD//+H//+B///z///w///+///8P///////n///////5///////+f///////3///////9////////f///////3///////9////////f///////j///////4///////+P///////B///////wf//////4D//////+Af//////AH//////gA//////4AH/////8AA/////+AAH/////AAB/////gAAP////wAAA////4AAAH///8AAAA///+AAAAH///AAAAA///AAAAAH//gAAAAAf/wAAAAAD/4AAAAAAf4AAAAAAB8AAAAAAAOAAAAAAAAAAAAAAAAAAAAAA=="),g.getWidth()-80,60) |
| 87 | + .drawImage(atob("Mi2BAAAAAAAAAAAP4AAf4AAf/wAf/gAP/+Af/+AH//wP//wD//+H//+B///z///w///+///8P///////n///////5///////+f///////3///////9////////f///////3///////9////////f///////j///////4///////+P///////B///////wf//////4D//////+Af//////AH//////gA//////4AH/////8AA/////+AAH/////AAB/////gAAP////wAAA////4AAAH///8AAAA///+AAAAH///AAAAA///AAAAAH//gAAAAAf/wAAAAAD/4AAAAAAf4AAAAAAB8AAAAAAAOAAAAAAAAAAAAAAAAAAAAAA=="), g.getWidth() - 80, 60) |
88 | 88 | .setColor(g.theme.fg) |
89 | 89 | .setFont("Vector", 16) |
90 | | - .drawString(counter + "s remaining", g.getWidth()/2, g.getHeight() - 55) |
91 | | - |
92 | | - if(hrm.confidence<=80){ |
93 | | - g.setFont("Vector", 14).drawString("Low confidence\nKeep still", g.getWidth()/2, g.getHeight() - 20); |
| 90 | + .drawString(counter + "s remaining", g.getWidth() / 2, g.getHeight() - 55) |
| 91 | + |
| 92 | + if (hrm.confidence <= 80) { |
| 93 | + g.setFont("Vector", 14).drawString("Low confidence\nKeep still", g.getWidth() / 2, g.getHeight() - 20); |
94 | 94 | } |
95 | 95 | } |
96 | 96 |
|
97 | | - function startRHR(){ |
| 97 | + function startRHR() { |
98 | 98 | // Start the reading |
99 | 99 | g.clearRect(Bangle.appRect) |
100 | | - g.setColor(g.theme.fg); |
101 | | - g.setFont("Vector", 20).setFontAlign(0,0); |
102 | | - g.drawString("Starting...", g.getWidth()/2, g.getHeight()/2); |
| 100 | + g.setColor(g.theme.fg); |
| 101 | + g.setFont("Vector", 20).setFontAlign(0, 0); |
| 102 | + g.drawString("Starting...", g.getWidth() / 2, g.getHeight() / 2); |
103 | 103 | rhrData = []; |
104 | 104 | counter = seconds; |
105 | | - Bangle.on('HRM',onRHRHrm); |
| 105 | + Bangle.on('HRM', onRHRHrm); |
106 | 106 | Bangle.setHRMPower(1); |
107 | 107 | let interval = setInterval(() => { |
108 | 108 | counter--; |
|
112 | 112 | } |
113 | 113 | }, 1000); |
114 | 114 | } |
115 | | - |
116 | | - function RHRReading(){ |
117 | | - E.showPrompt("Resting Heart Rate reading requires you to be resting and still. Takes approx. 1 minute.",{ |
118 | | - title:"Continue?", |
119 | | - buttonHeight:50, |
120 | | - buttons:{"Continue":true,"Back":false} |
121 | | - }).then(function(v){ |
122 | | - if(v){ |
123 | | - E.showPrompt("Make sure Bangle.js is snug around your wrist, about 1 cm under your wrist bone.",{ |
124 | | - buttonHeight:40, |
125 | | - buttons:{"Continue":true} |
126 | | - }).then(function(v){ |
127 | | - startRHR(); |
128 | | - }); |
129 | | - }else{ |
| 115 | + |
| 116 | + function RHRReading() { |
| 117 | + E.showPrompt("Resting Heart Rate reading requires you to be resting and still. Takes approx. 1 minute.", { |
| 118 | + title: "Continue?", |
| 119 | + buttonHeight: 50, |
| 120 | + buttons: { "Continue": true, "Back": false } |
| 121 | + }).then(function (v) { |
| 122 | + if (v) { |
| 123 | + E.showPrompt("Make sure Bangle.js is snug around your wrist, about 1 cm under your wrist bone.", { |
| 124 | + buttonHeight: 40, |
| 125 | + buttons: { "Continue": true } |
| 126 | + }).then(function (v) { |
| 127 | + startRHR(); |
| 128 | + }); |
| 129 | + } else { |
130 | 130 | mainMenu() |
131 | 131 | } |
132 | 132 | }); |
133 | 133 | } |
134 | | - |
135 | | - const genderOpts = ["Male","Female","Not Set"]; |
| 134 | + |
| 135 | + const genderOpts = ["Male", "Female", "Not Set"]; |
136 | 136 |
|
137 | 137 | const ageMenu = () => { |
138 | 138 | const date = new Date(myprofile.birthday); |
139 | 139 |
|
140 | 140 | E.showMenu({ |
141 | | - "" : { "title" : /*LANG*/"Birthday" }, |
142 | | - |
143 | | - "< Back" : () => { |
| 141 | + "": { "title": /*LANG*/"Birthday" }, |
| 142 | + "< Back": () => { |
144 | 143 | if (date != new Date(myprofile.birthday)) { |
145 | 144 | // Birthday changed |
146 | 145 | if (date > new Date()) { |
147 | 146 | E.showPrompt(/*LANG*/"Birthday must not be in future!", { |
148 | | - |
149 | | - buttons : {"Ok":true}, |
| 147 | + buttons: { "Ok": true }, |
150 | 148 | }).then(() => ageMenu()); |
151 | | - |
| 149 | + |
152 | 150 | } else { |
153 | 151 | const age = (new Date()).getFullYear() - date.getFullYear(); |
154 | | - const newMaxHRM = Math.round(208-0.7*age); // Tanaka formula: https://my.clevelandclinic.org/health/articles/24649-heart-rate-reserve |
155 | | - E.showPrompt(/*LANG*/`Set HR max to ${newMaxHRM} calculated from age?`).then(function(v) { |
| 152 | + const newMaxHRM = Math.round(208 - 0.7 * age); // Tanaka formula: https://my.clevelandclinic.org/health/articles/24649-heart-rate-reserve |
| 153 | + E.showPrompt(/*LANG*/`Set HR max to ${newMaxHRM} calculated from age?`).then(function (v) { |
156 | 154 | myprofile.birthday = date.getFullYear() + "-" + (date.getMonth() + 1).toString().padStart(2, '0') + "-" + date.getDate().toString().padStart(2, '0'); |
157 | 155 | if (v) { |
158 | 156 | myprofile.maxHrm = newMaxHRM; |
|
179 | 177 | value: date ? date.getMonth() + 1 : null, |
180 | 178 | format: v => require("date_utils").month(v), |
181 | 179 | onchange: v => { |
182 | | - date.setMonth((v+11)%12); |
| 180 | + date.setMonth((v + 11) % 12); |
183 | 181 | } |
184 | 182 | }, |
185 | 183 | /*LANG*/"Year": { |
|
194 | 192 | }; |
195 | 193 |
|
196 | 194 | const mainMenu = () => { |
197 | | - var menu={ |
198 | | - "" : { "title" : /*LANG*/"My Profile" }, |
| 195 | + var menu = { |
| 196 | + "": { "title": /*LANG*/"My Profile" }, |
199 | 197 |
|
200 | | - "< Back" : () => back(), |
| 198 | + "< Back": () => back(), |
201 | 199 |
|
202 | | - /*LANG*/"Birthday" : () => ageMenu(), |
| 200 | + /*LANG*/"Birthday": () => ageMenu(), |
203 | 201 |
|
204 | 202 | /*LANG*/'Height': { |
205 | 203 | value: myprofile.height, |
206 | 204 | min: 0, max: 300, |
207 | | - step:0.01, |
| 205 | + step: 0.01, |
208 | 206 | format: v => v ? require("locale").distance(v, 2) : '-', |
209 | 207 | onchange: v => { |
210 | 208 | if (v !== myprofile.height) { |
211 | 209 | // height changed |
212 | 210 | myprofile.height = v; |
213 | 211 | setTimeout(() => { |
214 | 212 | const newStrideLength = myprofile.height * 0.414; |
215 | | - E.showPrompt(/*LANG*/`Set Stride length to ${require("locale").distance(newStrideLength, 2)} calculated from height?`).then(function(v) { |
| 213 | + E.showPrompt(/*LANG*/`Set Stride length to ${require("locale").distance(newStrideLength, 2)} calculated from height?`).then(function (v) { |
216 | 214 | if (v) { |
217 | 215 | myprofile.strideLength = newStrideLength; |
218 | 216 | } |
|
226 | 224 |
|
227 | 225 | /*LANG*/"Weight": { |
228 | 226 | value: myprofile.weight, |
229 | | - min:0, |
230 | | - step:1, |
| 227 | + min: 0, |
| 228 | + step: 1, |
231 | 229 | format: v => v ? v + "kg" : '-', |
232 | 230 | onchange: v => { |
233 | | - myprofile.weight=v; |
| 231 | + myprofile.weight = v; |
234 | 232 | writeProfile(); |
235 | 233 | }, |
236 | 234 | }, |
237 | 235 |
|
238 | 236 | /*LANG*/"Gender": { |
239 | 237 | value: (typeof myprofile.gender === "number" && |
240 | | - myprofile.gender >= 0 && |
241 | | - myprofile.gender < genderOpts.length) ? myprofile.gender : 2, |
242 | | - min:0, |
243 | | - max: genderOpts.length-1, |
| 238 | + myprofile.gender >= 0 && |
| 239 | + myprofile.gender < genderOpts.length) ? myprofile.gender : 2, |
| 240 | + min: 0, |
| 241 | + max: genderOpts.length - 1, |
244 | 242 | format: v => genderOpts[v], |
245 | 243 | onchange: v => { |
246 | 244 | myprofile.gender = v; |
|
258 | 256 | } |
259 | 257 | }, |
260 | 258 | }; |
261 | | - |
262 | | - menu[/*LANG*/`Resting/Min HR: ${myprofile.minHrm?myprofile.minHrm:"--"}`]=RHRReading; |
263 | | - menu[/*LANG*/"Stride length"]= { |
264 | | - value: myprofile.strideLength, |
265 | | - min:0.00, |
266 | | - step:0.01, |
267 | | - format: v => v ? require("locale").distance(v, 2) : '-', |
268 | | - onchange: v => { |
269 | | - myprofile.strideLength=v; |
270 | | - writeProfile(); |
271 | | - }, |
272 | | - } |
273 | | - E.showMenu(menu) |
| 259 | + |
| 260 | + menu[/*LANG*/`Resting/Min HR: ${myprofile.minHrm ? myprofile.minHrm : "--"}`] = RHRReading; |
| 261 | + menu[/*LANG*/"Stride length"] = { |
| 262 | + value: myprofile.strideLength, |
| 263 | + min: 0.00, |
| 264 | + step: 0.01, |
| 265 | + format: v => v ? require("locale").distance(v, 2) : '-', |
| 266 | + onchange: v => { |
| 267 | + myprofile.strideLength = v; |
| 268 | + writeProfile(); |
| 269 | + }, |
| 270 | + } |
| 271 | + E.showMenu(menu) |
274 | 272 | }; |
275 | | - |
| 273 | + |
276 | 274 | mainMenu(); |
277 | 275 | }) |
0 commit comments