Avatar for HughB


Member since Dec 2020 • Last active Apr 2021
  • 28 conversations

Been in IT for 40 years. Love interprative programming languages. Wrote my own small Emacs in 2000 lines of C (see Atto on Github).

Most recent activity

  • in Bangle.js
    Avatar for HughB

    Apps have some dependencies but it is not very obvious (ex: stepometer clock)

    Hi. I wrote the Stepometer clock. I have other Apps with dependancies on a later version of the firmware and I usually state this upfront in the one line description in the App loader and also in the README file. Stepometer has no dependancies to my knowledge, what did you observe ?

    Ah - I think you mean you have to install one of the pedominter widgets. It will work with either. I will update the README when I get a chance.

    Remember we are all hobbyists with day jobs burning the midnight oil to write these apps :)

  • in Bangle.js
    Avatar for HughB

    thanks both.

  • in Bangle.js
    Avatar for HughB

    here's how the file looked after I uploaded it.

  • in Bangle.js
    Avatar for HughB

    I mistakenly logged 2 walks in the same GPS log file. So I downloaded the file and split them. However when I upload the file I end up with quotes round the filename. How could I upload these files ? Also I am wondering what is the purpose / benefit of having these files have (Storage File) appended on the end of the filename ?

  • in Bangle.js
    Avatar for HughB

    During development I tend to repeatedly upload the same file again and again. So in the IDE I click on the disk icon, select upload file, browse to the source directory and select the file. I also found it saves time if you just call the source file the same as it will be when it is deployed through the App Loader. So instead of something generic like app.js, which will have to be renamed before upload, use myappid.app.js. Its is useful not to have the code mimified during development as you can recover a file you accidently delete in your sourec tree by downloading it from the bangle.

  • in Bangle.js
    Avatar for HughB

    Right on the money. Took that line out and the LCD goes off as expected.
    Is that a defect with LCD1.write() ?

  • in Bangle.js
    Avatar for HughB

    Could be. Its the only thing that would make sense. Will test tomorrow.

  • in Bangle.js
    Avatar for HughB

    Here's the latest code for arrow. I can reproduce the problem with this code. There is no use of g.flip(). flip1() and flip2() just draw buf1 and buf2 which are different sizes. I have also taken out the setLCDTimeout(30);

    The LCD will only go of if the watch is totally still. I have disabled switch on on twist in the settings.

    For simplicity I have taken out the calibrate functions in the code below.

    var pal1color = new Uint16Array([0x0000,0xFFC0],0,1);
    var pal2color = new Uint16Array([0x0000,0xffff],0,1);
    var buf1 = Graphics.createArrayBuffer(128,128,1,{ms­b:true});
    var buf2 = Graphics.createArrayBuffer(80,40,1,{msb:­true});
    var intervalRef;
    var bearing=0; // always point north
    var heading = 0;
    var oldHeading = 0;
    var candraw = false;
    var CALIBDATA = require("Storage").readJSON("magnav.json­",1)||null;
    function flip1(x,y) {
      g.drawImage({width:128,height:128,bpp:1,­buffer:buf1.buffer, palette:pal1color},x,y);
    function flip2(x,y) {
     g.drawImage({width:80,height:40,bpp:1,bu­ffer:buf2.buffer, palette:pal2color},x,y);
    function radians(d) {
      return (d*Math.PI) / 180;
    // takes 32ms
    function drawCompass(hd) {
      if(!candraw) return;
      if (Math.abs(hd - oldHeading) < 2) return 0;
      var t1 = getTime();
      var p = [0, 1.1071, Math.PI/4, 2.8198, 3.4633, 7*Math.PI/4 , 5.1760];
      // using polar cordinates, 64,64 is the offset from the 0,0 origin
      var poly = [
        64+60*Math.sin(hd+p[0]),       64-60*Math.cos(hd+p[0]),
        64+44.7214*Math.sin(hd+p[1]),  64-44.7214*Math.cos(hd+p[1]),
        64+28.2843*Math.sin(hd+p[2]),  64-28.2843*Math.cos(hd+p[2]),
        64+63.2455*Math.sin(hd+p[3]),  64-63.2455*Math.cos(hd+p[3]),
        64+63.2455*Math.sin(hd+p[4]),  64-63.2455*Math.cos(hd+p[4]),
        64+28.2843*Math.sin(hd+p[5]),  64-28.2843*Math.cos(hd+p[5]),
        64+44.7214*Math.sin(hd+p[6]),  64-44.7214*Math.cos(hd+p[6])
      flip1(56, 56);
      var t = Math.round((getTime() - t1)*1000);
      LED1.write((t > 100));
    // stops violent compass swings and wobbles, takes 3ms
    function newHeading(m,h){ 
        var s = Math.abs(m - h);
        var delta = (m>h)?1:-1;
        if (s>=180){s=360-s; delta = -delta;} 
        if (s<2) return h;
        var hd = h + delta*(1 + Math.round(s/5));
        if (hd<0) hd+=360;
        if (hd>360)hd-= 360;
        return hd;
    // takes approx 7ms
    function tiltfixread(O,S){
      var start = Date.now();
      var m = Bangle.getCompass();
      var g = Bangle.getAccel();
      m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z;
      var d = Math.atan2(-m.dx,m.dy)*180/Math.PI;
      if (d<0) d+=360;
      var phi = Math.atan(-g.x/-g.z);
      var cosphi = Math.cos(phi), sinphi = Math.sin(phi);
      var theta = Math.atan(-g.y/(-g.x*sinphi-g.z*cosphi))­;
      var costheta = Math.cos(theta), sintheta = Math.sin(theta);
      var xh = m.dy*costheta + m.dx*sinphi*sintheta + m.dz*cosphi*sintheta;
      var yh = m.dz*sinphi - m.dx*cosphi;
      var psi = Math.atan2(yh,xh)*180/Math.PI;
      if (psi<0) psi+=360;
      return psi;
    function reading() {
      var d = tiltfixread(CALIBDATA.offset,CALIBDATA.s­cale);
      heading = newHeading(d,heading);
      var dir = bearing - heading;
      if (dir < 0) dir += 360;
      if (dir > 360) dir -= 360;
      drawCompass(dir);  // we want compass to show us where to go
      oldHeading = dir;
      var course = Math.round(heading);
      var cs = course.toString();
      cs = course<10?"00"+cs : course<100 ?"0"+cs : cs;
      flip2(90, 200);
    function startdraw(){
      candraw = true;
      intervalRef = setInterval(reading,500);
    function stopdraw() {
      if(intervalRef) {clearInterval(intervalRef);}
    function setButtons(){
      setWatch(()=>{load();}, BTN1, {repeat:false,edge:"falling"});
      setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
    Bangle.on('lcdPower',function(on) {
      if (on) {
      } else {