pushups: new app

pull/3669/head
frederic wagner 2024-01-15 15:14:37 +01:00
parent 8f7528699f
commit 163f08b990
6 changed files with 99 additions and 0 deletions

1
apps/pushups/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: Initial code

11
apps/pushups/README.md Normal file
View File

@ -0,0 +1,11 @@
# Pushups
Train for push ups using the accelerometer. It should buzz everytime you go up and down.
Swipe the screen to set the countdown value.
## Creator
Feel free to give me feedback : is it useful for you ? what other features would you like ?
frederic.wagner@imag.fr

1
apps/pushups/app-icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwhC/AH4A/AH4A/ACcEogXVolEoAuVAAIXYhvdC6vdAAPQL6QuBAAaPRhtNDAgyQDQIXE7qYPC48iMaFM5gWC6kikAXPpvMDAXSC6BIBhoYB5oXBJB4XBOQPc5lCC4IYPC4StBCwUikgvQAAMCC4TlCeZgHFC4YYKFwoADkgXCDBIuHEQgACOpZTKC6oNGiIASC7YA/AH4A/AH4AdA"))

69
apps/pushups/app.js Normal file
View File

@ -0,0 +1,69 @@
Bangle.loadWidgets();
const UP = 0;
const DOWN = 1;
let status = UP;
// 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;
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);
Bangle.drawWidgets();
g.flip();
}
display();
Bangle.setPollInterval(80);
setWatch(
function () {
load();
},
BTN1,
{
repeat: true,
}
);
Bangle.on('swipe', function(directionLR, directionUD) {
if (directionUD == -1) {
remaining_pushups += 1;
} else if (directionUD == 1) {
remaining_pushups = Math.max(remaining_pushups-1, 1);
} else if (directionLR == -1) {
remaining_pushups += 5;
} else if (directionLR == 1) {
remaining_pushups = Math.max(remaining_pushups-5, 1);
}
display();
});
Bangle.on('accel', function(xyz) {
let new_status = (xyz.y > 0.4)?DOWN:UP;
if (new_status != status) {
counts_in_opposite_status += 1;
if (counts_in_opposite_status == 6) {
status = 1-status;
counts_in_opposite_status = 0;
if (status == UP) {
remaining_pushups -= 1;
display();
if (remaining_pushups == 0) {
Bangle.buzz(500);
}
}
Bangle.buzz(100);
}
} else {
counts_in_opposite_status = 0;
}
});

View File

@ -0,0 +1,17 @@
{
"id": "pushups",
"name": "Pushups",
"shortName": "Pushups",
"version": "0.1",
"description": "Pushups countdown using the accelerometer.",
"allow_emulator":false,
"icon": "pushups.png",
"type": "app",
"tags": "health",
"supports": ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name":"pushups.app.js","url":"app.js"},
{"name":"pushups.img","url":"app-icon.js","evaluate":true}
]
}

BIN
apps/pushups/pushups.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B