2022-09-19 15:23:37 +00:00
|
|
|
(function() {
|
|
|
|
var weather = {
|
|
|
|
temp: "?",
|
|
|
|
hum: "?",
|
|
|
|
wind: "?",
|
2022-11-27 14:03:28 +00:00
|
|
|
txt: "?",
|
2022-09-19 15:23:37 +00:00
|
|
|
};
|
|
|
|
|
2022-08-11 11:07:28 +00:00
|
|
|
var weatherJson = require("Storage").readJSON('weather.json');
|
2022-09-19 15:23:37 +00:00
|
|
|
if(weatherJson !== undefined && weatherJson.weather !== undefined){
|
|
|
|
weather = weatherJson.weather;
|
2022-08-11 11:07:28 +00:00
|
|
|
weather.temp = require("locale").temp(weather.temp-273.15);
|
2022-09-19 15:23:37 +00:00
|
|
|
weather.hum = weather.hum + "%";
|
2022-08-11 11:07:28 +00:00
|
|
|
weather.wind = require("locale").speed(weather.wind).match(/^(\D*\d*)(.*)$/);
|
2022-09-19 15:23:37 +00:00
|
|
|
weather.wind = Math.round(weather.wind[1]) + "kph";
|
|
|
|
}
|
|
|
|
|
2022-11-27 14:03:28 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-08-11 11:07:28 +00:00
|
|
|
//FIXME ranges are somehow arbitrary
|
2022-09-19 15:23:37 +00:00
|
|
|
var weatherItems = {
|
|
|
|
name: "Weather",
|
2022-12-04 15:42:24 +00:00
|
|
|
img: atob("GBiBAABAAARGAAYEAADgACP4wDf8gAf+AA/+AE/4AG/jwA/v4A8P8AR/8DH/8AH//AP//g///g///g///gf//AAAAABkwABMgABMgA=="),
|
2022-09-19 15:23:37 +00:00
|
|
|
items: [
|
2022-12-01 14:16:50 +00:00
|
|
|
{
|
|
|
|
name: "conditionWithTemperature",
|
|
|
|
get: () => ({ text: weather.temp, img: weatherIcon(weather.code),
|
|
|
|
v: parseInt(weather.temp), min: -30, max: 55}),
|
2022-12-16 15:40:58 +00:00
|
|
|
show: function() {},
|
2022-12-01 14:16:50 +00:00
|
|
|
hide: function () {}
|
|
|
|
},
|
2022-11-27 14:03:28 +00:00
|
|
|
{
|
|
|
|
name: "condition",
|
|
|
|
get: () => ({ text: weather.txt, img: weatherIcon(weather.code),
|
|
|
|
v: weather.code}),
|
2022-12-16 15:40:58 +00:00
|
|
|
show: function() {},
|
2022-11-27 14:03:28 +00:00
|
|
|
hide: function () {}
|
|
|
|
},
|
2022-09-19 15:23:37 +00:00
|
|
|
{
|
|
|
|
name: "temperature",
|
2022-11-25 17:28:20 +00:00
|
|
|
hasRange : true,
|
2022-08-11 11:07:28 +00:00
|
|
|
get: () => ({ text: weather.temp, img: atob("GBiBAAA8AAB+AADnAADDAADDAADDAADDAADDAADbAADbAADbAADbAADbAADbAAHbgAGZgAM8wAN+wAN+wAM8wAGZgAHDgAD/AAA8AA=="),
|
2022-11-25 17:28:20 +00:00
|
|
|
v: parseInt(weather.temp), min: -30, max: 55}),
|
2022-12-16 15:40:58 +00:00
|
|
|
show: function() {},
|
2022-09-19 15:23:37 +00:00
|
|
|
hide: function () {}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "humidity",
|
2022-11-25 17:28:20 +00:00
|
|
|
hasRange : true,
|
2022-08-11 11:07:28 +00:00
|
|
|
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=="),
|
2022-11-25 17:28:20 +00:00
|
|
|
v: parseInt(weather.hum), min: 0, max: 100}),
|
2022-12-16 15:40:58 +00:00
|
|
|
show: function() {},
|
2022-09-19 15:23:37 +00:00
|
|
|
hide: function () {}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "wind",
|
2022-11-25 17:28:20 +00:00
|
|
|
hasRange : true,
|
2022-08-11 11:07:28 +00:00
|
|
|
get: () => ({ text: weather.wind, img: atob("GBiBAAHgAAPwAAYYAAwYAAwMfAAY/gAZh3/xg//hgwAAAwAABg///g//+AAAAAAAAP//wH//4AAAMAAAMAAYMAAYMAAMcAAP4AADwA=="),
|
2022-11-25 17:28:20 +00:00
|
|
|
v: parseInt(weather.wind), min: 0, max: 118}),
|
2022-12-16 15:40:58 +00:00
|
|
|
show: function() {},
|
2022-09-19 15:23:37 +00:00
|
|
|
hide: function () {}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
return weatherItems;
|
2022-11-21 09:19:31 +00:00
|
|
|
})
|