Skip to content

Commit

Permalink
myprofile: Added height setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nxdefiant committed Dec 12, 2023
1 parent 16cc803 commit 9f3d78c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/myprofile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Configure your personal profile. All settings are optional and are only stored o
| Birthday | Used to calculate age | year, month, day | 'YYYY-MM-DD' | 01.01.1970 | - |
| HR max | maximum heart rate | BPM | BPM | 60 | Use maximum value when exercising.<br/> If unsure set to 220-age. |
| HR min | minimum heart rate | BPM | BPM | 200 | Measure your heart rate after waking up |
| Height | Body height | local length unit | meter | 0 (=not set) | - |
| Stride length | distance traveled with one step | local length unit | meter | 0 (=not set) | Walk 10 steps and divide the travelled distance by 10 |

## Developer notes
Expand Down
28 changes: 26 additions & 2 deletions apps/myprofile/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
maxHrm: 200,
strideLength: 0, // 0 = not set
birthday: '1970-01-01',
height: 0, // 0 = not set
}, require('Storage').readJSON(FILE, true) || {});

function writeProfile() {
Expand All @@ -20,20 +21,20 @@

"< Back" : () => {
if (date != new Date(myprofile.birthday)) {
// Birthday changed
if (date > new Date()) {
E.showPrompt(/*LANG*/"Birthday must not be in future!", {
buttons : {"Ok":true},
}).then(() => ageMenu());
} else {
// Birthday changed
const age = (new Date()).getFullYear() - date.getFullYear();
const newMaxHRM = 220-age;
E.showPrompt(/*LANG*/`Set HR max to ${newMaxHRM} calculated from age?`).then(function(v) {
myprofile.birthday = date.getFullYear() + "-" + (date.getMonth() + 1).toString().padStart(2, '0') + "-" + date.getDate().toString().padStart(2, '0');
if (v) {
myprofile.maxHrm = newMaxHRM;
writeProfile();
}
writeProfile();
mainMenu();
});
}
Expand Down Expand Up @@ -77,6 +78,29 @@

/*LANG*/"Birthday" : () => ageMenu(),

/*LANG*/'Height': {
value: myprofile.height,
min: 0, max: 300,
step:0.01,
format: v => v ? require("locale").distance(v, 2) : '-',
onchange: v => {
if (v !== myprofile.height) {
// height changed
myprofile.height = v;
setTimeout(() => {
const newStrideLength = myprofile.height * 0.414;
E.showPrompt(/*LANG*/`Set Stride length to ${require("locale").distance(newStrideLength, 2)} calculated from height?`).then(function(v) {
if (v) {
myprofile.strideLength = newStrideLength;
}
writeProfile();
mainMenu();
});
}, 1);
}
}
},

/*LANG*/'HR max': {
format: v => /*LANG*/`${v} BPM`,
value: myprofile.maxHrm,
Expand Down

0 comments on commit 9f3d78c

Please sign in to comment.