Added display of steps and ability to switch on heart rate monitor

pull/654/head
hughbarney 2021-01-30 18:28:30 +00:00
parent be086908e8
commit f04f3d139e
2 changed files with 85 additions and 11 deletions

View File

@ -9,6 +9,14 @@ A retro VT100 command line style clock
### With BTN1 pressed
* Successive presses of BTN1 will show id, FW version, battery %, memory %
* Successive presses of BTN1 will show Heart rate, Steps, id, FW version, battery %, memory %
![](cli_clock_with_id.jpg)
* BTN2 shows a functional menu that enables the Heart rate monitor to be turned on / off using BTN1
Once the heart rate monitor is ON, you can cycle through the displays to show the heart rate.
## Future Enhancements
* Ability to turn on the GPS and show, lat long, grid ref
* Maybe a simple stopwatch capability

View File

@ -4,17 +4,21 @@ var marginTop = 40;
var flag = false;
var WeekDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var hrtOn = false;
var hrtStr = "Hrt: ??? bpm";
const NONE_MODE = "none";
const ID_MODE = "id";
const VER_MODE = "ver";
const BATT_MODE = "batt";
const MEM_MODE = "mem";
const STEP_MODE = "step";
const STEPS_MODE = "step";
const HRT_MODE = "hrt";
const NONE_FN_MODE = "no_fn";
const HRT_FN_MODE = "fn_hrt";
let infoMode = NONE_MODE;
let functionMode = NONE_MODE;
let functionMode = NONE_FN_MODE;
function drawAll(){
updateTime();
@ -58,11 +62,29 @@ function drawInfo(line) {
let str = "";
let col = 0x07E0; // green
console.log("drawInfo(), infoMode=" + infoMode + " funcMode=" + functionMode);
switch(functionMode) {
case NONE_FN_MODE:
break;
case HRT_FN_MODE:
col = 0x07FF; // cyan
str = "HRM: " + (hrtOn ? "ON" : "OFF");
drawModeLine(line,str,col);
return;
}
switch(infoMode) {
case NONE_MODE:
col = 0x0000;
str = "";
break;
case HRT_MODE:
str = hrtStr;
break;
case STEPS_MODE:
str = "Steps: " + stepsWidget().getSteps();
break;
case ID_MODE:
val = NRF.getAddress().split(":");
str = "Id: " + val[4] + val[5];
@ -79,6 +101,10 @@ function drawInfo(line) {
str = "Battery: " + E.getBattery() + "%";
}
drawModeLine(line,str,col);
}
function drawModeLine(line, str, col) {
g.setColor(col);
g.fillRect(0, marginTop-3+line*30, 239, marginTop+25+line*30);
g.setColor(0,0,0);
@ -87,8 +113,31 @@ function drawInfo(line) {
}
function changeInfoMode() {
switch(functionMode) {
case NONE_FN_MODE:
break;
case HRT_FN_MODE:
hrtOn = !hrtOn;
Bangle.buzz();
Bangle.setHRMPower(hrtOn ? 1 : 0);
if (hrtOn) infoMode = HRT_MODE;
return;
}
switch(infoMode) {
case NONE_MODE:
if (stepsWidget() !== undefined)
infoMode = hrtOn ? HRT_MODE : STEPS_MODE;
else
infoMode = VER_MODE;
break;
case HRT_MODE:
if (stepsWidget() !== undefined)
infoMode = STEPS_MODE;
else
infoMode = VER_MODE;
break;
case STEPS_MODE:
infoMode = ID_MODE;
break;
case ID_MODE:
@ -107,19 +156,36 @@ function changeInfoMode() {
}
function changeFunctionMode() {
console.log("changeFunctionMode()");
switch(functionMode) {
case NONE_MODE:
functionMode = STEP_MODE;
case NONE_FN_MODE:
functionMode = HRT_FN_MODE;
break;
case STEP_MODE:
functionMode = HRT_MODE;
break;
case HRT_MODE:
case HRT_FN_MODE:
default:
functionMode = NONE_MODE;
functionMode = NONE_FN_MODE;
}
console.log(functionMode);
}
function stepsWidget() {
if (WIDGETS.activepedom !== undefined) {
return WIDGETS.activepedom;
} else if (WIDGETS.wpedom !== undefined) {
return WIDGETS.wpedom;
}
return undefined;
}
Bangle.on('HRM', function(hrm) {
if(hrm.confidence > 90){
hrtStr = "Hrt: " + hrm.bpm + " bpm";
} else {
hrtStr = "Hrt: ??? bpm";
}
});
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
@ -131,4 +197,4 @@ Bangle.on('lcdPower',function(on) {
var click = setInterval(updateTime, 1000);
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
setWatch(() => { changeInfoMode(); drawAll(); }, BTN1, {repeat: true});
setWatch(() => { changeFunctionMode(); drawAll(); }, BTN2, {repeat: true});
setWatch(() => { changeFunctionMode(); drawAll(); }, BTN3, {repeat: true});