mirror of https://github.com/espruino/BangleApps
parent
f2a02642fd
commit
2d387c8e07
|
@ -4964,7 +4964,7 @@
|
|||
{
|
||||
"id": "coretemp",
|
||||
"name": "CoreTemp",
|
||||
"version": "0.03",
|
||||
"version": "0.02",
|
||||
"description": "Display CoreTemp device sensor data",
|
||||
"icon": "coretemp.png",
|
||||
"type": "app",
|
||||
|
@ -4978,7 +4978,8 @@
|
|||
{"name":"coretemp.img","url":"coretemp-icon.js","evaluate":true},
|
||||
{"name":"coretemp.boot.js","url":"boot.js"}
|
||||
],
|
||||
"data": [{"name":"coretemp.json","url":"app-settings.json"}]
|
||||
"data": [{"name":"coretemp.json","url":"app-settings.json"}],
|
||||
"screenshots": [{"url":"screenshot.png"}]
|
||||
},
|
||||
{
|
||||
"id": "showimg",
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
0.01: New app
|
||||
0.02: Cleanup interface and add settings, widget, add skin temp reporting.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// If enabled in settings run constantly in background
|
||||
//
|
||||
(function() {
|
||||
|
||||
var log = function() {};//print
|
||||
var settings = {};
|
||||
var device;
|
||||
var gatt;
|
||||
|
@ -28,8 +28,16 @@ class CoreSensor {
|
|||
this.unit = "C";
|
||||
}
|
||||
|
||||
if (flags & 1) this.skin = (dv.buffer[4] * 256 + dv.buffer[3]) / 100;
|
||||
if (flags & 2) this.core = (dv.buffer[2] * 256 + dv.buffer[1]) / 100;
|
||||
if (flags & 1) {
|
||||
this.skin = (dv.buffer[4] * 256 + dv.buffer[3]) / 100;
|
||||
} else {
|
||||
this.skin = 0;
|
||||
}
|
||||
if (flags & 2) {
|
||||
this.core = (dv.buffer[2] * 256 + dv.buffer[1]) / 100;
|
||||
} else {
|
||||
this.core = 0;
|
||||
}
|
||||
|
||||
Bangle.emit('CoreTemp',
|
||||
{core : this.core, skin : this.skin, unit : this.unit});
|
||||
|
@ -55,11 +63,11 @@ function getSensorBatteryLevel(gatt) {
|
|||
}
|
||||
|
||||
function connection_setup() {
|
||||
console.log("Scanning for CoreTemp sensor...");
|
||||
log("Scanning for CoreTemp sensor...");
|
||||
NRF.requestDevice({timeout : 20000, filters : [ {namePrefix : 'CORE'} ]})
|
||||
.then(function(d) {
|
||||
device = d;
|
||||
console.log("Found device");
|
||||
log("Found device");
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(function(g) {
|
||||
|
@ -78,27 +86,28 @@ function connection_setup() {
|
|||
return characteristic.startNotifications();
|
||||
})
|
||||
.then(function() {
|
||||
console.log("Done!");
|
||||
// getSensorBatteryLevel(gatt);
|
||||
// g.reset().clearRect(Bangle.appRect).flip();
|
||||
log("Done!");
|
||||
// getSensorBatteryLevel(gatt);
|
||||
// g.reset().clearRect(Bangle.appRect).flip();
|
||||
})
|
||||
.catch(function(e) {
|
||||
console.log(e.toString(), "ERROR");
|
||||
console.log(e);
|
||||
log(e.toString(), "ERROR");
|
||||
log(e);
|
||||
});
|
||||
}
|
||||
|
||||
function connection_end() {
|
||||
if (gatt != undefined) gatt.disconnect();
|
||||
if (gatt != undefined)
|
||||
gatt.disconnect();
|
||||
}
|
||||
|
||||
settings = require("Storage").readJSON("coretemp.json",1)||{};
|
||||
console.log("Settings:");
|
||||
console.log(settings);
|
||||
settings = require("Storage").readJSON("coretemp.json", 1) || {};
|
||||
log("Settings:");
|
||||
log(settings);
|
||||
|
||||
if (settings.enabled) {
|
||||
connection_setup();
|
||||
NRF.on('disconnect', connection_setup);
|
||||
connection_setup();
|
||||
NRF.on('disconnect', connection_setup);
|
||||
}
|
||||
|
||||
E.on('kill', () => { connection_end(); });
|
||||
|
|
|
@ -1,76 +1,66 @@
|
|||
// Simply listen for core events and show data
|
||||
|
||||
Bangle.setLCDPower(1);
|
||||
Bangle.setLCDTimeout(0);
|
||||
|
||||
var btm = g.getHeight() - 1;
|
||||
var px = g.getWidth() / 2;
|
||||
|
||||
// Dark or light logo
|
||||
var col = (process.env.HWVERSION == 1) ? 65535 : 0;
|
||||
|
||||
var corelogo = {
|
||||
width : 146,
|
||||
height : 48,
|
||||
bpp : 4,
|
||||
transparent : 0,
|
||||
palette : new Uint16Array([ 65535, 65535, 2854, 1419 ]),
|
||||
palette : new Uint16Array([ col, col, 2854, 1419 ]),
|
||||
buffer :
|
||||
require("heatshrink")
|
||||
.decompress(atob(
|
||||
"AEUDmczmBD/I4xJ/AAMCkBHFAAJG8kQABJAJHFSVURAAUQRphHCkQGBJAySngJHDJRhHEJALZDAgiSBEQ0RPBIAKHAwQQI4xIEaoQFEEZpIULSRHFkDZDBwZIMEYhITa44SKSAxIDSARIDJ4IjKJCpHNEoiQGJDA2CJCQSOCYaQGJDBsCGiKQGTZIJCI4xBEJBAAEFpQAPDQoMGBQyOGIJJPGF6AALC5glCbJAQEgZCEAoowTSBypJBwKQMIQaSBAgZIJWw5ITB5RTDSBLbEAAjDOPRIVabIiQFJBCQKPYhIVCRxIEBg7WDSBpIVbJ5IQJIqQBgZIiCh7ZLJIriDbhJI3JoxIebIZITI6BIjCZ5IRI4RIPHAYAJJH4AIUAJIzHIhI/SAwzBJH6QGJH5HIHApI2HCIAJL4pITkATOJQJIMHCJeFJD8zaZCQHJCEBJCUCJCKPBJBhWGJEcia5oACJBSfHJB4QMJA6SLI4ZIKPAg3QJCUAJCbbBJETbPJAbbKbIhIBYJpIQbZ5UDbZzZFPBxIVSRIOBJA5JISAhIIF4ZIUfQpJHEwQKDJAhJHbJbBJJCIZECY4KGSQoABBIZOBSBbbIJC6IEBQqSJJoyQLbZBIRbYoAKJAaSHJAjbCF541RSRISLSRkgJAKQKbY5ISJJyQDSRyQMbYxITChhHFSRhGMbY5IUCpRHHJJZITiBIVbpBHJbpJHPFhBITfI4ANIwcgI6AAV"))
|
||||
};
|
||||
|
||||
first = true;
|
||||
function onCore(c) {
|
||||
var core = "Core: " + c.core + c.unit;
|
||||
var skin = "Skin: " + c.skin + c.unit;
|
||||
// Large or small font
|
||||
var sz = ((process.env.HWVERSION == 1) ? 3 : 2);
|
||||
|
||||
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.setColor(0xC618); // Light gray
|
||||
g.setFont("6x8", 3).drawString(core, px, 48 + 48);
|
||||
g.setFont("6x8", 3).drawString(skin, px, 48 + 48 + 24);
|
||||
g.clearRect(0, 32 + 48, g.getWidth(), 32 + 48 + 24 * 4);
|
||||
g.setColor(g.theme.dark ? "#CCC" : "#333"); // gray
|
||||
g.setFont("6x8", sz).drawString(
|
||||
"Core: " + ((c.core < 327) ? (c.core + c.unit) : 'n/a'), px, 48 + 48);
|
||||
g.setFont("6x8", sz).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);
|
||||
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
drawBackground("Waiting for\ndata...");
|
||||
}
|
||||
}
|
||||
|
||||
function drawMessage() {
|
||||
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("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);
|
||||
}
|
||||
function drawBackground(message) {
|
||||
g.clear();
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
g.reset().setFont("6x8", 2).setFontAlign(0, 0);
|
||||
g.drawImage(corelogo, px - 146 / 2, 30);
|
||||
g.drawString(message, g.getWidth() / 2, g.getHeight() / 2 + 16);
|
||||
}
|
||||
|
||||
setWatch(() => { enableSensor(); }, BTN2, {repeat : false});
|
||||
Bangle.on('CoreTemp', onCore);
|
||||
|
||||
drawMessage();
|
||||
settings = require("Storage").readJSON("coretemp.json", 1) || {};
|
||||
|
||||
if (!settings.enabled) {
|
||||
drawBackground("Sensor off\nBTN" +
|
||||
((process.env.HWVERSION == 1) ? '2' : '1') + " to enable");
|
||||
} else {
|
||||
drawBackground("Waiting for\ndata...");
|
||||
}
|
||||
|
||||
setWatch(() => { enableSensor(); }, (process.env.HWVERSION == 1) ? BTN2 : BTN1,
|
||||
{repeat : false});
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
|
@ -1,42 +1,39 @@
|
|||
// 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("DAyBAAHh0js3EuDMA8A8AWBnDj9A8A=="),
|
||||
this.x+(24-12)/2,this.y+1);
|
||||
|
||||
g.setColor(g.theme.fg);
|
||||
g.drawString(parseInt(core)+"\n."+parseInt((core*100)%100), this.x + 24 / 2, this.y + 18);
|
||||
|
||||
g.setColor(-1);
|
||||
}
|
||||
|
||||
// Set a listener to 'blink'
|
||||
function onTemp(temp) {
|
||||
count = count + 1;
|
||||
core = temp.core;
|
||||
WIDGETS["coretemp"].draw();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
Fix interface.html
|
||||
0.03: Fix theme and maps/graphing if no GPS
|
||||
0.04: Multiple bugfixes
|
||||
0.05: Add recording for coresensor
|
||||
|
|
Loading…
Reference in New Issue