mirror of https://github.com/espruino/BangleApps
weather: added weather condition to clkinfo
picture is dynamically generated with the weather libpull/2327/head
parent
e8163a6f14
commit
52c807aea5
|
@ -15,3 +15,4 @@
|
||||||
0.16: Don't mark app as clock
|
0.16: Don't mark app as clock
|
||||||
0.17: Added clkinfo for clocks.
|
0.17: Added clkinfo for clocks.
|
||||||
0.18: Added hasRange to clkinfo.
|
0.18: Added hasRange to clkinfo.
|
||||||
|
0.19: Added weather condition to clkinfo.
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
temp: "?",
|
temp: "?",
|
||||||
hum: "?",
|
hum: "?",
|
||||||
wind: "?",
|
wind: "?",
|
||||||
|
txt: "?",
|
||||||
};
|
};
|
||||||
|
|
||||||
var weatherJson = require("Storage").readJSON('weather.json');
|
var weatherJson = require("Storage").readJSON('weather.json');
|
||||||
|
@ -14,17 +15,34 @@
|
||||||
weather.wind = Math.round(weather.wind[1]) + "kph";
|
weather.wind = Math.round(weather.wind[1]) + "kph";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function weatherIcon(code) {
|
||||||
|
var ovr = Graphics.createArrayBuffer(24,24,1,{msb:true});
|
||||||
|
require("weather").drawIcon({code:code},12,12,12,ovr);
|
||||||
|
var img = ovr.asImage();
|
||||||
|
img.transparent = 0;
|
||||||
|
//for (var i=0;i<img.buffer.length;i++) img.buffer[i]^=255;
|
||||||
|
return img;
|
||||||
|
//g.setColor("#0ff").drawImage(img, 42, 42);
|
||||||
|
}
|
||||||
|
|
||||||
//FIXME ranges are somehow arbitrary
|
//FIXME ranges are somehow arbitrary
|
||||||
var weatherItems = {
|
var weatherItems = {
|
||||||
name: "Weather",
|
name: "Weather",
|
||||||
img: atob("GBiBAf+///u5//n7//8f/9wHP8gDf/gB//AB/7AH/5AcP/AQH/DwD/uAD84AD/4AA/wAAfAAAfAAAfAAAfgAA/////+bP/+zf/+zfw=="),
|
img: atob("GBiBAf+///u5//n7//8f/9wHP8gDf/gB//AB/7AH/5AcP/AQH/DwD/uAD84AD/4AA/wAAfAAAfAAAfAAAfgAA/////+bP/+zf/+zfw=="),
|
||||||
items: [
|
items: [
|
||||||
|
{
|
||||||
|
name: "condition",
|
||||||
|
get: () => ({ text: weather.txt, img: weatherIcon(weather.code),
|
||||||
|
v: weather.code}),
|
||||||
|
show: function() { weatherItems.items[0].emit("redraw"); },
|
||||||
|
hide: function () {}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "temperature",
|
name: "temperature",
|
||||||
hasRange : true,
|
hasRange : true,
|
||||||
get: () => ({ text: weather.temp, img: atob("GBiBAAA8AAB+AADnAADDAADDAADDAADDAADDAADbAADbAADbAADbAADbAADbAAHbgAGZgAM8wAN+wAN+wAM8wAGZgAHDgAD/AAA8AA=="),
|
get: () => ({ text: weather.temp, img: atob("GBiBAAA8AAB+AADnAADDAADDAADDAADDAADDAADbAADbAADbAADbAADbAADbAAHbgAGZgAM8wAN+wAN+wAM8wAGZgAHDgAD/AAA8AA=="),
|
||||||
v: parseInt(weather.temp), min: -30, max: 55}),
|
v: parseInt(weather.temp), min: -30, max: 55}),
|
||||||
show: function() { weatherItems.items[0].emit("redraw"); },
|
show: function() { weatherItems.items[1].emit("redraw"); },
|
||||||
hide: function () {}
|
hide: function () {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -32,7 +50,7 @@
|
||||||
hasRange : true,
|
hasRange : true,
|
||||||
get: () => ({ text: weather.hum, img: atob("GBiBAAAEAAAMAAAOAAAfAAAfAAA/gAA/gAI/gAY/AAcfAA+AQA+A4B/A4D/B8D/h+D/j+H/n/D/n/D/n/B/H/A+H/AAH/AAD+AAA8A=="),
|
get: () => ({ text: weather.hum, img: atob("GBiBAAAEAAAMAAAOAAAfAAAfAAA/gAA/gAI/gAY/AAcfAA+AQA+A4B/A4D/B8D/h+D/j+H/n/D/n/D/n/B/H/A+H/AAH/AAD+AAA8A=="),
|
||||||
v: parseInt(weather.hum), min: 0, max: 100}),
|
v: parseInt(weather.hum), min: 0, max: 100}),
|
||||||
show: function() { weatherItems.items[1].emit("redraw"); },
|
show: function() { weatherItems.items[2].emit("redraw"); },
|
||||||
hide: function () {}
|
hide: function () {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -40,7 +58,7 @@
|
||||||
hasRange : true,
|
hasRange : true,
|
||||||
get: () => ({ text: weather.wind, img: atob("GBiBAAHgAAPwAAYYAAwYAAwMfAAY/gAZh3/xg//hgwAAAwAABg///g//+AAAAAAAAP//wH//4AAAMAAAMAAYMAAYMAAMcAAP4AADwA=="),
|
get: () => ({ text: weather.wind, img: atob("GBiBAAHgAAPwAAYYAAwYAAwMfAAY/gAZh3/xg//hgwAAAwAABg///g//+AAAAAAAAP//wH//4AAAMAAAMAAYMAAYMAAMcAAP4AADwA=="),
|
||||||
v: parseInt(weather.wind), min: 0, max: 118}),
|
v: parseInt(weather.wind), min: 0, max: 118}),
|
||||||
show: function() { weatherItems.items[2].emit("redraw"); },
|
show: function() { weatherItems.items[3].emit("redraw"); },
|
||||||
hide: function () {}
|
hide: function () {}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
|
@ -62,12 +62,29 @@ scheduleExpiry(storage.readJSON('weather.json')||{});
|
||||||
* @param x Left
|
* @param x Left
|
||||||
* @param y Top
|
* @param y Top
|
||||||
* @param r Icon Size
|
* @param r Icon Size
|
||||||
|
* @param ovr Graphics instance (or undefined for g)
|
||||||
*/
|
*/
|
||||||
exports.drawIcon = function(cond, x, y, r) {
|
exports.drawIcon = function(cond, x, y, r, ovr) {
|
||||||
var palette;
|
var palette;
|
||||||
|
var monochrome=1;
|
||||||
|
if(!ovr) {
|
||||||
|
ovr = g;
|
||||||
|
monochrome=0;
|
||||||
|
}
|
||||||
|
if(monochrome) {
|
||||||
|
palette = {
|
||||||
|
sun: '#FFF',
|
||||||
|
cloud: '#FFF',
|
||||||
|
bgCloud: '#FFF',
|
||||||
|
rain: '#FFF',
|
||||||
|
lightning: '#FFF',
|
||||||
|
snow: '#FFF',
|
||||||
|
mist: '#FFF',
|
||||||
|
background: '#000'
|
||||||
|
};
|
||||||
|
} else
|
||||||
if (B2) {
|
if (B2) {
|
||||||
if (g.theme.dark) {
|
if (ovr.theme.dark) {
|
||||||
palette = {
|
palette = {
|
||||||
sun: '#FF0',
|
sun: '#FF0',
|
||||||
cloud: '#FFF',
|
cloud: '#FFF',
|
||||||
|
@ -89,7 +106,7 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (g.theme.dark) {
|
if (ovr.theme.dark) {
|
||||||
palette = {
|
palette = {
|
||||||
sun: '#FE0',
|
sun: '#FE0',
|
||||||
cloud: '#BBB',
|
cloud: '#BBB',
|
||||||
|
@ -113,19 +130,19 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawSun(x, y, r) {
|
function drawSun(x, y, r) {
|
||||||
g.setColor(palette.sun);
|
ovr.setColor(palette.sun);
|
||||||
g.fillCircle(x, y, r);
|
ovr.fillCircle(x, y, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawCloud(x, y, r, c) {
|
function drawCloud(x, y, r, c) {
|
||||||
const u = r/12;
|
const u = r/12;
|
||||||
if (c==null) c = palette.cloud;
|
if (c==null) c = palette.cloud;
|
||||||
g.setColor(c);
|
ovr.setColor(c);
|
||||||
g.fillCircle(x-8*u, y+3*u, 4*u);
|
ovr.fillCircle(x-8*u, y+3*u, 4*u);
|
||||||
g.fillCircle(x-4*u, y-2*u, 5*u);
|
ovr.fillCircle(x-4*u, y-2*u, 5*u);
|
||||||
g.fillCircle(x+4*u, y+0*u, 4*u);
|
ovr.fillCircle(x+4*u, y+0*u, 4*u);
|
||||||
g.fillCircle(x+9*u, y+4*u, 3*u);
|
ovr.fillCircle(x+9*u, y+4*u, 3*u);
|
||||||
g.fillPoly([
|
ovr.fillPoly([
|
||||||
x-8*u, y+7*u,
|
x-8*u, y+7*u,
|
||||||
x-8*u, y+3*u,
|
x-8*u, y+3*u,
|
||||||
x-4*u, y-2*u,
|
x-4*u, y-2*u,
|
||||||
|
@ -137,19 +154,23 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
|
|
||||||
function drawBrokenClouds(x, y, r) {
|
function drawBrokenClouds(x, y, r) {
|
||||||
drawCloud(x+1/8*r, y-1/8*r, 7/8*r, palette.bgCloud);
|
drawCloud(x+1/8*r, y-1/8*r, 7/8*r, palette.bgCloud);
|
||||||
|
if(monochrome)
|
||||||
|
drawCloud(x-1/8*r, y+2/16*r, r, palette.background);
|
||||||
drawCloud(x-1/8*r, y+1/8*r, 7/8*r);
|
drawCloud(x-1/8*r, y+1/8*r, 7/8*r);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawFewClouds(x, y, r) {
|
function drawFewClouds(x, y, r) {
|
||||||
drawSun(x+3/8*r, y-1/8*r, 5/8*r);
|
drawSun(x+3/8*r, y-1/8*r, 5/8*r);
|
||||||
|
if(monochrome)
|
||||||
|
drawCloud(x-1/8*r, y+2/16*r, r, palette.background);
|
||||||
drawCloud(x-1/8*r, y+1/8*r, 7/8*r);
|
drawCloud(x-1/8*r, y+1/8*r, 7/8*r);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawRainLines(x, y, r) {
|
function drawRainLines(x, y, r) {
|
||||||
g.setColor(palette.rain);
|
ovr.setColor(palette.rain);
|
||||||
const y1 = y+1/2*r;
|
const y1 = y+1/2*r;
|
||||||
const y2 = y+1*r;
|
const y2 = y+1*r;
|
||||||
const poly = g.fillPolyAA ? p => g.fillPolyAA(p) : p => g.fillPoly(p);
|
const poly = ovr.fillPolyAA ? p => ovr.fillPolyAA(p) : p => ovr.fillPoly(p);
|
||||||
poly([
|
poly([
|
||||||
x-6/12*r, y1,
|
x-6/12*r, y1,
|
||||||
x-8/12*r, y2,
|
x-8/12*r, y2,
|
||||||
|
@ -182,8 +203,8 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
|
|
||||||
function drawThunderstorm(x, y, r) {
|
function drawThunderstorm(x, y, r) {
|
||||||
function drawLightning(x, y, r) {
|
function drawLightning(x, y, r) {
|
||||||
g.setColor(palette.lightning);
|
ovr.setColor(palette.lightning);
|
||||||
g.fillPoly([
|
ovr.fillPoly([
|
||||||
x-2/6*r, y-r,
|
x-2/6*r, y-r,
|
||||||
x-4/6*r, y+1/6*r,
|
x-4/6*r, y+1/6*r,
|
||||||
x-1/6*r, y+1/6*r,
|
x-1/6*r, y+1/6*r,
|
||||||
|
@ -194,8 +215,9 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawBrokenClouds(x, y-1/3*r, r);
|
if(monochrome) drawBrokenClouds(x, y-1/3*r, r);
|
||||||
drawLightning(x-1/12*r, y+1/2*r, 1/2*r);
|
drawLightning(x-1/12*r, y+1/2*r, 1/2*r);
|
||||||
|
drawBrokenClouds(x, y-1/3*r, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawSnow(x, y, r) {
|
function drawSnow(x, y, r) {
|
||||||
|
@ -210,7 +232,7 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.setColor(palette.snow);
|
ovr.setColor(palette.snow);
|
||||||
const w = 1/12*r;
|
const w = 1/12*r;
|
||||||
for(let i = 0; i<=6; ++i) {
|
for(let i = 0; i<=6; ++i) {
|
||||||
const points = [
|
const points = [
|
||||||
|
@ -220,7 +242,7 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
x+w, y+r,
|
x+w, y+r,
|
||||||
];
|
];
|
||||||
rotatePoints(points, x, y, i/3*Math.PI);
|
rotatePoints(points, x, y, i/3*Math.PI);
|
||||||
g.fillPoly(points);
|
ovr.fillPoly(points);
|
||||||
|
|
||||||
for(let j = -1; j<=1; j += 2) {
|
for(let j = -1; j<=1; j += 2) {
|
||||||
const points = [
|
const points = [
|
||||||
|
@ -231,7 +253,7 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
];
|
];
|
||||||
rotatePoints(points, x, y+7/12*r, j/3*Math.PI);
|
rotatePoints(points, x, y+7/12*r, j/3*Math.PI);
|
||||||
rotatePoints(points, x, y, i/3*Math.PI);
|
rotatePoints(points, x, y, i/3*Math.PI);
|
||||||
g.fillPoly(points);
|
ovr.fillPoly(points);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -245,18 +267,18 @@ exports.drawIcon = function(cond, x, y, r) {
|
||||||
[-0.2, 0.3],
|
[-0.2, 0.3],
|
||||||
];
|
];
|
||||||
|
|
||||||
g.setColor(palette.mist);
|
ovr.setColor(palette.mist);
|
||||||
for(let i = 0; i<5; ++i) {
|
for(let i = 0; i<5; ++i) {
|
||||||
g.fillRect(x+layers[i][0]*r, y+(0.4*i-0.9)*r, x+layers[i][1]*r,
|
ovr.fillRect(x+layers[i][0]*r, y+(0.4*i-0.9)*r, x+layers[i][1]*r,
|
||||||
y+(0.4*i-0.7)*r-1);
|
y+(0.4*i-0.7)*r-1);
|
||||||
g.fillCircle(x+layers[i][0]*r, y+(0.4*i-0.8)*r-0.5, 0.1*r-0.5);
|
ovr.fillCircle(x+layers[i][0]*r, y+(0.4*i-0.8)*r-0.5, 0.1*r-0.5);
|
||||||
g.fillCircle(x+layers[i][1]*r, y+(0.4*i-0.8)*r-0.5, 0.1*r-0.5);
|
ovr.fillCircle(x+layers[i][1]*r, y+(0.4*i-0.8)*r-0.5, 0.1*r-0.5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawUnknown(x, y, r) {
|
function drawUnknown(x, y, r) {
|
||||||
drawCloud(x, y, r, palette.bgCloud);
|
drawCloud(x, y, r, palette.bgCloud);
|
||||||
g.setColor(g.theme.fg).setFontAlign(0, 0).setFont('Vector', r*2).drawString("?", x+r/10, y+r/6);
|
ovr.setColor(ovr.theme.fg).setFontAlign(0, 0).setFont('Vector', r*2).drawString("?", x+r/10, y+r/6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "weather",
|
"id": "weather",
|
||||||
"name": "Weather",
|
"name": "Weather",
|
||||||
"version": "0.18",
|
"version": "0.19",
|
||||||
"description": "Show Gadgetbridge weather report",
|
"description": "Show Gadgetbridge weather report",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"screenshots": [{"url":"screenshot.png"}],
|
"screenshots": [{"url":"screenshot.png"}],
|
||||||
|
|
Loading…
Reference in New Issue