diff --git a/apps/info/ChangeLog b/apps/info/ChangeLog index 07afedd21..400e7a119 100644 --- a/apps/info/ChangeLog +++ b/apps/info/ChangeLog @@ -1 +1,2 @@ -0.01: Release \ No newline at end of file +0.01: Release +0.02: Recfactoring and show weather data. \ No newline at end of file diff --git a/apps/info/info.app.js b/apps/info/info.app.js index c61a88045..9de80affc 100644 --- a/apps/info/info.app.js +++ b/apps/info/info.app.js @@ -1,27 +1,90 @@ -var s = require("Storage"); +const storage = require("Storage"); const locale = require('locale'); var ENV = process.env; var W = g.getWidth(), H = g.getHeight(); var screen = 0; -const maxScreen = 2; + + +var screens = [ + { + name: "General", + items: [ + {name: "Steps", fun: () => getSteps()}, + {name: "HRM", fun: () => getBpm()}, + {name: "", fun: () => ""}, + {name: "Temp.", fun: () => getWeatherTemp()}, + {name: "Humidity", fun: () => getWeatherHumidity()}, + {name: "Wind", fun: () => getWeatherWind()}, + ] + }, + { + name: "Hardware", + items: [ + {name: "Battery", fun: () => E.getBattery() + "%"}, + {name: "Charge?", fun: () => Bangle.isCharging() ? "Yes" : "No"}, + {name: "TempInt.", fun: () => locale.temp(parseInt(E.getTemperature()))}, + {name: "Bluetooth", fun: () => NRF.getSecurityStatus().connected ? "Conn" : "NoConn"}, + {name: "GPS", fun: () => Bangle.isGPSOn() ? "On" : "Off"}, + {name: "Compass", fun: () => Bangle.isCompassOn() ? "On" : "Off"}, + ] + }, + { + name: "Software", + items: [ + {name: "Firmw.", fun: () => ENV.VERSION}, + {name: "Boot.", fun: () => getVersion("boot.info")}, + {name: "Settings.", fun: () => getVersion("setting.info")}, + {name: "Storage.", fun: () => ""}, + {name: " Total", fun: () => ENV.STORAGE>>10}, + {name: " Free", fun: () => require("Storage").getFree()>>10}, + ] + } +]; + + +function getWeatherTemp(){ + try { + var weather = storage.readJSON('weather.json').weather; + return locale.temp(weather.temp-273.15); + } catch(ex) { } + + return "?"; +} + + +function getWeatherHumidity(){ + try { + var weather = storage.readJSON('weather.json').weather; + return weather.hum = weather.hum + "%"; + } catch(ex) { } + + return "?"; +} + + +function getWeatherWind(){ + try { + var weather = storage.readJSON('weather.json').weather; + var speed = locale.speed(weather.wind).replace("mph", ""); + return Math.round(speed * 1.609344) + "kph"; + } catch(ex) { } + + return "?"; +} + function getVersion(file) { - var j = s.readJSON(file,1); + var j = storage.readJSON(file,1); var v = ("object"==typeof j)?j.version:false; return v?((v?"v"+v:"Unknown")):"NO "; } -function drawData(name, value, y){ - g.drawString(name, 5, y); - g.drawString(value, 100, y); -} - function getSteps(){ try{ return Bangle.getHealthStatus("day").steps; } catch(e) { - return ">= 2v12"; + return ">2v12"; } } @@ -29,53 +92,36 @@ function getBpm(){ try{ return Math.round(Bangle.getHealthStatus("day").bpm) + "bpm"; } catch(e) { - return ">= 2v12"; + return ">2v12"; } } +function drawData(name, value, y){ + g.drawString(name, 10, y); + g.drawString(value, 100, y); +} + function drawInfo() { g.reset().clearRect(Bangle.appRect); var h=18, y = h;//-h; // Header - g.setFont("Vector", h+2).setFontAlign(0,-1); - g.drawString("--==|| INFO ||==--", W/2, 0); + g.drawLine(0,25,W,25); + g.drawLine(0,26,W,26); + + // Info body depending on screen g.setFont("Vector",h).setFontAlign(-1,-1); + screens[screen].items.forEach(function (item, index){ + drawData(item.name, item.fun(), y+=h); + }); - // Dynamic data - if(screen == 0){ - drawData("Steps", getSteps(), y+=h); - drawData("HRM", getBpm(), y+=h); - drawData("Battery", E.getBattery() + "%", y+=h); - drawData("Voltage", E.getAnalogVRef().toFixed(2) + "V", y+=h); - drawData("IntTemp.", locale.temp(parseInt(E.getTemperature())), y+=h); - } - - if(screen == 1){ - drawData("Charging?", Bangle.isCharging() ? "Yes" : "No", y+=h); - drawData("Bluetooth", NRF.getSecurityStatus().connected ? "Conn." : "Disconn.", y+=h); - drawData("GPS", Bangle.isGPSOn() ? "On" : "Off", y+=h); - drawData("Compass", Bangle.isCompassOn() ? "On" : "Off", y+=h); - drawData("HRM", Bangle.isHRMOn() ? "On" : "Off", y+=h); - } - - // Static data - if(screen == 2){ - drawData("Firmw.", ENV.VERSION, y+=h); - drawData("Boot.", getVersion("boot.info"), y+=h); - drawData("Settings", getVersion("setting.info"), y+=h); - drawData("Storage", "", y+=h); - drawData(" Total", ENV.STORAGE>>10, y+=h); - drawData(" Free", require("Storage").getFree()>>10, y+=h); - } - - if(Bangle.isLocked()){ - g.setFont("Vector",h-2).setFontAlign(-1,-1); - g.drawString("Locked", 0, H-h+2); - } - + // Bottom + g.drawLine(0,H-h-3,W,H-h-3); + g.drawLine(0,H-h-2,W,H-h-2); + g.setFont("Vector",h-2).setFontAlign(-1,-1); + g.drawString(screens[screen].name, 2, H-h+2); g.setFont("Vector",h-2).setFontAlign(1,-1); - g.drawString((screen+1) + "/3", W, H-h+2); + g.drawString((screen+1) + "/" + screens.length, W, H-h+2); } drawInfo(); @@ -88,14 +134,15 @@ Bangle.on('touch', function(btn, e){ var isRight = e.x > right; if(isRight){ - screen = (screen + 1) % (maxScreen+1); + screen = (screen + 1) % screens.length; } if(isLeft){ screen -= 1; - screen = screen < 0 ? maxScreen : screen; + screen = screen < 0 ? screens.length-1 : screen; } + Bangle.buzz(40, 0.6); drawInfo(); }); @@ -104,5 +151,4 @@ Bangle.on('lock', function(isLocked) { }); Bangle.loadWidgets(); -for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} -// Bangle.drawWidgets(); \ No newline at end of file +Bangle.drawWidgets(); \ No newline at end of file diff --git a/apps/info/metadata.json b/apps/info/metadata.json index f05f0e134..97aeb687a 100644 --- a/apps/info/metadata.json +++ b/apps/info/metadata.json @@ -1,7 +1,7 @@ { "id": "info", "name": "Info", - "version": "0.01", + "version": "0.02", "description": "An application that displays information such as battery level, steps etc.", "icon": "info.png", "type": "app", diff --git a/apps/info/screenshot_1.png b/apps/info/screenshot_1.png index 97d42a896..25f5b0a8b 100644 Binary files a/apps/info/screenshot_1.png and b/apps/info/screenshot_1.png differ diff --git a/apps/info/screenshot_2.png b/apps/info/screenshot_2.png index 2d25dd4e6..517a83299 100644 Binary files a/apps/info/screenshot_2.png and b/apps/info/screenshot_2.png differ diff --git a/apps/info/screenshot_3.png b/apps/info/screenshot_3.png index 782e4a195..6802495f5 100644 Binary files a/apps/info/screenshot_3.png and b/apps/info/screenshot_3.png differ