weather: add semicolons, replace substr with match
parent
18214da1f4
commit
3e4ac82b90
|
|
@ -50,5 +50,5 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show launcher when middle button pressed
|
// Show launcher when middle button pressed
|
||||||
setWatch(Bangle.showLauncher, BTN2, {repeat: false, edge: 'falling'})
|
setWatch(Bangle.showLauncher, BTN2, {repeat: false, edge: 'falling'});
|
||||||
})()
|
})()
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
exports = {
|
exports = {
|
||||||
save: weather => {
|
save: weather => {
|
||||||
let json = require('Storage').readJSON('weather.json')||{}
|
let json = require('Storage').readJSON('weather.json')||{};
|
||||||
json.weather = Object.assign({}, weather) // don't mutate GB events
|
json.weather = Object.assign({}, weather); // don't mutate GB events
|
||||||
delete json.weather.t // don't save the event type (if present)
|
delete json.weather.t; // don't save the event type (if present)
|
||||||
require('Storage').write('weather.json', json)
|
require('Storage').write('weather.json', json);
|
||||||
},
|
},
|
||||||
load: () => {
|
load: () => {
|
||||||
let json = require('Storage').readJSON('weather.json')||{}
|
let json = require('Storage').readJSON('weather.json')||{};
|
||||||
return json.weather
|
return json.weather;
|
||||||
},
|
},
|
||||||
drawIcon: (cond, x, y, r) => {
|
drawIcon: (cond, x, y, r) => {
|
||||||
function drawSun(x, y, r) {
|
function drawSun(x, y, r) {
|
||||||
|
|
@ -171,6 +171,6 @@ exports = {
|
||||||
return drawMist;
|
return drawMist;
|
||||||
}
|
}
|
||||||
|
|
||||||
chooseIcon(cond)(x, y, r)
|
chooseIcon(cond)(x, y, r);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
(() => {
|
(() => {
|
||||||
function draw() {
|
function draw() {
|
||||||
const w = require('weather').load()
|
const w = require('weather').load();
|
||||||
if (!w) return;
|
if (!w) return;
|
||||||
g.reset();
|
g.reset();
|
||||||
g.setColor(0).fillRect(this.x, this.y, this.x+this.width-1, this.y+23)
|
g.setColor(0).fillRect(this.x, this.y, this.x+this.width-1, this.y+23);
|
||||||
if (w.txt) {
|
if (w.txt) {
|
||||||
require('weather').drawIcon(w.txt, this.x+10, this.y+8, 7.5);
|
require('weather').drawIcon(w.txt, this.x+10, this.y+8, 7.5);
|
||||||
}
|
}
|
||||||
if (w.temp) {
|
if (w.temp) {
|
||||||
let t = require('locale').temp(w.temp-273.15); // applies conversion
|
let t = require('locale').temp(w.temp-273.15); // applies conversion
|
||||||
t = t.substr(0, t.length-2); // but we have no room for units
|
t = t.match(/[\d\-]*/)[0]; // but we have no room for units
|
||||||
g.setFontAlign(0, 1); // center horizontally at bottom of widget
|
g.setFontAlign(0, 1); // center horizontally at bottom of widget
|
||||||
g.setFont('6x8', 1);
|
g.setFont('6x8', 1);
|
||||||
g.setColor(-1)
|
g.setColor(-1);
|
||||||
g.drawString(t, this.x+10, this.y+24)
|
g.drawString(t, this.x+10, this.y+24);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,10 +22,10 @@
|
||||||
function update(weather) {
|
function update(weather) {
|
||||||
require('weather').save(weather);
|
require('weather').save(weather);
|
||||||
if (!WIDGETS["weather"].width) {
|
if (!WIDGETS["weather"].width) {
|
||||||
WIDGETS["weather"].width = 20
|
WIDGETS["weather"].width = 20;
|
||||||
Bangle.drawWidgets()
|
Bangle.drawWidgets();
|
||||||
} else if (Bangle.isLCDOn()) {
|
} else if (Bangle.isLCDOn()) {
|
||||||
WIDGETS["weather"].draw()
|
WIDGETS["weather"].draw();
|
||||||
} else {
|
} else {
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
@ -46,6 +46,6 @@
|
||||||
|
|
||||||
WIDGETS["weather"] = {area: "tl", width: 20, draw: draw};
|
WIDGETS["weather"] = {area: "tl", width: 20, draw: draw};
|
||||||
if (!require('weather').load()) {
|
if (!require('weather').load()) {
|
||||||
WIDGETS["weather"].width = 0
|
WIDGETS["weather"].width = 0;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue