forked from FOSS/BangleApps
getting ready for more activities
parent
163f08b990
commit
63043b18f5
|
@ -1 +1 @@
|
|||
0.01: Initial code
|
||||
0.1: Initial code
|
||||
|
|
|
@ -1,19 +1,37 @@
|
|||
|
||||
Bangle.loadWidgets();
|
||||
|
||||
const UP = 0;
|
||||
const DOWN = 1;
|
||||
const ACTIVITIES = ["pushups", "situps"];
|
||||
const POSITIONS = [2, 2];
|
||||
const GOALS = [10, 10];
|
||||
const DETECTORS = [
|
||||
(xyz) => {
|
||||
return (xyz.y > 0.4)?1:0;
|
||||
},
|
||||
(xyz) => {
|
||||
if (xyz.x > 0.8 && xyz.z > -0.5) {
|
||||
return 1;
|
||||
} else if (xyz.x < 0.8 && xyz.z < -0.5) {
|
||||
return 0;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
let status = UP;
|
||||
let current_activity = 0;
|
||||
let current_status = 0;
|
||||
|
||||
// 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 remaining_pushups = 10;
|
||||
let remaining = 10;
|
||||
|
||||
|
||||
function display() {
|
||||
g.clear();
|
||||
g.setColor(0, 0, 0);
|
||||
g.setFont("Vector:80").setFontAlign(0, 0).drawString(""+remaining_pushups, 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());
|
||||
Bangle.drawWidgets();
|
||||
g.flip();
|
||||
}
|
||||
|
@ -35,29 +53,32 @@ setWatch(
|
|||
|
||||
Bangle.on('swipe', function(directionLR, directionUD) {
|
||||
if (directionUD == -1) {
|
||||
remaining_pushups += 1;
|
||||
remaining += 1;
|
||||
} else if (directionUD == 1) {
|
||||
remaining_pushups = Math.max(remaining_pushups-1, 1);
|
||||
remaining = Math.max(remaining-1, 1);
|
||||
} else if (directionLR == -1) {
|
||||
remaining_pushups += 5;
|
||||
remaining += 5;
|
||||
} else if (directionLR == 1) {
|
||||
remaining_pushups = Math.max(remaining_pushups-5, 1);
|
||||
remaining = Math.max(remaining-5, 1);
|
||||
}
|
||||
display();
|
||||
});
|
||||
|
||||
Bangle.on('accel', function(xyz) {
|
||||
let new_status = (xyz.y > 0.4)?DOWN:UP;
|
||||
if (new_status != status) {
|
||||
let new_status = DETECTORS[current_activity](xyz);
|
||||
if (new_status === null) {
|
||||
return;
|
||||
}
|
||||
if (new_status != current_status) {
|
||||
counts_in_opposite_status += 1;
|
||||
|
||||
if (counts_in_opposite_status == 6) {
|
||||
status = 1-status;
|
||||
current_status = 1-current_status;
|
||||
counts_in_opposite_status = 0;
|
||||
if (status == UP) {
|
||||
remaining_pushups -= 1;
|
||||
if (current_status == 0) {
|
||||
remaining -= 1;
|
||||
display();
|
||||
if (remaining_pushups == 0) {
|
||||
if (remaining == 0) {
|
||||
Bangle.buzz(500);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue