forked from FOSS/BangleApps
Merge pull request #3004 from joyrider3774/add_widhrm
Add widhr (Last announced heartrate BPM Widget)master
commit
42141524b2
|
@ -0,0 +1 @@
|
|||
0.01: First release
|
|
@ -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
|
||||
|
||||

|
||||
|
||||
Code based on Lato Pedometer Written by: [Hugh Barney](https://github.com/hughbarney)
|
||||
Code Modified by: [Willems Davy](https://github.com/joyrider3774)
|
|
@ -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 not shown.
After Width: | Height: | Size: 2.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
|
@ -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};
|
Loading…
Reference in New Issue