diff --git a/apps/pushups/ChangeLog b/apps/pushups/ChangeLog new file mode 100644 index 000000000..9fa2c8172 --- /dev/null +++ b/apps/pushups/ChangeLog @@ -0,0 +1 @@ +0.01: Initial code diff --git a/apps/pushups/README.md b/apps/pushups/README.md new file mode 100644 index 000000000..60c0f315e --- /dev/null +++ b/apps/pushups/README.md @@ -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 diff --git a/apps/pushups/app-icon.js b/apps/pushups/app-icon.js new file mode 100644 index 000000000..3f98295ad --- /dev/null +++ b/apps/pushups/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwwhC/AH4A/AH4A/ACcEogXVolEoAuVAAIXYhvdC6vdAAPQL6QuBAAaPRhtNDAgyQDQIXE7qYPC48iMaFM5gWC6kikAXPpvMDAXSC6BIBhoYB5oXBJB4XBOQPc5lCC4IYPC4StBCwUikgvQAAMCC4TlCeZgHFC4YYKFwoADkgXCDBIuHEQgACOpZTKC6oNGiIASC7YA/AH4A/AH4AdA")) diff --git a/apps/pushups/app.js b/apps/pushups/app.js new file mode 100644 index 000000000..26f490c77 --- /dev/null +++ b/apps/pushups/app.js @@ -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; + } +}); diff --git a/apps/pushups/metadata.json b/apps/pushups/metadata.json new file mode 100644 index 000000000..64a445067 --- /dev/null +++ b/apps/pushups/metadata.json @@ -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} + ] +} diff --git a/apps/pushups/pushups.png b/apps/pushups/pushups.png new file mode 100644 index 000000000..66c5902b6 Binary files /dev/null and b/apps/pushups/pushups.png differ