var locale = require("locale"); var CHARW = 34; var CHARP = 2; var Y = 50; // Offscreen buffer var buf = Graphics.createArrayBuffer(CHARW+CHARP*2,CHARW*2 + CHARP*2,1,{msb:true}); var bufimg = {width:buf.getWidth(),height:buf.getHeight(),buffer:buf.buffer}; // The last time that we displayed var lastTime = " "; // If animating, this is the interval's id var animInterval; var timeInterval; /* Get array of lines from digit d to d+1. n is the amount (0..1) maxFive is true is this digit only counts 0..5 */ const DIGITS = { " ":(g,s,p,n)=>{}, "0":(g,s,p,n)=>{ g.fillRect(1+s*n,1-p, 1+s,1+p); g.fillRect(1+s-p,1, 1+s+p,1+s); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1+s*n,1+2*s-p, 1+s,1+2*s+p); g.fillRect(1+s*n,1+s-p, 1+s*n,1+2*s+p); g.fillRect(1+s*n-p,1, 1+s*n+p,1+s)}, "1":(g,s,p,n)=>{ g.fillRect(1+(1-n)*s,1-p, 1+s,1+p); g.fillRect(1+s-p,1, 1+s+p,1+s); g.fillRect(1+(1-n)*s,1+s-p, 1+s,1+s+p); g.fillRect(1-p+(1-n)*s,1+s, 1+p+(1-n)*s,1+2*s); g.fillRect(1+(1-n)*s,1-p+2*s, 1+s,1+p+2*s)}, "2":(g,s,p,n)=>{ g.fillRect(1,1-p, 1+s,1+p); g.fillRect(1+s-p,1, 1+s+p,1+s); g.fillRect(1,1+s-p, 1+s,1+s+p); g.fillRect(1-p,1+(1+n)*s, 1+p,1+2*s); g.fillRect(1+s-p,1+(2-n)*s, 1+s+p,1+2*s); g.fillRect(1,1+2*s-p, 1+s,1+2*s+p)}, "3":(g,s,p,n)=>{ g.fillRect(1,1-p, 1+(1-n)*s,1+p); g.fillRect(1-p,1, 1+p,n); g.fillRect(1+s-p,1, 1+s+p,1+s); g.fillRect(1,1+s-p, 1+s,1+s+p); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1+s*n,1+2*s-p, 1+s,1+2*s+p)}, "4":(g,s,p,n)=>{ g.fillRect(1-p,1, 1+p,1+s); g.fillRect(1+s,1-p, 1+(1-n)*s,1+p); g.fillRect(1+s-p,1, 1+s+p,1+(1-n)*s); g.fillRect(1,1+s-p, 1+s,1+s+p); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1+(1-n)*s,1+2*s-p, 1+s,1+2*s+p)}, "5to0": (g,s,p,n)=>{ // 5 -> 0 g.fillRect(1-p,1, 1+p,1+s); g.fillRect(1,1-p, 1+s,1+p); g.fillRect(1+s*n,1+s-p, 1+s,1+s+p); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1,1+2*s*p, 1+s,1+2*s+p); g.fillRect(1,1+2*s-p, 1,1+2*s+p); g.fillRect(1+s-p,1+(1-n)*s, 1+s+p,1+s); g.fillRect(1-p,1+s, 1+p,1+(1+n)*s)}, "5to6": (g,s,p,n)=>{ // 5 -> 6 g.fillRect(1-p,1, 1+p,1+s); g.fillRect(1,1-p, 1+s,1+p); g.fillRect(1,1+s-p, 1+s,1+s+p); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1,1+2*s-p, 1+s,1+2*s+p); g.fillRect(1-p,2-n, 1+p,1+2*s)}, "6":(g,s,p,n)=>{ g.fillRect(1-p,1, 1+p,1+(1-n)*s); g.fillRect(1,1-p, 1+s,1+p); g.fillRect(1+s*n,1+s-p, 1+s,1+s+p); g.fillRect(1+s-p,1+(1-n)*s, 1+s+p,1+s); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1+s*n,1+2*s-p, 1+s,1+2*s+p); g.fillRect(1-p,1+(1-n)*s, 1+p,1+s*(2-2*n))}, "7":(g,s,p,n)=>{ g.fillRect(1-p,1, 1+p,n); g.fillRect(1,1-p, 1+s,1+p); g.fillRect(1+s-p,1, 1+s+p,1+s); g.fillRect(1+(1-n)*s,1+s-p, 1+s,1+s+p); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1+(1-n)*s,1+2*s-p, 1+s,1+2*s+p); g.fillRect(1+(1-n)*s-p,1+s, 1+(1-n)*s+p,1+2*s)}, "8":(g,s,p,n)=>{ g.fillRect(1-p,1, 1+p,1+s); g.fillRect(1,1-p, 1+s,1+p); g.fillRect(1+s-p,1, 1+s+p,1+s); g.fillRect(1,1+s-p, 1+s,1+s+p); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1,1+2*s-p, 1+s,1+2*s+p); g.fillRect(1-p,1+s, 1+p,1+s*(2-n))}, "9":(g,s,p,n)=>{ g.fillRect(1-p,1, 1+p,1+s); g.fillRect(1,1-p, 1+s,1+p); g.fillRect(1+s-p,1, 1+s+p,1+s); g.fillRect(1,1+s-p, 1+(1-n)*s,1+s+p); g.fillRect(1-p,1+s, 1+p,1+(1+n)*s); g.fillRect(1+s-p,1+s, 1+s+p,1+2*s); g.fillRect(1,1+2*s-p, 1+s,1+2*s+p)}, ":":(g,s,p,n)=>{ g.fillRect(1+s*0.4,1+s*0.4-p, 1+s*0.6,1+s*0.4+p); g.fillRect(1+s*0.6-p,1+s*0.4, 1+s*0.6+p,1+s*0.6); g.fillRect(1+s*0.6,1+s*0.6-p, 1+s*0.4,1+s*0.6+p); g.fillRect(1+s*0.4-p,1+s*0.4, 1+s*0.4+p,1+s*0.6); g.fillRect(1+s*0.4,1+s*1.4-p, 1+s*0.6,1+s*1.4+p); g.fillRect(1+s*0.6-p,1+s*1.4, 1+s*0.6+p,1+s*1.6); g.fillRect(1+s*0.6,1+s*1.6-p, 1+s*0.4,1+s*1.6+p); g.fillRect(1+s*0.4-p,1+s*1.4, 1+s*0.4+p,1+s*1.6) }}; /* Draw a transition between lastText and thisText. 'n' is the amount - 0..1 */ function drawDigits(lastText,thisText,n) { const p = CHARP; // padding around digits const s = CHARW; // character size var x = p; // x offset var y = Y+p; // y offset g.reset(); for (var i=0;i=1) { n=1; clearInterval(animInterval); animInterval = undefined; } drawDigits(l,t,n); }, 20); lastTime = t; } Bangle.on('lcdPower',function(on) { if (animInterval) { clearInterval(animInterval); animInterval = undefined; } if (timeInterval) { clearInterval(timeInterval); timeInterval = undefined; } if (on) { showTime(); timeInterval = setInterval(showTime, 1000); } }); g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); // Update time once a second timeInterval = setInterval(showTime, 1000); showTime(); // Show launcher when middle button pressed setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});