Skip to content

Commit

Permalink
Merge pull request #3004 from joyrider3774/add_widhrm
Browse files Browse the repository at this point in the history
Add widhr (Last announced heartrate BPM Widget)
  • Loading branch information
gfwilliams authored Sep 11, 2023
2 parents 71be348 + a93e201 commit 4214152
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/widhr/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: First release
10 changes: 10 additions & 0 deletions apps/widhr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Last announced heartrate BPM Widget

* Displays the last announced bpm measurement from Bangle.on('HRM', ...);
* it does not enable the heartrate sensor to do measurements it waits on such annoucement. I use it to view the last read value when letting the system take a reading every 10 minutes.
* saves last read value to a file so it can display that last value between app starts / reboots

![](screenshot_widhr.png)

Code based on Lato Pedometer Written by: [Hugh Barney](https://github.com/hughbarney)
Code Modified by: [Willems Davy](https://github.com/joyrider3774)
19 changes: 19 additions & 0 deletions apps/widhr/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"id": "widhr",
"name": "Last announced heartrate BPM Widget",
"shortName":"Last Heartrate BPM",
"icon": "widhr.icon.png",
"screenshots": [{"url":"screenshot_widhr.png"}],
"version":"0.01",
"type": "widget",
"supports": ["BANGLEJS2"],
"readme": "README.md",
"description": "Displays the last announced heartrate BPM from `Bangle.on(\"HRM\", ...);` (it does not enable the hrm sensor it expects the system or other app todo so)",
"tags": "widget",
"data": [
{"name":"widhr.data.json"}
],
"storage": [
{"name":"widhr.wid.js","url":"widhr.wid.js"}
]
}
Binary file added apps/widhr/screenshot_widhr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/widhr/widhr.icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions apps/widhr/widhr.wid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function widhr_hrm(hrm) {
require("Storage").writeJSON("widhr.data.json", {"bpm":hrm.bpm});
WIDGETS["widhr"].draw();
}

Bangle.on('HRM', widhr_hrm);

function widhr_draw() {
var json = require("Storage").readJSON("widhr.data.json");
var bpm = json === undefined ? 0 : json.bpm;
//3x6 from bpm text in 6x8 font
var w = (bpm.toString().length)*8 > 3 * 6 ? (bpm.toString().length)*8 : 3 * 6;
if (w != this.width)
{
this.width = w;
setTimeout(() => Bangle.drawWidgets(),10); return;
}
g.reset();
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.setFont("6x8:1");
g.setFontAlign(-1, 0);
g.drawString("bpm", this.x, this.y + 5);
g.setFont("4x6:2");
g.setFontAlign(-1, 0);
g.drawString(bpm, this.x, this.y + 17);
}

WIDGETS["widhr"]={area:"tl",sortorder:-1,width:13,draw:widhr_draw};

0 comments on commit 4214152

Please sign in to comment.