Skip to content

Commit

Permalink
Bangle.js2: Update test to use accelerometer to test vibration motor
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Jan 24, 2025
1 parent 2afd10e commit 672e959
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 41 additions & 16 deletions libs/js/banglejs/Bangle_showTestScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -39,7 +64,7 @@
msg = "NO DCDC";
ok = false;
}
draw(8,'Chg',msg,ok);
draw('Chg',msg,ok);
},500);
},1000);
Bangle.on('swipe', e => {
Expand Down
2 changes: 1 addition & 1 deletion libs/js/banglejs/Bangle_showTestScreen.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 672e959

Please sign in to comment.