diff --git a/apps.json b/apps.json index 96a224d6e..cb40456fe 100644 --- a/apps.json +++ b/apps.json @@ -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", diff --git a/apps/weather/ChangeLog b/apps/weather/ChangeLog index d202a5562..8d8585db9 100644 --- a/apps/weather/ChangeLog +++ b/apps/weather/ChangeLog @@ -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. \ No newline at end of file +0.04: Adjust "weather unknown" message according to Bluetooth connection. +0.05: Add wind direction. \ No newline at end of file diff --git a/apps/weather/app.js b/apps/weather/app.js index 288f0a3e3..6ea043467 100644 --- a/apps/weather/app.js +++ b/apps/weather/app.js @@ -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); diff --git a/apps/weather/lib.js b/apps/weather/lib.js index fffc523ca..597eac105 100644 --- a/apps/weather/lib.js +++ b/apps/weather/lib.js @@ -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')||{}; diff --git a/apps/weather/screenshot.png b/apps/weather/screenshot.png index ce79b3b64..0cd6de46a 100644 Binary files a/apps/weather/screenshot.png and b/apps/weather/screenshot.png differ