diff --git a/apps/widhrt/README.md b/apps/widhrt/README.md index dc1bb4388c..0cb1b984a7 100644 --- a/apps/widhrt/README.md +++ b/apps/widhrt/README.md @@ -3,8 +3,7 @@ A simple widget that shows the on/off status of the Heart Rate Monitor. -- Uses Bangle.isHRTOn(). Requires firmware v2.08.167 or later. -- Shows in grey when the HRT is off +- Shows in white/black when the HRT is off - Shows in red when the HRT is on Written by: [Hugh Barney](https://github.com/hughbarney) For support diff --git a/apps/widhrtplus/README.md b/apps/widhrtplus/README.md new file mode 100644 index 0000000000..7231e938fe --- /dev/null +++ b/apps/widhrtplus/README.md @@ -0,0 +1,14 @@ +# Heart Rate Widget+ + +A simple widget that shows the on/off status of the Heart Rate +Monitor and the last measured value. + +- Shows in red when the HRM is on +- Shows in black or white (foreground colour) when the HRM is off +- Does not power the HRM on or off. Relies on the Health app to do that. +- Resizes widget based on value of heart rate +- Uses Lato font so looks consistant with Lato Pedometer and Yet Another Battery Widget + +Written by: [Hugh Barney](https://github.com/hughbarney) For support +and discussion please post in the [Bangle JS +Forum](http://forum.espruino.com/microcosms/1424/) diff --git a/apps/widhrtplus/icons8-heart-20.png b/apps/widhrtplus/icons8-heart-20.png new file mode 100644 index 0000000000..d0e8015023 Binary files /dev/null and b/apps/widhrtplus/icons8-heart-20.png differ diff --git a/apps/widhrtplus/metadata.json b/apps/widhrtplus/metadata.json new file mode 100644 index 0000000000..ce19b9ceea --- /dev/null +++ b/apps/widhrtplus/metadata.json @@ -0,0 +1,15 @@ +{ + "id": "widhrtplus", + "name": "HRM Widget+", + "icon": "widget.png", + "screenshots": [{"url":"screenshot.png"}], + "version":"0.01", + "type": "widget", + "supports": ["BANGLEJS2"], + "readme": "README.md", + "description": "Widget to display heart rate and status of Heart Rate Monitor", + "tags": "widget", + "storage": [ + {"name":"widhrtplus.wid.js","url":"widget.js"} + ] + } diff --git a/apps/widhrtplus/screenshot.png b/apps/widhrtplus/screenshot.png new file mode 100644 index 0000000000..8967405bef Binary files /dev/null and b/apps/widhrtplus/screenshot.png differ diff --git a/apps/widhrtplus/widget.js b/apps/widhrtplus/widget.js new file mode 100644 index 0000000000..c2fdda9d3b --- /dev/null +++ b/apps/widhrtplus/widget.js @@ -0,0 +1,49 @@ +(function(){ + if (!Bangle.isHRMOn) return; // old firmware + var hp = Bangle.setHRMPower; + Bangle.setHRMPower = () => { + hp.apply(Bangle, arguments); + WIDGETS.widhrt.draw(); + }; + + var bp = Math.round(Bangle.getHealthStatus().bpm||Bangle.getHealthStatus("last").bpm); + + Bangle.on('HRM',(e)=>{ + //console.log('onHrm'); + if (e && e.confidence>60) bp = Math.round(e.bpm); + if (bp == 0) bp = Math.round(Bangle.getHealthStatus().bpm||Bangle.getHealthStatus("last").bpm); + WIDGETS["widhrt"].draw(); + }); + + WIDGETS.widhrt={area:"tr",sortorder:9,width:56,draw:function() { + g.reset(); + // Lato from fonts.google.com, Actual height 17 (17 - 1), Numeric only + g.setFontCustom(atob("AAAAABwAAOAAAgAAHAADwAD4AB8AB8AA+AAeAADAAAAOAAP+AH/8B4DwMAGBgAwMAGBgAwOAOA//gD/4AD4AAAAAAAABgAAcAwDAGAwAwP/+B//wAAGAAAwAAGAAAAAAAAIAwHgOA4DwMA+BgOwMDmBg4wOeGA/gwDwGAAAAAAAAAGAHA8A4DwMAGBhAwMMGBjgwOcOA+/gDj4AAAAABgAAcAAHgADsAA5gAOMAHBgBwMAP/+B//wABgAAMAAAAAAAgD4OB/AwOYGBjAwMYGBjBwMe8Bh/AIHwAAAAAAAAAfAAP8AHxwB8GAdgwPMGBxgwMOOAB/gAH4AAAAAAABgAAMAABgAwMAeBgPgMHwBj4AN8AB+AAPAABAAAAAAAMfAH38B/xwMcGBhgwMMGBjgwP+OA+/gDj4AAAAAAAAOAAH4AA/gQMMGBgzwME8BhvAOPgA/4AD8AAEAAAAAAGAwA4OAHBwAAA="), 46, atob("BAgMDAwMDAwMDAwMBQ=="), 21+(1<<8)+(1<<16)); + //console.log("hrm=" + bp); + + var text_w = g.stringWidth(bp); + var hw = 20; // heart image width + var w = text_w + 3 + hw + 2; + // we need this to be able to shrink or grow on the 3,2,1 digit bpm + if (w != this.width) {this.width = w; setTimeout(() => Bangle.drawWidgets(),10); return;} + //var h = 12; // height + + g.setColor(g.theme.bg); + g.fillRect(this.x, this.y, this.x + this.width, this.y + 23); // erase background + g.setColor(g.theme.fg); + g.setFontAlign(-1, 0); + g.drawString(bp, this.x, this.y + 12); + var x = this.x + text_w + 3; + + // draw image + if (Bangle.isHRMOn()) { + g.setColor('#f00'); // on = red + } else { + g.setColor(g.theme.dark ? '#fff' : '#000'); // off + } + + // image converter https://www.espruino.com/Image+Converter ; settings to get a fillable image + // 1 bit bw, transparency? Y, transparent bg, white heart (must be white for color fill) + g.drawImage(atob("FBSBAAAAAAAAAAAB+fg//8f//n//5//+f//n//5//+P//D//wf/4D/8Af+AB+AAPAABgAAAA"), x, 1+this.y); + }}; +})(); diff --git a/apps/widhrtplus/widget.png b/apps/widhrtplus/widget.png new file mode 100644 index 0000000000..8060d93ecd Binary files /dev/null and b/apps/widhrtplus/widget.png differ