mirror of https://github.com/espruino/BangleApps
hasensors: add step count sensor
parent
cf237621f3
commit
a02b5a6f56
|
@ -2,3 +2,4 @@
|
|||
0.02: Add sensor icons
|
||||
Customize code directly, remove config file
|
||||
0.03: Add HRM sensor
|
||||
Add step count sensor
|
||||
|
|
|
@ -23,3 +23,4 @@ Currently creates these sensors:
|
|||
* `<sensor id>_battery_level`: Your watch battery level as percentage
|
||||
* `<sensor id>_battery_state`: `charging` or `discharging`
|
||||
* `<sensor id>_hrm`: Heart rate (only if measured: this app doesn't enable/disable the sensor)
|
||||
* `<sensor id>_steps`: Step Count
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
(function () {
|
||||
const sb = () => require("hasensors").sendBattery();
|
||||
Bangle.on("charging", sb);
|
||||
NRF.on("connect", () => setTimeout(sb, 2000));
|
||||
setInterval(sb, 10 * 60 * 1000);
|
||||
const su = () => require("hasensors").sendUpdate();
|
||||
Bangle.on("charging", su);
|
||||
NRF.on("connect", () => setTimeout(su, 2000));
|
||||
su();
|
||||
setInterval(su, 10 * 60 * 1000);
|
||||
Bangle.on('HRM', h=>require("hasensors").sendHRM(h));
|
||||
})();
|
||||
|
|
|
@ -12,8 +12,7 @@ function post(sensor, data) {
|
|||
});
|
||||
}
|
||||
|
||||
exports.sendBattery = function () {
|
||||
if (!NRF.getSecurityStatus().connected) return;
|
||||
function sendBattery() {
|
||||
const b = E.getBattery(),
|
||||
c = Bangle.isCharging();
|
||||
let i = "mdi:battery";
|
||||
|
@ -40,7 +39,26 @@ exports.sendBattery = function () {
|
|||
icon: i,
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function sendSteps() {
|
||||
post("steps", {
|
||||
state: Bangle.getStepCount(),
|
||||
attributes: {
|
||||
friendly_name: "{name} Step Count",
|
||||
unit_of_measurement: "steps",
|
||||
state_class: "total",
|
||||
icon: "mdi:shoe-print",
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.sendUpdate = function() {
|
||||
if (!NRF.getSecurityStatus().connected) return;
|
||||
sendBattery();
|
||||
sendSteps();
|
||||
}
|
||||
|
||||
|
||||
let hrm_last = 0;
|
||||
const HRM_INTERVAL = 10*60*1000;
|
||||
|
|
Loading…
Reference in New Issue