diff --git a/apps/flashcount/ChangeLog b/apps/flashcount/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/flashcount/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/flashcount/app-icon.js b/apps/flashcount/app-icon.js new file mode 100644 index 000000000..e1cf5fb54 --- /dev/null +++ b/apps/flashcount/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4UA///x3ygHo8H1Jf8AgILLoALVgoLHggLCqAgJioLIqgLDGQsBqtAioOBqoYFqtUAIMVBY9VqwCBDIIAECYILCHowLBrWVBZFlrWWyptGgtq1WqJYI7GrQLCFxGrBYJHEBQNV1Wv9IEBEocFKIOq//qJAIZEAoNq3/+1QMBHoYYBrQLB1J4GitaEYZfGtfvBYJ3HtWr9WlNY0V1Nr1WlC4xIBrWmBZWVrJGFcYILBZY4LBoILIgoNBEILvHDIQ5BBY4IBBYMBMAwLBBA4LPBRMAKAoLRiALWAGw=")) \ No newline at end of file diff --git a/apps/flashcount/app.js b/apps/flashcount/app.js new file mode 100644 index 000000000..e3f925b27 --- /dev/null +++ b/apps/flashcount/app.js @@ -0,0 +1,59 @@ +Bangle.loadWidgets(); +Bangle.drawWidgets(); +E.showMessage("Loading..."); +Bangle.setOptions({hrmPollInterval:5}); +Bangle.setHRMPower(1); + +function drawCounter() { + g.reset().clearRect(0,24,175,90); + //g.drawRect(0,24,175,90); + g.setFontAlign(0,0).setFontVector(60); + g.drawString(count, 88, 60); +} + +function hadPulse() { + count++; + drawCounter(); + g.setColor("#f00").fillCircle(156,156,20); + setTimeout(function() { + g.setColor(g.theme.bg).fillCircle(156,156,20); + }, 500); +} + +if (parseFloat(process.env.VERSION.replace("v","0"))<2019) { + E.showMessage("You need at least firmware 2v19","Error"); +} else if (Bangle.hrmRd(0)!=33) { // wrong sensor - probably VC31 from original bangle.js 2 + E.showMessage("This Bangle.js doesn't have a VC31B HRM sensor","Error"); +} else { + Bangle.setOptions({hrmGreenAdjust:false, hrmWearDetect:false, hrmPushEnv:true}); + Bangle.hrmWr(0x10, 197&0xF8 | 4); // just SLOT2 + Bangle.hrmWr(0x16, 0); // force env to be used as fast as possible + + var samples = 0, samplesHi = 0; + var count = 0; + { + let last = 0; + Bangle.on('HRM-env',v => { + if (v) { + if (!last) hadPulse(); + samplesHi++; + } + last = v; + samples++; + }); + } + + drawCounter(); + setInterval(function() { + g.reset().clearRect(0,90,175,130); + g.setFontAlign(0,0).setFont("6x8:2"); + g.drawString(samples+" sps", 88, 100); + if (samplesHi*5 > samples) { + g.setBgColor("#f00").setColor("#fff"); + g.clearRect(0,110,175,130).drawString("TOO LIGHT",88,120); + } + samples=0; + samplesHi=0; + Bangle.setLCDPower(1); // force LCD on! + }, 1000); +} \ No newline at end of file diff --git a/apps/flashcount/app.png b/apps/flashcount/app.png new file mode 100644 index 000000000..379b9d381 Binary files /dev/null and b/apps/flashcount/app.png differ diff --git a/apps/flashcount/metadata.json b/apps/flashcount/metadata.json new file mode 100644 index 000000000..1c0f785fd --- /dev/null +++ b/apps/flashcount/metadata.json @@ -0,0 +1,13 @@ +{ "id": "flashcount", + "name": "Flash Counter", + "shortName":"FlashCount", + "version":"0.01", + "description": "Count flashes/pulses of light using the heart rate monitor. Requires a VC31B HRM sensor, which should be in most watches except those produced for the original KickStarter campaign.", + "icon": "app.png", + "tags": "", + "supports" : ["BANGLEJS2"], + "storage": [ + {"name":"flashcount.app.js","url":"app.js"}, + {"name":"flashcount.img","url":"app-icon.js","evaluate":true} + ] +}