mirror of https://github.com/espruino/BangleApps
Initial release of widtemp temperature widget
parent
a33a6df463
commit
089a9a7d0d
|
@ -0,0 +1 @@
|
|||
0.01: Initial release
|
|
@ -0,0 +1,7 @@
|
|||
# Temperature widget
|
||||
A simple temperature widget, showing the current microcontroller's internal temperature (E.getTemperature()).
|
||||
|
||||
It updates every minute. If the current temperature is above the last 10 minutes average, the text is shown in red. If below, the text is shown in blue and black otherwise.
|
||||
|
||||

|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"id": "widtemp",
|
||||
"name": "Temperature widget",
|
||||
"version": "0.01",
|
||||
"description": "A temperature widget, showing the current internal temperature",
|
||||
"readme": "README.md",
|
||||
"icon": "widtemp.png",
|
||||
"screenshots": [{"url":"screenshot.jpg"}],
|
||||
"type": "widget",
|
||||
"tags": "widget,health",
|
||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||
"dependencies" : {},
|
||||
"allow_emulator":true,
|
||||
"storage": [
|
||||
{"name":"widtemp.wid.js","url":"widtemp.wid.js"}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 79 KiB |
|
@ -0,0 +1,34 @@
|
|||
(() => {
|
||||
const width = 38;
|
||||
const max_temps_len = 10;
|
||||
let temps = [];
|
||||
|
||||
function push_temp(temp, length) {
|
||||
temps.unshift(temp) > length ? temps.pop() : null;
|
||||
}
|
||||
|
||||
function draw() {
|
||||
const temp = Math.round(E.getTemperature());
|
||||
const sum = temps.reduce((a, b) => a + b, 0);
|
||||
const avg = (sum / temps.length) || 0;
|
||||
|
||||
g.reset();
|
||||
g.setFont("6x8", 2);
|
||||
g.clearRect(this.x, this.y, this.x + width, this.y + 18);
|
||||
|
||||
if (temp > avg) {
|
||||
g.setColor("#ff0000"); // red
|
||||
} else if (temp < avg) {
|
||||
g.setColor("#0096ff"); // blue
|
||||
}
|
||||
|
||||
push_temp(temp, max_temps_len);
|
||||
g.drawString(temp + "°", this.x + 3, this.y + 4);
|
||||
}
|
||||
|
||||
setInterval(function() {
|
||||
WIDGETS["widtemp"].draw(WIDGETS["widtemp"]);
|
||||
}, 60000); // update every minute
|
||||
|
||||
WIDGETS["widtemp"]={area:"tl", width: width, draw:draw};
|
||||
})()
|
Binary file not shown.
After Width: | Height: | Size: 498 B |
Loading…
Reference in New Issue