improved speed of stepo draw and started and stopped timer on screen on / off

master
hughbarney 2021-03-09 21:09:43 +00:00
parent a55ec3f1af
commit 72c60dbfa7
3 changed files with 20 additions and 6 deletions

View File

@ -2962,7 +2962,7 @@
{ "id": "stepo",
"name": "Stepometer Clock",
"icon": "stepo.png",
"version":"0.01",
"version":"0.02",
"description": "A large font watch, displays step count in a doughnut guage and warns of low battery",
"tags": "clock",
"type":"clock",

2
apps/stepo/ChangeLog Normal file
View File

@ -0,0 +1,2 @@
0.01: First version
0.02: Speeded up first draw, ensure timer is stopped and started depending on screen event

View File

@ -1,6 +1,7 @@
var pal4color = new Uint16Array([0x0000,0xFFFF,0x7BEF,0xAFE5],0,2); // b,w,grey,greenyellow
var pal4red = new Uint16Array([0x0000,0xFFFF,0xF800,0xAFE5],0,2); // b,w,red,greenyellow
var buf = Graphics.createArrayBuffer(160,160,2,{msb:true});
var intervalRefSec;
function flip(x,y) {
g.drawImage({width:160,height:160,bpp:2,buffer:buf.buffer, palette:pal4color}, x, y);
@ -33,7 +34,7 @@ function drawSteps() {
buf.setColor(3); // green-yellow
// draw guauge
for (i = startrot; i > midrot; i--) {
for (i = startrot; i > midrot; i -= 4) {
x = cx + r * Math.sin(radians(i));
y = cy + r * Math.cos(radians(i));
buf.fillCircle(x,y,4);
@ -42,7 +43,7 @@ function drawSteps() {
buf.setColor(2); // grey
// draw remainder of guage in grey
for (i = midrot; i > endrot; i--) {
for (i = midrot; i > endrot; i -= 4) {
x = cx + r * Math.sin(radians(i));
y = cy + r * Math.cos(radians(i));
buf.fillCircle(x,y,4);
@ -80,6 +81,15 @@ function getSteps() {
return stepsWidget().getSteps();
return "-";
}
function startTimer() {
draw();
intervalRefSec = setInterval(draw, 15000);
}
function stopTimer() {
if(intervalRefSec) { intervalRefSec = clearInterval(intervalRefSec); }
}
function stepsWidget() {
if (WIDGETS.activepedom !== undefined) {
@ -92,13 +102,15 @@ function stepsWidget() {
// handle switch display on by pressing BTN1
Bangle.on('lcdPower', function(on) {
if (on) draw();
if (on)
startTimer();
else
stopTimer();
});
g.reset();
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
setInterval(draw, 15000); // refresh every 15s
draw();
startTimer();
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});