mirror of https://github.com/espruino/BangleApps
Intial try to use weather condition code for icon selection
parent
e869ffe415
commit
fdc519c3df
|
@ -9,7 +9,7 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
|
|||
{filly: 1},
|
||||
{type: "h", filly: 0, c: [
|
||||
{type: "custom", width: g.getWidth()/2, height: g.getWidth()/2, valign: -1, txt: "unknown", id: "icon",
|
||||
render: l => weather.drawIcon(l.txt, l.x+l.w/2, l.y+l.h/2, l.w/2-5)},
|
||||
render: l => weather.drawIcon(l, l.x+l.w/2, l.y+l.h/2, l.w/2-5)},
|
||||
{type: "v", fillx: 1, c: [
|
||||
{type: "h", pad: 2, c: [
|
||||
{type: "txt", font: "18%", id: "temp", label: "000"},
|
||||
|
@ -47,6 +47,7 @@ function formatDuration(millis) {
|
|||
|
||||
function draw() {
|
||||
layout.icon.txt = current.txt;
|
||||
layout.icon.cond = current.code;
|
||||
const temp = locale.temp(current.temp-273.15).match(/^(\D*\d*)(.*)$/);
|
||||
layout.temp.label = temp[1];
|
||||
layout.tempUnit.label = temp[2];
|
||||
|
|
|
@ -16,7 +16,7 @@ function scheduleExpiry(json) {
|
|||
|
||||
function update(weatherEvent) {
|
||||
let json = storage.readJSON('weather.json')||{};
|
||||
|
||||
|
||||
if (weatherEvent) {
|
||||
let weather = weatherEvent.clone();
|
||||
delete weather.t;
|
||||
|
@ -55,7 +55,7 @@ scheduleExpiry(storage.readJSON('weather.json')||{});
|
|||
|
||||
exports.drawIcon = function(cond, x, y, r) {
|
||||
var palette;
|
||||
|
||||
|
||||
if (B2) {
|
||||
if (g.theme.dark) {
|
||||
palette = {
|
||||
|
@ -101,7 +101,7 @@ exports.drawIcon = function(cond, x, y, r) {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function drawSun(x, y, r) {
|
||||
g.setColor(palette.sun);
|
||||
g.fillCircle(x, y, r);
|
||||
|
@ -280,5 +280,46 @@ exports.drawIcon = function(cond, x, y, r) {
|
|||
return drawUnknown;
|
||||
}
|
||||
|
||||
chooseIcon(cond)(x, y, r);
|
||||
/*
|
||||
* Choose weather icon to display based on weather conditition code
|
||||
* https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2
|
||||
*/
|
||||
function chooseIconByCode(code) {
|
||||
const codeGroup = Math.round(code / 100);
|
||||
switch (codeGroup) {
|
||||
case 2: return drawThunderstorm;
|
||||
case 3: return drawRain;
|
||||
case 5:
|
||||
switch (code) {
|
||||
case 520: return drawShowerRain;
|
||||
case 521: return drawShowerRain;
|
||||
case 522: return drawShowerRain;
|
||||
case 531: return drawShowerRain;
|
||||
default: return drawRain;
|
||||
}
|
||||
break;
|
||||
case 6: return drawSnow;
|
||||
case 7: return drawMist;
|
||||
case 8:
|
||||
switch (code) {
|
||||
case 800: return drawSun;
|
||||
case 801: return drawFewClouds;
|
||||
case 802: return drawCloud;
|
||||
default: return drawBrokenClouds;
|
||||
}
|
||||
break;
|
||||
default: return drawUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
const code = cond.code || -1;
|
||||
if (code > 0) {
|
||||
chooseIconByCode(code.code)(x, y, r);
|
||||
} else {
|
||||
chooseIcon(cond.txt)(x, y, r);
|
||||
}
|
||||
|
||||
console.log(cond);
|
||||
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue