diff --git a/apps.json b/apps.json index aef51980f7..cb40456fe5 100644 --- a/apps.json +++ b/apps.json @@ -531,7 +531,7 @@ { "id": "weather", "name": "Weather", "icon": "icon.png", - "version":"0.03", + "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 5e27e1bf43..8d8585db95 100644 --- a/apps/weather/ChangeLog +++ b/apps/weather/ChangeLog @@ -1,2 +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. \ No newline at end of file +0.03: Fix flickering last updated time. +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 ea89368861..6ea0434677 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); @@ -56,10 +60,14 @@ } function update() { + NRF.removeListener("connect", update); if (weather.current) { draw(); + } else if (NRF.getSecurityStatus().connected) { + E.showMessage("Weather unknown\n\nIs Gadgetbridge\nweather reporting\nset up on your\nphone?"); } else { - E.showMessage('Weather unknown\n\nIs Gadgetbridge\nconnected?'); + E.showMessage("Weather unknown\n\nGadgetbridge\nnot connected"); + NRF.on("connect", update); } } @@ -77,7 +85,7 @@ weather.on("update", update); - update(weather.current); + update(); // Show launcher when middle button pressed setWatch(Bangle.showLauncher, BTN2, {repeat: false, edge: 'falling'}); diff --git a/apps/weather/lib.js b/apps/weather/lib.js index fffc523ca4..597eac105e 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/readme.md b/apps/weather/readme.md index a326b67dd2..e2fb886b74 100644 --- a/apps/weather/readme.md +++ b/apps/weather/readme.md @@ -1,15 +1,15 @@ # Weather -Shows Gadgetbridge weather reports. +This allows your Bangle.js to display weather reports from the Gadgetbridge app on an Android phone. -This adds a widget with a weather pictogram and the temperature. +It adds a widget with a weather pictogram and the temperature. You can view the full report through the app: ![Screenshot](screenshot.png) ## Setup -See [this guide](https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather) -to setup Gadgetbridge weather reporting. +1. Install [Gadgetbridge for Android](https://f-droid.org/packages/nodomain.freeyourgadget.gadgetbridge/) on your phone. +2. Set up [Gadgetbridge weather reporting](https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather). ## Controls diff --git a/apps/weather/screenshot.png b/apps/weather/screenshot.png index ce79b3b646..0cd6de46aa 100644 Binary files a/apps/weather/screenshot.png and b/apps/weather/screenshot.png differ