Cleanup widget
parent
f2a02642fd
commit
9e8a3b6c92
|
|
@ -1,19 +1,18 @@
|
|||
# CoreTemp display
|
||||
|
||||
Basic bare-bones example of connecting to a bluetooth [CoreTemp](https://corebodytemp.com/) device and displaying the current body core temperature readings.
|
||||
Basic example of connecting to a bluetooth [CoreTemp](https://corebodytemp.com/) device and displaying the current skin and body core temperature readings.
|
||||
|
||||
## Usage
|
||||
|
||||
On startup connects to a CoreTemp device (1809/2A1C) and emits a "Core, temp" value for each reading.
|
||||
The app simply displays these readings on screen.
|
||||
Background task connects to any CoreTemp device (2100/2101) and emits a CoreTemp signal value for each reading.
|
||||
Application contains three components, one is a background task that monitors the sensor and emits a 'CoreTemp' signal on activity if activated in settings.
|
||||
The widget shows when the sensor is enabled with a mini value and blinks on use.
|
||||
The app listens for 'CoreTemp' signals and shows the current skin and core temperatures in large numbers.
|
||||
|
||||
## TODO
|
||||
|
||||
* Integrate with other tracking/sports apps to log data.
|
||||
* Add device selection
|
||||
* Provide enable/disable option
|
||||
* Check status, add Retry/reconnect
|
||||
* Also provide skin temp reading
|
||||
* Add specific device selection
|
||||
|
||||
## Creator
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ Bangle.setLCDPower(1);
|
|||
Bangle.setLCDTimeout(0);
|
||||
|
||||
var btm = g.getHeight() - 1;
|
||||
var px = g.getWidth() / 2;
|
||||
|
||||
var corelogo = {
|
||||
width : 146,
|
||||
height : 48,
|
||||
|
|
@ -16,61 +18,52 @@ var corelogo = {
|
|||
"AEUDmczmBD/I4xJ/AAMCkBHFAAJG8kQABJAJHFSVURAAUQRphHCkQGBJAySngJHDJRhHEJALZDAgiSBEQ0RPBIAKHAwQQI4xIEaoQFEEZpIULSRHFkDZDBwZIMEYhITa44SKSAxIDSARIDJ4IjKJCpHNEoiQGJDA2CJCQSOCYaQGJDBsCGiKQGTZIJCI4xBEJBAAEFpQAPDQoMGBQyOGIJJPGF6AALC5glCbJAQEgZCEAoowTSBypJBwKQMIQaSBAgZIJWw5ITB5RTDSBLbEAAjDOPRIVabIiQFJBCQKPYhIVCRxIEBg7WDSBpIVbJ5IQJIqQBgZIiCh7ZLJIriDbhJI3JoxIebIZITI6BIjCZ5IRI4RIPHAYAJJH4AIUAJIzHIhI/SAwzBJH6QGJH5HIHApI2HCIAJL4pITkATOJQJIMHCJeFJD8zaZCQHJCEBJCUCJCKPBJBhWGJEcia5oACJBSfHJB4QMJA6SLI4ZIKPAg3QJCUAJCbbBJETbPJAbbKbIhIBYJpIQbZ5UDbZzZFPBxIVSRIOBJA5JISAhIIF4ZIUfQpJHEwQKDJAhJHbJbBJJCIZECY4KGSQoABBIZOBSBbbIJC6IEBQqSJJoyQLbZBIRbYoAKJAaSHJAjbCF541RSRISLSRkgJAKQKbY5ISJJyQDSRyQMbYxITChhHFSRhGMbY5IUCpRHHJJZITiBIVbpBHJbpJHPFhBITfI4ANIwcgI6AAV"))
|
||||
};
|
||||
|
||||
first = true;
|
||||
function onCore(c) {
|
||||
var core = "Core: " + c.core + c.unit;
|
||||
var skin = "Skin: " + c.skin + c.unit;
|
||||
|
||||
var px = g.getWidth() / 2;
|
||||
g.setFontAlign(0, 0);
|
||||
if (first) {
|
||||
g.clearRect(0, 24, g.getWidth(), g.getHeight() - 24);
|
||||
g.drawImage(corelogo, px - 146 / 2, 30);
|
||||
first = false;
|
||||
} else {
|
||||
g.clearRect(0, 48 + 48, g.getWidth(), 48 + 48 + 24 * 2);
|
||||
}
|
||||
g.clearRect(0, 48 + 48, g.getWidth(), 48 + 48 + 24 * 2);
|
||||
g.setColor(0xC618); // Light gray
|
||||
g.setFont("6x8", 3).drawString(core, px, 48 + 48);
|
||||
g.setFont("6x8", 3).drawString(skin, px, 48 + 48 + 24);
|
||||
g.setFont("6x8", 3).drawString("Core: " + c.core + c.unit, px, 48 + 48);
|
||||
g.setFont("6x8", 3).drawString("Skin: " + c.skin + c.unit, px, 48 + 48 + 24);
|
||||
}
|
||||
|
||||
Bangle.on('CoreTemp', onCore);
|
||||
|
||||
g.clear();
|
||||
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
|
||||
// Background task will activate if settings are enabled.
|
||||
// Background task will activate once settings are enabled.
|
||||
function enableSensor() {
|
||||
settings = require("Storage").readJSON("coretemp.json", 1) || {};
|
||||
|
||||
if (!settings.enabled) {
|
||||
|
||||
settings.enabled = true;
|
||||
require("Storage").write("coretemp.json", settings);
|
||||
|
||||
drawBackground();
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
}
|
||||
}
|
||||
|
||||
function drawMessage() {
|
||||
settings = require("Storage").readJSON("coretemp.json", 1) || {};
|
||||
g.clearRect(0, 24, g.getWidth(), g.getHeight() - 24);
|
||||
function drawBackground() {
|
||||
g.reset().setFont("6x8", 2).setFontAlign(0, 0);
|
||||
|
||||
if (!settings.enabled) {
|
||||
g.reset().setFont("6x8", 2).setFontAlign(0, 0);
|
||||
g.drawString("Disabled, press BTN2\nto enable.", g.getWidth() / 2,
|
||||
g.getHeight() / 2 - 16);
|
||||
} else {
|
||||
g.reset().setFont("6x8", 2).setFontAlign(0, 0);
|
||||
g.drawString("Please wait...\nWaiting for data", g.getWidth() / 2,
|
||||
g.getHeight() / 2 - 16);
|
||||
}
|
||||
g.clearRect(0, 24, g.getWidth(), g.getHeight() - 24);
|
||||
g.drawImage(corelogo, px - 146 / 2, 30);
|
||||
|
||||
g.drawString("Please wait...\nWaiting for data", g.getWidth() / 2,
|
||||
g.getHeight() / 2 + 16);
|
||||
}
|
||||
|
||||
g.clear();
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
Bangle.on('CoreTemp', onCore);
|
||||
|
||||
settings = require("Storage").readJSON("coretemp.json", 1) || {};
|
||||
g.clearRect(0, 24, g.getWidth(), g.getHeight() - 24);
|
||||
|
||||
if (!settings.enabled) {
|
||||
g.reset().setFont("6x8", 2).setFontAlign(0, 0);
|
||||
g.drawString("Sensor disabled,\nBTN2 to enable.", g.getWidth() / 2,
|
||||
g.getHeight() / 2 - 16);
|
||||
} else {
|
||||
drawBackground();
|
||||
}
|
||||
|
||||
setWatch(() => { enableSensor(); }, BTN2, {repeat : false});
|
||||
|
||||
drawMessage();
|
||||
|
|
|
|||
|
|
@ -1,42 +1,40 @@
|
|||
// TODO Change to generic multiple sensor
|
||||
// TODO Change to a generic multiple sensor widget?
|
||||
|
||||
(() => {
|
||||
var settings = {};
|
||||
var count = 0;
|
||||
|
||||
var img0 = {
|
||||
width : 24,
|
||||
height : 24,
|
||||
bpp : 4,
|
||||
transparent : 0,
|
||||
buffer :
|
||||
require("heatshrink")
|
||||
.decompress(atob(
|
||||
"AA0IxGIBAtms0ABQOIwAKFsAWCDAkGBYQUCBwIKEBYgmBBYoHBC4oKDBAILECwRSFDQQLBsBLDBYg4CNYoKBwALGDQYLCQpALaF45jBBZBfJMIZ3GZgwkGZYibCDIMGWoILDWYbBDd4gMFWoTvFYYgAFEYYHDA=="))
|
||||
};
|
||||
var img1 = {
|
||||
width : 24,
|
||||
height : 24,
|
||||
bpp : 3,
|
||||
transparent : 0,
|
||||
buffer :
|
||||
require("heatshrink")
|
||||
.decompress(atob(
|
||||
"AAkCpMgAwYFBiVJkgHCAoMAyQIBwAIBAoMEyEABAUkBAkEBAdICIkBBAIdBBAcJEwo1BBAI4EAoJBEKAMAiAIEAAIvBLgosBBCYjFJQIIFKwJHFBARZFBwRrCNAKbCC4J0CpApFR4REGBAWShIxDPQSSCYogvEA="))
|
||||
};
|
||||
var core = 0;
|
||||
|
||||
// draw your widget
|
||||
function draw() {
|
||||
if (!settings.enabled)
|
||||
return;
|
||||
g.reset();
|
||||
g.setFont("6x8", 1).setFontAlign(0, 0);
|
||||
g.setFontAlign(0, 0);
|
||||
g.clearRect(this.x, this.y, this.x + 23, this.y + 23);
|
||||
g.drawImage((count & 1) ? img1: img0, this.x, this.y);
|
||||
|
||||
if (count & 1) {
|
||||
g.setColor("#0f0"); // green
|
||||
} else {
|
||||
g.setColor(g.theme.dark ? "#333" : "#CCC"); // off = grey
|
||||
}
|
||||
|
||||
g.drawImage(
|
||||
atob(
|
||||
"GBgBAAHwAHP4A+f8B+4cH+4MH84cPwYcfAf4eAP4+AHi+AAO8AAe8AAe8AAe+AAG+AA4eAA8fAB8PgD4P8b4H/7wB/9gA/8AAP4A"),
|
||||
this.x, this.y);
|
||||
|
||||
g.setColor(g.theme.fg);
|
||||
g.drawString(core, this.x + 24 / 2, this.y + 19);
|
||||
|
||||
g.setColor(-1);
|
||||
}
|
||||
|
||||
// Set a listener to 'blink'
|
||||
function onTemp(temp) {
|
||||
count = count + 1;
|
||||
core = temp.core;
|
||||
WIDGETS["coretemp"].draw();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue