Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HRM Widget+ adds bpm digits in lato font, plus some README, icon, screenshot fixes #3018

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/widhrt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions apps/widhrtplus/README.md
Original file line number Diff line number Diff line change
@@ -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/)
Binary file added apps/widhrtplus/icons8-heart-20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions apps/widhrtplus/metadata.json
Original file line number Diff line number Diff line change
@@ -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"}
]
}
Binary file added apps/widhrtplus/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions apps/widhrtplus/widget.js
Original file line number Diff line number Diff line change
@@ -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);
}};
})();
Binary file added apps/widhrtplus/widget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.