mirror of https://github.com/espruino/BangleApps
Fix sensors activation/deactivation and fix more pretokenisation issues (doesn't work well with var names with lenght <= 3
parent
40c4673db7
commit
5a7216166f
|
@ -12,6 +12,17 @@ A clock face simulating the classic dotmatrix displays. Shows time, date, compas
|
||||||
* Heart rate monitor
|
* Heart rate monitor
|
||||||
* Multiple colour palletes, swipe to change
|
* Multiple colour palletes, swipe to change
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Sensor readings
|
||||||
|
|
||||||
|
When the display is activated by 'flipping' the watch up, the compass and heart sensors will be activated automatically, but if
|
||||||
|
you activate the LCD through a button press, then the sensors will remain off until you press button-1.
|
||||||
|
|
||||||
|
### Colours
|
||||||
|
|
||||||
|
The display defaults to blue, but you can change this to orange by swiping the screen
|
||||||
|
|
||||||
## Requests
|
## Requests
|
||||||
|
|
||||||
If you have any feature requests, please send an email to the author paulcockrell@gmail.com`
|
If you have any feature requests, please send an email to the author paulcockrell@gmail.com`
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
const storage = require('Storage');
|
const storage = require('Storage');
|
||||||
const settings = (storage.readJSON('setting.json', 1) || {});
|
const settings = (storage.readJSON('setting.json', 1) || {});
|
||||||
const is12Hour = settings["12hour"] || false;
|
const is12Hour = settings["12hour"] || false;
|
||||||
|
const timeout = settings.timeout || 20;
|
||||||
|
|
||||||
const font7x7 = {
|
const font7x7 = {
|
||||||
"empty": "00000000",
|
"empty": "00000000",
|
||||||
|
@ -25,6 +25,7 @@ const font7x7 = {
|
||||||
|
|
||||||
const font5x5 = {
|
const font5x5 = {
|
||||||
"empty": "00000000",
|
"empty": "00000000",
|
||||||
|
"-": "0000FF0000",
|
||||||
"0": "0E1915130E",
|
"0": "0E1915130E",
|
||||||
"1": "0C0404040E",
|
"1": "0C0404040E",
|
||||||
"2": "1E010E101F",
|
"2": "1E010E101F",
|
||||||
|
@ -74,6 +75,7 @@ const COLORS = {
|
||||||
};
|
};
|
||||||
|
|
||||||
let selectedColor = "blue";
|
let selectedColor = "blue";
|
||||||
|
let displayTimeoutRef, sensorTimeoutRef;
|
||||||
|
|
||||||
// Example
|
// Example
|
||||||
// binToHex(["0111110", "1000000", "1000000", "1111110", "1000001", "1000001", "0111110"])
|
// binToHex(["0111110", "1000000", "1000000", "1111110", "1000001", "1000001", "0111110"])
|
||||||
|
@ -109,12 +111,12 @@ function drawGrid(pos, dims, charAsBin, opts) {
|
||||||
};
|
};
|
||||||
const pxl = Object.assign({}, defaultOpts, opts);
|
const pxl = Object.assign({}, defaultOpts, opts);
|
||||||
|
|
||||||
for (let r = 0; r < dims.rows; r++) {
|
for (let rowY = 0; rowY < dims.rows; rowY++) {
|
||||||
const y = pos.y + ((pxl.pxlH + pxl.gap) * r);
|
const y = pos.y + ((pxl.pxlH + pxl.gap) * rowY);
|
||||||
|
|
||||||
for (let c = 7; c > (7 - dims.cols); c--) {
|
for (let colX = 7; colX > (7 - dims.cols); colX--) {
|
||||||
const x = pos.x + ((pxl.pxlW + pxl.gap) * c);
|
const x = pos.x + ((pxl.pxlW + pxl.gap) * colX);
|
||||||
const color = (charAsBin && parseInt(charAsBin[r][c])) ? pxl.onColor : pxl.offColor;
|
const color = (charAsBin && parseInt(charAsBin[rowY][colX])) ? pxl.onColor : pxl.offColor;
|
||||||
|
|
||||||
drawPixel({
|
drawPixel({
|
||||||
x: x,
|
x: x,
|
||||||
|
@ -187,7 +189,7 @@ function drawCompass(lastHeading) {
|
||||||
let angle = cps.heading;
|
let angle = cps.heading;
|
||||||
let heading = angle?
|
let heading = angle?
|
||||||
directions[Math.round(((angle %= 360) < 0 ? angle + 360 : angle) / 45) % 8]:
|
directions[Math.round(((angle %= 360) < 0 ? angle + 360 : angle) / 45) % 8]:
|
||||||
" ";
|
"-- ";
|
||||||
|
|
||||||
heading = (heading + " ").slice(0, 3);
|
heading = (heading + " ").slice(0, 3);
|
||||||
if (lastHeading != heading) drawFont(heading, "5x5", 40, 67);
|
if (lastHeading != heading) drawFont(heading, "5x5", 40, 67);
|
||||||
|
@ -195,7 +197,7 @@ function drawCompass(lastHeading) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawHeart(hrm) {
|
function drawHeart(hrm) {
|
||||||
drawFont((" " + (hrm ? hrm.bpm : '')).slice(-3), "5x5", 109, 67);
|
drawFont((" " + (hrm ? hrm.bpm : "---")).slice(-3), "5x5", 109, 67);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawTime(lastHrs, lastMns, toggle) {
|
function drawTime(lastHrs, lastMns, toggle) {
|
||||||
|
@ -245,6 +247,23 @@ function drawDate(lastDate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSensors(state) {
|
function setSensors(state) {
|
||||||
|
// Already reading sensors and trying to activate sensors, do nothing
|
||||||
|
if (sensorTimeoutRef && state === 1) return;
|
||||||
|
|
||||||
|
// If we are activating the sensors, turn them off again in one minute
|
||||||
|
if (state === 1) {
|
||||||
|
sensorTimeoutRef = setTimeout(() => { setSensors(0); }, 1000 * 60);
|
||||||
|
} else {
|
||||||
|
if (sensorTimeoutRef) {
|
||||||
|
clearInterval(sensorTimeoutRef);
|
||||||
|
sensorTimeoutRef = null;
|
||||||
|
}
|
||||||
|
// Bit nasty, but we only redraw the heart value on sensor callback
|
||||||
|
// but we want to blank out when sensor is off, but no callback for
|
||||||
|
// that so force redraw here
|
||||||
|
drawHeart();
|
||||||
|
}
|
||||||
|
|
||||||
Bangle.setHRMPower(state);
|
Bangle.setHRMPower(state);
|
||||||
Bangle.setCompassPower(state);
|
Bangle.setCompassPower(state);
|
||||||
}
|
}
|
||||||
|
@ -261,6 +280,28 @@ function drawScreen() {
|
||||||
drawDate();
|
drawDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearTimers(){
|
||||||
|
if (displayTimeoutRef) {
|
||||||
|
clearInterval(displayTimeoutRef);
|
||||||
|
displayTimeoutRef = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sensorTimeoutRef) {
|
||||||
|
clearInterval(sensorTimeoutRef);
|
||||||
|
sensorTimeoutRef = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetDisplayTimeout() {
|
||||||
|
if (displayTimeoutRef) clearInterval(displayTimeoutRef);
|
||||||
|
Bangle.setLCDPower(true);
|
||||||
|
|
||||||
|
displayTimeoutRef = setTimeout(() => {
|
||||||
|
if (Bangle.isLCDOn()) Bangle.setLCDPower(false);
|
||||||
|
clearTimers();
|
||||||
|
}, 1000 * timeout);
|
||||||
|
}
|
||||||
|
|
||||||
// Turn sensors on
|
// Turn sensors on
|
||||||
setSensors(1);
|
setSensors(1);
|
||||||
|
|
||||||
|
@ -273,27 +314,41 @@ Bangle.drawWidgets();
|
||||||
|
|
||||||
// Draw screen
|
// Draw screen
|
||||||
drawScreen();
|
drawScreen();
|
||||||
|
resetDisplayTimeout();
|
||||||
|
|
||||||
// Setup callbacks
|
// Setup callbacks
|
||||||
Bangle.on('swipe', (sDir) => {
|
Bangle.on('swipe', (sDir) => {
|
||||||
selectedColor = selectedColor === "blue" ? "orange" : "blue";
|
selectedColor = selectedColor === "blue" ? "orange" : "blue";
|
||||||
clearTimeout();
|
resetDisplayTimeout();
|
||||||
drawScreen();
|
drawScreen();
|
||||||
});
|
});
|
||||||
|
|
||||||
Bangle.on('HRM', drawHeart);
|
Bangle.on('HRM', drawHeart);
|
||||||
|
|
||||||
|
setWatch(() => {
|
||||||
|
setSensors(1);
|
||||||
|
resetDisplayTimeout();
|
||||||
|
}, BTN1, {repeat: true, edge: "falling"});
|
||||||
|
|
||||||
setWatch(() => {
|
setWatch(() => {
|
||||||
setSensors(0);
|
setSensors(0);
|
||||||
|
clearTimers();
|
||||||
Bangle.setLCDMode();
|
Bangle.setLCDMode();
|
||||||
Bangle.showLauncher();
|
Bangle.showLauncher();
|
||||||
}, BTN2, {repeat: false, edge: "falling"});
|
}, BTN2, {repeat: false, edge: "falling"});
|
||||||
|
|
||||||
Bangle.on('lcdPower', (on) => on ? setSensors(1) : setSensors(0));
|
Bangle.on('lcdPower', (on) => {
|
||||||
|
if(on) {
|
||||||
|
resetDisplayTimeout();
|
||||||
|
} else {
|
||||||
|
clearTimers();
|
||||||
|
setSensors(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Bangle.on('faceUp', (up) => {
|
Bangle.on('faceUp', (up) => {
|
||||||
if (up && !Bangle.isLCDOn()) {
|
if (up && !Bangle.isLCDOn()) {
|
||||||
setSensors(1);
|
setSensors(1);
|
||||||
Bangle.setLCDPower(true);
|
resetDisplayTimeout();
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue