From 163f08b9908ed0f756ef7a5e28d68084efc3c848 Mon Sep 17 00:00:00 2001 From: frederic wagner Date: Mon, 15 Jan 2024 15:14:37 +0100 Subject: [PATCH] pushups: new app --- apps/pushups/ChangeLog | 1 + apps/pushups/README.md | 11 ++++++ apps/pushups/app-icon.js | 1 + apps/pushups/app.js | 69 +++++++++++++++++++++++++++++++++++++ apps/pushups/metadata.json | 17 +++++++++ apps/pushups/pushups.png | Bin 0 -> 854 bytes 6 files changed, 99 insertions(+) create mode 100644 apps/pushups/ChangeLog create mode 100644 apps/pushups/README.md create mode 100644 apps/pushups/app-icon.js create mode 100644 apps/pushups/app.js create mode 100644 apps/pushups/metadata.json create mode 100644 apps/pushups/pushups.png 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 0000000000000000000000000000000000000000..66c5902b6dc5ce8c6f094f7db20647e0d991a039 GIT binary patch literal 854 zcmV-c1F8IpP)~B5)xQb^$|7 zNQjn$gadS@mhMPmNE(dMcrZrgsUbcv_#noEi5}E+RtN~R8caNEjUtMQ6gdd#{$^{p zEl`jM*jDFD{!4ea`+xsGvoj+I91e%W;cz${PTaw;Sf~;-pknd6ic!C6MUs$U$-~TG z1QiI003*m9RRE)BLL#6NaeR&rj2ZU;m5P8${h&xbpz;f#avjvlW+4$e0D$rPf@mh^auI zExpSSczz@qe3m^hWy|}mfJO_Uoj!(U+7GIu*%~te7ulG}FwzW(HwRK+s2~+aN-|)g zVlQZp{HOw6YKKPZ2}GxI|C=e3yg@J#_v8$R`!?D9c;MRJY|Tu%59TGx1nrC&}76mqhY@L+wl3# z?T&M;ZA#~8G=bapW8p;;qfwQhR#u(7b6Jw_t`^f67Kg%H4AIkLH?3Ld^S6kz;JV{N zZ;QhGdh$(l03O*gXRZ9f!nhehmF~*awM&w`-rm6ZAUt%2U3in}PyXwQ&AH)*<5W|J z{e)Nl5JVG*m}8%e-N2&ITN_cGNoGa+mZUINal1;yvnoNK=aj(c?V?}Ah&T~Z{c2%} zd4RXB(kC(_BAeM2hLLyCFJKs*4xAS-IwLGIu3%RfLGM+J-Yw)1;jnegFUf07*qoM6N<$f+pCAS^xk5 literal 0 HcmV?d00001