Fix occasional NaN values!

master
Gordon Williams 2019-11-13 17:03:41 +00:00
parent c4daf19ab8
commit 9f1827200d
2 changed files with 11 additions and 6 deletions

View File

@ -23,7 +23,7 @@ Bangle.on('mag', function(m) {
g.fillRect(70,0,170,24);
g.setColor(0xffff);
g.setFontAlign(0,0);
g.drawString((m.heading===undefined)?"---":Math.round(m.heading),120,12);
g.drawString(isNaN(m.heading)?"---":Math.round(m.heading),120,12);
g.setColor(0,0,0);
arrow(oldHeading,0);
arrow(oldHeading+180,0);

View File

@ -14,9 +14,9 @@ function readHRM() {
min=Math.min(min*0.97+a*0.03,a);
max=Math.max(max*0.97+a*0.03,a);
y = E.clip(170 - (a*960*4),100,230);
if (x==0) {
g.clearRect(0,100,239,239);
g.moveTo(-100,0);
if (x==0) {
g.clearRect(0,100,239,239);
g.moveTo(-100,0);
}
/*g.setColor(0,1,0);
var z = 170 - (min*960*4); g.fillRect(x,z,x,z);
@ -39,11 +39,16 @@ function readHRM() {
t.sort();
// average the middle 3
var mid = t.length>>1;
hrm = (t[mid]+t[mid+1]+t[mid+2])/3;
if (mid+2<t.length)
hrm = (t[mid]+t[mid+1]+t[mid+2])/3;
else if (mid<t.length)
hrm = t[mid];
else
hrm = 0;
g.setFontVector(40);
g.setFontAlign(0,0);
g.clearRect(0,0,239,100);
var str = Math.round(hrm);
var str = hrm ? Math.round(hrm) : "?";
var px = 120;
g.drawString(str,px,40);
px += g.stringWidth(str)/2;