pushups: ready for routines
parent
63043b18f5
commit
16f18d409e
|
|
@ -1,37 +1,47 @@
|
||||||
|
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
|
|
||||||
const ACTIVITIES = ["pushups", "situps"];
|
const ACTIVITIES = ["pushups", "situps", "squats"];
|
||||||
const POSITIONS = [2, 2];
|
let routine = [[0, 10], [1, 10], [2, 10]];
|
||||||
const GOALS = [10, 10];
|
|
||||||
const DETECTORS = [
|
const DETECTORS = [
|
||||||
(xyz) => {
|
(xyz) => {
|
||||||
return (xyz.y > 0.4)?1:0;
|
return (xyz.y > 0.4)?1:0;
|
||||||
},
|
},
|
||||||
(xyz) => {
|
(xyz) => {
|
||||||
if (xyz.x > 0.8 && xyz.z > -0.5) {
|
if (xyz.y > 0.4 && xyz.z > -1) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (xyz.x < 0.8 && xyz.z < -0.5) {
|
} else if (xyz.x < 0.4 && xyz.z < -1) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
(xyz) => {
|
||||||
|
if (xyz.z > -1) {
|
||||||
|
return 0;
|
||||||
|
} else if (xyz.z < -1.1) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
let current_activity = 0;
|
let routine_step = 0;
|
||||||
let current_status = 0;
|
let current_status = 0;
|
||||||
|
|
||||||
// to get rid of noise we'll need to count how many measures confirm where we think we are
|
// to get rid of noise we'll need to count how many measures confirm where we think we are
|
||||||
let counts_in_opposite_status = 0;
|
let counts_in_opposite_status = 0;
|
||||||
let remaining = 10;
|
let remaining = routine[routine_step][1];
|
||||||
|
|
||||||
|
|
||||||
function display() {
|
function display() {
|
||||||
g.clear();
|
g.clear();
|
||||||
g.setColor(0, 0, 0);
|
g.setColor(0, 0, 0);
|
||||||
g.setFont("Vector:80").setFontAlign(0, 0).drawString(""+remaining, g.getWidth()/2, g.getHeight()/2);
|
g.setFont("Vector:80").setFontAlign(0, 0).drawString(""+remaining, g.getWidth()/2, g.getHeight()/2);
|
||||||
g.setFont("6x8:2").setFontAlign(0, 1).drawString(ACTIVITIES[current_activity], g.getWidth()/2, g.getHeight());
|
let activity = ACTIVITIES[routine[routine_step][0]];
|
||||||
|
g.setFont("6x8:2").setFontAlign(0, 1).drawString(activity, g.getWidth()/2, g.getHeight());
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
g.flip();
|
g.flip();
|
||||||
}
|
}
|
||||||
|
|
@ -57,15 +67,22 @@ Bangle.on('swipe', function(directionLR, directionUD) {
|
||||||
} else if (directionUD == 1) {
|
} else if (directionUD == 1) {
|
||||||
remaining = Math.max(remaining-1, 1);
|
remaining = Math.max(remaining-1, 1);
|
||||||
} else if (directionLR == -1) {
|
} else if (directionLR == -1) {
|
||||||
remaining += 5;
|
if (routine_step < routine.length -1) {
|
||||||
|
routine_step += 1;
|
||||||
|
remaining = routine[routine_step][1];
|
||||||
|
}
|
||||||
} else if (directionLR == 1) {
|
} else if (directionLR == 1) {
|
||||||
remaining = Math.max(remaining-5, 1);
|
if (routine_step > 0) {
|
||||||
|
routine_step -= 1;
|
||||||
|
remaining = routine[routine_step][1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
display();
|
display();
|
||||||
});
|
});
|
||||||
|
|
||||||
Bangle.on('accel', function(xyz) {
|
Bangle.on('accel', function(xyz) {
|
||||||
let new_status = DETECTORS[current_activity](xyz);
|
let activity = routine[routine_step][0];
|
||||||
|
let new_status = DETECTORS[activity](xyz);
|
||||||
if (new_status === null) {
|
if (new_status === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +96,14 @@ Bangle.on('accel', function(xyz) {
|
||||||
remaining -= 1;
|
remaining -= 1;
|
||||||
display();
|
display();
|
||||||
if (remaining == 0) {
|
if (remaining == 0) {
|
||||||
Bangle.buzz(500);
|
Bangle.buzz(500).then(() => {
|
||||||
|
routine_step += 1;
|
||||||
|
if (routine_step >= routine.length) {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
remaining = routine[routine_step][1];
|
||||||
|
display();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bangle.buzz(100);
|
Bangle.buzz(100);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue