GPS Power Status widget

Posted on
  • I have developed a little widget that works like the bluetooth widget to show the power status of the GPS.

    This uses Bangle.isGPSOn() which is in the leading edge formware v2.08.167
    I wont check in until that firmware is generally available.

    One thing I have found is that when I switch to a multiclock face that switches the GPS On; the widget does not repond and display the status until the LCD has powered off, or I change to a different clock face. To get round this I am poking the widget using.

            // poke the gps widget indicator to change
            if (WIDGETS.gps !== undefined) {
              WIDGETS.gps.draw();
            }
    

    Code of widget below:

    (function(){
      var img = E.toArrayBuffer(atob("GBiBAAAAAAAAAAAAAA­//8B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+B//+B­gYGBgYGBgYGBgYGBgYGBgYGB//+A//8AAAAAAAAA­AAAA=="));
      
      function draw() {
        g.reset();
        if (Bangle.isGPSOn()) {
          g.setColor(1,0.8,0);     // on = amber
        } else {
          g.setColor(0.3,0.3,0.3); // off = grey
        }
        g.drawImage(img, 10+this.x, 2+this.y);
      }
    
      var timerInterval;
      Bangle.on('lcdPower', function(on) {
        if (on) {
          WIDGETS.gps.draw();
          if (!timerInterval) timerInterval = setInterval(()=>WIDGETS["gps"].draw(), 2000);
        } else {
          if (timerInterval) {
            clearInterval(timerInterval);
            timerInterval = undefined;
          }
        }
      });
    
      WIDGETS.gps={area:"tr",width:24,draw:dra­w};
    })();
    

    1 Attachment

    • thumbnail_IMG_20210206_182756 (1).jpg
  • Great! Yes, I'd say that looks good.

    I guess what might be happening is the widget gets Bangle.on('lcdPower' called before the multiclock face is called, so it's not turned on then. You could add a little delay to it?

    Bangle.on('lcdPower', function(on) {
        if (on) {
          setTimeout(function() { WIDGETS.gps.draw(); }, 100); // <-- here
          if (!timerInterval) timerInterval = setInterval(()=>WIDGETS["gps"].draw(), 2000);
        } else {
          if (timerInterval) {
            clearInterval(timerInterval);
            timerInterval = undefined;
          }
        }
      });
    

    or you could just overwrite the function when the widget is loaded so you respond immediately:

    Bangle._setGPSPower = Bangle.setGPSPower;
    Bangle.setGPSPower = function(on,appid) {
      Bangle._setGPSPower(op,appid);
      WIDGETS["gps"].draw();
    };
    
  • Now that I have checked the GPSsetup app in, I am wondering if I should check widgps in OR wait until 2.09 comes out that supports isGPSOn() ?

  • I'd check widgps in - maybe with a comment in the description and if (Bangle.isGPSOn) return check at the top just to ensure it doesn't crash on old firmwares. We can always add the Bangle.on('GPS',_=>setGPSisOn) code to make it work on older firmware

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

GPS Power Status widget

Posted by Avatar for HughB @HughB

Actions