Quick fixes and performance improvement (#3)

* Some performance improvement updates. Suspends timer when LCD is off, and resume when it comes back.
master
Akinboyewa Akindolani 2019-11-12 14:32:07 +00:00 committed by GitHub
parent d6179b955f
commit b384eeb084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 100 additions and 65 deletions

View File

@ -1,18 +1,23 @@
(function(){
g.clear();
const p = Math.PI/2;
const PRad = Math.PI/180;
var minuteDate = new Date();
var secondDate = new Date();
let intervalRefMin = null;
let intervalRefSec = null;
let minuteDate = new Date();
let secondDate = new Date();
function seconds(angle, r) {
var a = angle*Math.PI/180;
var x = 120+Math.sin(a)*r;
var y = 120-Math.cos(a)*r;
const a = angle*PRad;
const x = 120+Math.sin(a)*r;
const y = 120-Math.cos(a)*r;
g.fillRect(x-1,y-1,x+1,y+1);
}
function hand(angle, r1,r2) {
var a = angle*Math.PI/180;
var r3 = 3;
var p = Math.PI/2;
const a = angle*PRad;
const r3 = 3;
g.fillPoly([
120+Math.sin(a)*r1,
120-Math.cos(a)*r1,
@ -27,7 +32,7 @@ function hand(angle, r1,r2) {
function drawAll() {
g.clear();
g.setColor(0,0,0.6);
for (var i=0;i<60;i++)
for (let i=0;i<60;i++)
seconds(360*i/60, 90);
secondDate = minuteDate = new Date();
onSecond();
@ -48,20 +53,50 @@ function onMinute() {
g.setColor(0,0,0);
hand(360*minuteDate.getHours()/12, -10, 50);
hand(360*minuteDate.getMinutes()/60, -10, 82);
oldMinute = new Date();
minuteDate = new Date();
g.setColor(1,1,1);
hand(360*minuteDate.getHours()/12, -10, 50);
hand(360*minuteDate.getMinutes()/60, -10, 82);
if(minuteDate.getHours() >= 0 && minuteDate.getMinutes() === 0) {
Bangle.buzz();
}
}
setInterval(onSecond,1000);
setInterval(onMinute,60*1000);
function clearTimers() {
if(intervalRefMin) {clearInterval(intervalRefMin);}
if(intervalRefSec) {clearInterval(intervalRefSec);}
}
function startTimers() {
minuteDate = new Date();
secondDate = new Date();
intervalRefSec = setInterval(onSecond,1000);
intervalRefMin = setInterval(onMinute,60*1000);
drawAll();
}
startTimers();
Bangle.on('lcdPower',function(on) {
if (on) {
g.clear();
drawAll();
startTimers();
drawWidgets();
}else {
clearTimers();
}
});
Bangle.on('gesture',function(gesture){
if (gesture && !Bangle.isLCDOn()) {
clearTimers();
g.clear();
startTimers();
drawWidgets();
Bangle.setLCDTimeout(30);
Bangle.setLCDPower(true);
}
});
})();