Initial release of widtemp temperature widget

pull/2688/head
mgellner 2023-04-10 18:01:59 +02:00
parent a33a6df463
commit 089a9a7d0d
6 changed files with 59 additions and 0 deletions

1
apps/widtemp/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: Initial release

7
apps/widtemp/README.md Normal file
View File

@ -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.
![](screenshot.jpg)

View File

@ -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"}
]
}

BIN
apps/widtemp/screenshot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

34
apps/widtemp/wid.js Normal file
View File

@ -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};
})()

BIN
apps/widtemp/widtemp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B