feat: add support for weather module
parent
f7c1b1b3aa
commit
26b889e536
|
|
@ -39,7 +39,12 @@ class TimeCalClock{
|
|||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
|
||||
this.centerX = Bangle.appRect.w/2;
|
||||
// X coord to center date and time text at
|
||||
this.dtCenterX = Bangle.appRect.w/2;
|
||||
this.hasWeather = require('weather') && require('weather').get();
|
||||
if(this.hasWeather){
|
||||
this.dtCenterX =2*Bangle.appRect.w/3;
|
||||
}
|
||||
this.nrgb = [g.theme.fg, "#E00", "#0E0", "#00E"]; //fg, r ,g , b
|
||||
|
||||
this.ABR_DAY=[];
|
||||
|
|
@ -68,10 +73,45 @@ class TimeCalClock{
|
|||
* Run forest run
|
||||
**/
|
||||
draw(){
|
||||
// DEBUG
|
||||
// require("weather").get = () => ({
|
||||
// "temp": 298.15, // Temperature in Kelvin
|
||||
// "code": 800, // Weather condition code
|
||||
// "txt": "few clouds", // Weather condition text
|
||||
// });
|
||||
// require("weather").get = undefined;
|
||||
|
||||
this.hasWeather = require('weather') && require('weather').get();
|
||||
const prevCenterX = this.dtCenterX;
|
||||
if(this.hasWeather){
|
||||
this.dtCenterX = 2 * Bangle.appRect.w / 3;
|
||||
} else {
|
||||
this.dtCenterX = Bangle.appRect.w / 2;
|
||||
}
|
||||
this.drawTime();
|
||||
if(prevCenterX !== this.dtCenterX) {
|
||||
this.drawDateAndCal();
|
||||
}
|
||||
|
||||
if (this.TZOffset===undefined || this.TZOffset!==d.getTimezoneOffset())
|
||||
this.drawDateAndCal();
|
||||
|
||||
if(this.hasWeather){
|
||||
this.drawWeather();
|
||||
}
|
||||
}
|
||||
|
||||
drawWeather() {
|
||||
const weather = require('weather');
|
||||
const curr = weather.get();
|
||||
const temp = require("locale").temp(curr.temp-273.15).match(/^(\D*\d*)(.*)$/)[0];
|
||||
weather.drawIcon(curr, 24, 20, 20);
|
||||
|
||||
g
|
||||
.setFontAlign(0, -1)
|
||||
.setFont('6x8', 2)
|
||||
.setColor(g.theme.fg)
|
||||
.drawString(temp, Bangle.appRect.x2/6, 40);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,10 +125,13 @@ class TimeCalClock{
|
|||
|
||||
d=d?d :new Date();
|
||||
|
||||
g.setFontAlign(0, -1).setFont("Vector", this.TIME_FONT_SIZE()).setColor(g.theme.fg)
|
||||
.clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7)
|
||||
.drawString(("0" + require("locale").time(d, 1)).slice(-5), this.centerX, Y, true);
|
||||
//.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7); //DEV-Option
|
||||
g.setFontAlign(0, -1)
|
||||
.setFont("Vector", this.TIME_FONT_SIZE())
|
||||
.setColor(g.theme.fg)
|
||||
.clearRect(Bangle.appRect.x, Y - 13, Bangle.appRect.x2,Y+this.TIME_FONT_SIZE()-7)
|
||||
.drawString(("0" + require("locale").time(d, 1)).slice(-5), this.dtCenterX, Y, true)
|
||||
// .drawRect(Bangle.appRect.x, Y - 13, Bangle.appRect.x2,Y+this.TIME_FONT_SIZE()-7) //DEV-Option
|
||||
;
|
||||
|
||||
setTimeout(this.draw.bind(this), 60000-(d.getSeconds()*1000)-d.getMilliseconds());
|
||||
}
|
||||
|
|
@ -164,7 +207,12 @@ class TimeCalClock{
|
|||
}
|
||||
}
|
||||
if (render){
|
||||
g.setFont("Vector", FONT_SIZE).setColor(g.theme.fg).setFontAlign(0, -1).clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3).drawString(dateStr,this.centerX,Y);
|
||||
g
|
||||
.setFont("Vector", FONT_SIZE)
|
||||
.setColor(g.theme.fg)
|
||||
.setFontAlign(0, -1)
|
||||
.clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3)
|
||||
.drawString(dateStr, this.dtCenterX - 3, Y+1);
|
||||
}
|
||||
//g.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3); //DEV-Option
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue