diff --git a/apps/widtemp/ChangeLog b/apps/widtemp/ChangeLog new file mode 100644 index 000000000..af7f83942 --- /dev/null +++ b/apps/widtemp/ChangeLog @@ -0,0 +1 @@ +0.01: Initial release diff --git a/apps/widtemp/README.md b/apps/widtemp/README.md new file mode 100644 index 000000000..54ff4eebd --- /dev/null +++ b/apps/widtemp/README.md @@ -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) + diff --git a/apps/widtemp/metadata.json b/apps/widtemp/metadata.json new file mode 100644 index 000000000..7b28acd38 --- /dev/null +++ b/apps/widtemp/metadata.json @@ -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"} + ] + } diff --git a/apps/widtemp/screenshot.jpg b/apps/widtemp/screenshot.jpg new file mode 100644 index 000000000..4a1ab64e6 Binary files /dev/null and b/apps/widtemp/screenshot.jpg differ diff --git a/apps/widtemp/wid.js b/apps/widtemp/wid.js new file mode 100644 index 000000000..bd3197ade --- /dev/null +++ b/apps/widtemp/wid.js @@ -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}; +})() diff --git a/apps/widtemp/widtemp.png b/apps/widtemp/widtemp.png new file mode 100644 index 000000000..25b1e4c65 Binary files /dev/null and b/apps/widtemp/widtemp.png differ