1
0
Fork 0

fix #485: weather: add wind direction

master
Richard de Boer 2021-06-18 20:16:00 +02:00
parent aaadbd89f2
commit 863923a3aa
5 changed files with 26 additions and 4 deletions

View File

@ -531,7 +531,7 @@
{ "id": "weather",
"name": "Weather",
"icon": "icon.png",
"version":"0.04",
"version":"0.05",
"description": "Show Gadgetbridge weather report",
"readme": "readme.md",
"tags": "widget,outdoors",

View File

@ -1,3 +1,4 @@
0.02: Make minor adjustments to widget, and discard stale weather data after a configurable period.
0.03: Fix flickering last updated time.
0.04: Adjust "weather unknown" message according to Bluetooth connection.
0.05: Add wind direction.

View File

@ -30,10 +30,14 @@
g.setFont("6x8", 1);
g.setFontAlign(-1, 0, 0);
g.drawString("Humidity", 135, 130);
g.drawString("Wind", 135, 142);
g.setFontAlign(1, 0, 0);
g.drawString(w.hum+"%", 225, 130);
g.drawString(locale.speed(w.wind), 225, 142);
if ('wind' in w) {
g.setFontAlign(-1, 0, 0);
g.drawString("Wind", 135, 142);
g.setFontAlign(1, 0, 0);
g.drawString(locale.speed(w.wind)+' '+w.wrose.toUpperCase(), 225, 142);
}
g.setFont("6x8", 2).setFontAlign(0, 0, 0);
g.drawString(w.loc, 120, 170);

View File

@ -22,6 +22,20 @@ function scheduleExpiry(json) {
}
}
/**
* Convert numeric direction into human-readable label
*
* @param {number} deg - Direction in degrees
* @return {string|null} - Nearest compass point
*/
function compassRose(deg) {
if (typeof deg === 'undefined') return null;
while (deg<0 || deg>360) {
deg = (deg+360)%360;
}
return ['n','ne','e','se','s','sw','w','nw','n'][Math.floor((deg+22.5)/45)];
}
function setCurrentWeather(json) {
scheduleExpiry(json);
exports.current = json.weather;
@ -30,6 +44,9 @@ function setCurrentWeather(json) {
function update(weatherEvent) {
let weather = Object.assign({}, weatherEvent);
weather.time = Date.now();
if ('wdir' in weather) {
weather.wrose = compassRose(weather.wdir);
}
delete weather.t;
let json = storage.readJSON('weather.json')||{};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB