diff --git a/ChangeLog b/ChangeLog index a100e704a..2234be0c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ Bangle.js2: Test screen now fails if no DCDC enabled Bangle.js: Ensure fake LED1/LED2 remember state Ensure E.setComparator is added to the build for nRF52 + Bangle.js2: Update test to use accelerometer to test vibration motor 2v25 : ESP32C3: Get analogRead working correctly Graphics: Adjust image alignment when rotating images to avoid cropping (fix #2535) diff --git a/libs/js/banglejs/Bangle_showTestScreen.js b/libs/js/banglejs/Bangle_showTestScreen.js index 651ce4736..2d9a4a9f4 100644 --- a/libs/js/banglejs/Bangle_showTestScreen.js +++ b/libs/js/banglejs/Bangle_showTestScreen.js @@ -9,25 +9,50 @@ Bangle.setLocked(0); Bangle.setLCDTimeout(0); var pass = []; + const TESTS = "TS,GPS,HRM,Baro,Mag,Acc,Btn,FW,Chg,Vibrate".split(","); const abs = Math.abs; - function draw(n,id,s,ok) { + var vibOn = false, vibCounter = 0, vibMotion; + function draw(id,s,ok) { + var n = TESTS.indexOf(id); pass[n]=ok; - var y = n*19; - g.reset().clearRect(48,y,175,y+19).setFont("6x8:1x2"); - g.setBgColor(ok ? "#0f0" : "#f00").clearRect(0,y,48,y+19); - g.setFontAlign(0,0).drawString(id, 24, y+10); - g.setFontAlign(-1,0).drawString(s, 52, y+10); + var y = n*17; + g.reset().clearRect(48,y,175,y+17).setFont("6x8:1x2"); + g.setBgColor(ok ? "#0f0" : "#f00").clearRect(0,y,48,y+17); + g.setFontAlign(0,0).drawString(id, 24, y+9); + g.setFontAlign(-1,0).drawString(s, 52, y+9); } - "TS,GPS,HRM,Baro,Mag,Acc,Btn,FW,Chg".split(",").forEach((e,i)=>draw(i,e,"",false)); - Bangle.on('touch',(n,e)=>draw(0,"TS",e.x+","+e.y, e.x>-25 && e.y>-25 && e.x<200 && e.y<200)); - Bangle.on('GPS',fix=>draw(1,"GPS",fix.time?require("locale").time(fix.time,1):"--",true)); - Bangle.on('HRM-raw',h=>draw(2,"HRM",h.vcPPG,h.vcPPG>=0 && h.vcPPG<=5000)); - Bangle.on('pressure',p=>draw(3,"Baro",Math.round(p.pressure), p.pressure>900 && p.pressure<1100)); - Bangle.on('mag',p=>draw(4,"Mag",p.x+","+p.y+","+p.z, abs(p.x)<5000 && Math.abs(p.y)<5000 && Math.abs(p.z)<5000)); - Bangle.on('accel',p=>draw(5,"Acc",p.x.toFixed(1)+","+p.y.toFixed(1)+","+p.z.toFixed(1), abs(p.x)<0.5 && abs(p.y)<0.5 && p.z<-0.8 )); - setWatch(e=>draw(6,'Btn',e.state?"Press":"Released",true),BTN,{edge:0,repeat:1}); + TESTS.forEach(id=>draw(id,"",false)); + Bangle.on('touch',(n,e)=>draw("TS",e.x+","+e.y, e.x>-25 && e.y>-25 && e.x<200 && e.y<200)); + Bangle.on('GPS',fix=>draw("GPS",fix.time?require("locale").time(fix.time,1):"--",true)); + Bangle.on('HRM-raw',h=>draw("HRM",h.vcPPG,h.vcPPG>=0 && h.vcPPG<=5000)); + Bangle.on('pressure',p=>draw("Baro",Math.round(p.pressure), p.pressure>900 && p.pressure<1100)); + Bangle.on('mag',p=>draw("Mag",p.x+","+p.y+","+p.z, abs(p.x)<5000 && Math.abs(p.y)<5000 && Math.abs(p.z)<5000)); + Bangle.on('accel',p=>{ + draw("Acc",p.x.toFixed(1)+","+p.y.toFixed(1)+","+p.z.toFixed(1), abs(p.x)<0.5 && abs(p.y)<0.5 && p.z<-0.8 ); + if (vibOn) { // if testing, wait for 10 readings and sum difference to see if it moved + vibCounter++; + vibMotion += p.diff; + if (vibCounter>10) { + vibOn = false; + D19.reset(); + var ok = vibMotion>3; + draw("Vibrate",ok?"ok":"fail",ok); + } + } else if ((vibMotion===undefined) && p.diff < 0.02){ + // wait until the Bangle has been still for a few seconds before turning vib on + vibCounter++; + if (vibCounter>15) { + vibCounter = 0; + vibOn = true; + vibMotion = 0; + D19.set(); + } + } else vibCounter = 0; + + }); + setWatch(e=>draw('Btn',e.state?"Press":"Released",true),BTN,{edge:0,repeat:1}); var bootcode=require("Storage").read(".bootcde"); - draw(7,'FW',"boot "+(require("Storage").readJSON("boot.info",1)||{}).version||"NONE", bootcode&&bootcode.includes("clockHasWidgets")); + draw('FW',"boot "+(require("Storage").readJSON("boot.info",1)||{}).version||"NONE", bootcode&&bootcode.includes("clockHasWidgets")); setTimeout(function() { var mv = (0.0001+analogRead(D3)+analogRead(D3)+analogRead(D3))/3, cup = 0, chg = 0; setInterval(function() { @@ -39,7 +64,7 @@ msg = "NO DCDC"; ok = false; } - draw(8,'Chg',msg,ok); + draw('Chg',msg,ok); },500); },1000); Bangle.on('swipe', e => { diff --git a/libs/js/banglejs/Bangle_showTestScreen.min.js b/libs/js/banglejs/Bangle_showTestScreen.min.js index 42e591d0e..78d68e735 100644 --- a/libs/js/banglejs/Bangle_showTestScreen.min.js +++ b/libs/js/banglejs/Bangle_showTestScreen.min.js @@ -1,2 +1,2 @@ -(ª(){ªc(a,b,f,d){k[a]=d;aš19;g.reset().clearRect(48,a,175,a+19).setFont(Ñ6x8:1x2);g.setBgColor(d?Ñ#0f0:Ñ#f00).clearRect(0,a,48,a+19);g.setFontAlign(0,0).drawString(b,24,a+10);g.setFontAlign(-1,0).drawString(f,52,a+10)}Bangle.setUI();clearInterval();clearWatch();g.clear(1);Bangle.removeAllListeners();E.removeAllListeners();Bangle.setBarometerPower(1,Ñapp);Bangle.setCompassPower(1,Ñapp);Bangle.setGPSPower(1,Ñapp);Bangle.setHRMPower(1,Ñapp);Bangle.setLCDPower(1);Bangle.setLocked(0);Bangle.setLCDTimeout(0);¬k=[];®h=Math.abs;Ñ"TS GPS HRM Baro Mag Acc Btn FW Chg.split(Ñ ).forEach((a,b)¢c(b,a,"",!1));Bangle.on(Ñtouch,(a,b)¢c(0,ÑTS,b.x+Ñ,+b.y,-25b.xž200>b.y));Bangle.on(ÑGPS,a¢c(1,ÑGPS,a.time?require(Ñlocale).time(a.time,1):Ñ--,!0));Bangle.on(ÑHRM-raw,a¢c(2,ÑHRM,a.vcPPG,0Ža.vcPPGž5E3‘a.vcPPG));Bangle.on(Ñpressure,a¢c(3,ÑBaro,Math.round(a.pressure),900a.pressure));Bangle.on(Ñmag,a¢c(4,ÑMag,a.x+Ñ,+a.y+Ñ,+a.z,5E3>h(a.x)ž5E3>Math.abs(a.y)ž5E3>Math.abs(a.z)));Bangle.on(Ñaccel,a¢c(5,ÑAcc,a.x.toFixed(1)+Ñ,+a.y.toFixed(1)+Ñ,+a.z.toFixed(1),.5>h(a.x)ž.5>h(a.y)ž-.8>a.z));setWatch(a¢c(6,ÑBtn,a.state?ÑPress:ÑReleased,!0),BTN,{edge:0,repeat:1});¬l=require(ÑStorage).read(Ñ.bootcde);c(7,ÑFW,Ñboot +(require(ÑStorage).readJSON(Ñ boot.info,1) {}).version ÑNONE,lžl.includes(ÑclockHasWidgets));setTimeout(ª(){¬a=(1E-4+analogRead(D3)+analogRead(D3)+analogRead(D3))/3,b=0,f=0;setInterval(ª(){¬d=analogRead(D3),e=13.359*d;fŸBangle.isCharging();d>až(b=1);d=fžbž2e;e=e.toFixed(2)+Ñv +(Bangle.isCharging()?Ñcharge:Ñ discharge);peek32(1073743224) (e=ÑNO DCDC,d=!1);c(8,ÑChg,e,d)},500)},1E3);Bangle.on(Ñswipe,a¢{k.every(b¢b)ž(Bangle.removeAllListeners(),clearInterval(),clearWatch(),NRF.sleep(),Bangle.setBarometerPower(0,Ñapp),Bangle.setCompassPower(0,Ñapp),Bangle.setGPSPower(0,Ñapp),Bangle.setHRMPower(0,Ñapp),Bangle.setBacklight(0),Bangle.setLocked(1),g.clear(1).setFont(Ñ12x20:2).setFontAlign(0,0).drawString(Ñ TEST +(ª(){ªd(a,c,h){¬b=n.indexOf(a);p[b]=h;bš17;g.reset().clearRect(48,b,175,b+17).setFont(Ñ6x8:1x2);g.setBgColor(h?Ñ#0f0:Ñ#f00).clearRect(0,b,48,b+17);g.setFontAlign(0,0).drawString(a,24,b+9);g.setFontAlign(-1,0).drawString(c,52,b+9)}Bangle.setUI();clearInterval();clearWatch();g.clear(1);Bangle.removeAllListeners();E.removeAllListeners();Bangle.setBarometerPower(1,Ñapp);Bangle.setCompassPower(1,Ñapp);Bangle.setGPSPower(1,Ñapp);Bangle.setHRMPower(1,Ñapp);Bangle.setLCDPower(1);Bangle.setLocked(0);Bangle.setLCDTimeout(0);¬p=[];®n=Ñ*TS GPS HRM Baro Mag Acc Btn FW Chg Vibrate.split(Ñ ),l=Math.abs;¬m=!1,e=0,k;n.forEach(a¢d(a,"",!1));Bangle.on(Ñtouch,(a,c)¢d(ÑTS,c.x+Ñ,+c.y,-25c.xž200>c.y));Bangle.on(ÑGPS,a¢d(ÑGPS,a.time?require(Ñlocale).time(a.time,1):Ñ--,!0));Bangle.on(ÑHRM-raw,a¢d(ÑHRM,a.vcPPG,0Ža.vcPPGž5E3‘a.vcPPG));Bangle.on(Ñpressure,a¢d(ÑBaro,Math.round(a.pressure),900a.pressure));Bangle.on(Ñmag,a¢d(ÑMag,a.x+Ñ,+a.y+Ñ,+a.z,5E3>l(a.x)ž5E3>Math.abs(a.y)ž5E3>Math.abs(a.z)));Bangle.on(Ñaccel,a¢{d(ÑAcc,a.x.toFixed(1)+Ñ,+a.y.toFixed(1)+Ñ,+a.z.toFixed(1),.5>l(a.x)ž.5>l(a.y)ž-.8>a.z);m?(e˜,k–a.diff,10a.diff?(e˜,15až(c=1);b=hžcž2f;f=f.toFixed(2)+Ñv +(Bangle.isCharging()?Ñcharge:Ñ discharge);peek32(1073743224) (f=ÑNO DCDC,b=!1);d(ÑChg,f,b)},500)},1E3);Bangle.on(Ñswipe,a¢{p.every(c¢c)ž(Bangle.removeAllListeners(),clearInterval(),clearWatch(),NRF.sleep(),Bangle.setBarometerPower(0,Ñapp),Bangle.setCompassPower(0,Ñapp),Bangle.setGPSPower(0,Ñapp),Bangle.setHRMPower(0,Ñapp),Bangle.setBacklight(0),Bangle.setLocked(1),g.clear(1).setFont(Ñ12x20:2).setFontAlign(0,0).drawString(Ñ TEST PASS,88,88),require(ÑStorage).writeJSON(Ñ welcome.json,{welcomed:!1}),Bangle.setPollInterval(800),setTimeout(ª(){Bangle.off()},36E5))})}) \ No newline at end of file