pushups: activity editor works

we also disable jumping jacks detector
master
frederic wagner 2024-07-10 14:54:47 +02:00
parent d2133841b8
commit 3556ea7450
1 changed files with 48 additions and 21 deletions

View File

@ -36,6 +36,17 @@ const IMAGES = [
) )
]; ];
// number of movements or duration required for each activity
const DEFAULTS = [10, 10, 10, 30, 30, 30];
function default_routine() {
let routine = [];
DEFAULTS.forEach((d, i) => {
routine.push([i, d]);
});
return routine;
}
const DETECTORS = [ const DETECTORS = [
(xyz) => { (xyz) => {
return xyz.y > 0.4 ? 1 : 0; return xyz.y > 0.4 ? 1 : 0;
@ -53,28 +64,25 @@ const DETECTORS = [
} }
}, },
null, null,
(xyz) => { null,
if (xyz.y > 0.2) { // (xyz) => {
return 0; // if (xyz.y > 0.2) {
} // return 0;
if (xyz.y < 0) { // }
return 1; // if (xyz.y < 0) {
} // return 1;
return null; // }
}, // return null;
// }, // TODO: jumping jacks detector does not work
null null
]; ];
class FitnessStatus { class FitnessStatus {
constructor(duration) { constructor(duration) {
this.routine = [ this.routine = require("Storage").readJSON("pushups.cfg", true);
[0, 10], if (this.routine === undefined) {
[1, 10], this.routine = default_routine();
[2, 10], }
[3, 30],
[4, 10],
[5, 30],
];
this.routine_step = 0; this.routine_step = 0;
this.current_status = 0; this.current_status = 0;
this.buzzing = false; this.buzzing = false;
@ -257,8 +265,6 @@ function start_routine() {
function edit_menu() { function edit_menu() {
let w = g.getWidth();
let h = g.getHeight();
let routine = status.routine; let routine = status.routine;
E.showScroller({ E.showScroller({
@ -273,7 +279,6 @@ function edit_menu() {
} else { } else {
let activity = routine[idx][0]; let activity = routine[idx][0];
let count = routine[idx][1]; let count = routine[idx][1];
let activity_name = ACTIVITIES[activity];
let img = IMAGES[activity]; let img = IMAGES[activity];
g.drawImage(img, r.x + r.w / 5, r.y + 10); g.drawImage(img, r.x + r.w / 5, r.y + 10);
g.setFont("6x8:2").setFontAlign(0, 0).drawString(""+count, r.x+r.w*4/5, r.y+r.h/2); g.setFont("6x8:2").setFontAlign(0, 0).drawString(""+count, r.x+r.w*4/5, r.y+r.h/2);
@ -282,9 +287,11 @@ function edit_menu() {
select : function(idx) { select : function(idx) {
if (idx == routine.length + 1) { if (idx == routine.length + 1) {
E.showScroller(); E.showScroller();
require("Storage").writeJSON("pushups.cfg", routine);
start_routine(); start_routine();
} else if (idx == routine.length) { } else if (idx == routine.length) {
console.log("TODO: add"); E.showScroller();
add_activity();
} else { } else {
E.showScroller(); E.showScroller();
set_counter(idx); set_counter(idx);
@ -293,6 +300,26 @@ function edit_menu() {
}); });
} }
function add_activity() {
E.showScroller({
h : 60,
c : IMAGES.length,
draw : function(idx, r) {
g.setColor(1).drawRect(r.x, r.y, r.w, r.h);
let img = IMAGES[idx];
g.drawImage(img, r.x + r.w / 3, r.y + 10);
},
select : function(idx) {
let new_index = status.routine.length;
status.routine.push([idx, 10]);
E.showScroller();
set_counter(new_index);
}
});
}
function set_counter(index) { function set_counter(index) {
let w = g.getWidth(); let w = g.getWidth();
let h = g.getHeight(); let h = g.getHeight();