• Ah, ok I see now where I went wrong. I misunderstood that Gordon's code was meant to be placed in the main draw function, I was confused whether it was meant to replace of part of yours, malaire. One thing I don't fully understand is why we need Bangle.on('lock', on => { draw(); }); if we're going to call the draw function right afterward anyway.
    I tried removing the former, and it seems to work just the same.

    Anyway, here's what I have now:

    function draw(){
      if(Bangle.isLocked()){
        daylight();
        } else {
        nightglow();
        }
    }
    
    var drawTimeout;
    function queueDraw() {
      if (drawTimeout) clearTimeout(drawTimeout);
      drawTimeout = setTimeout(() => {
        drawTimeout = undefined;
        draw();
      }, 250 - (Date.now() % 250));
    }
    
    Bangle.on('lock', on => {
      draw();
    });
    
    draw();
    

    Calling queuedraw() at the end of the draw() function resulted in a frozen clock face, so I moved it to the end of my dalight() and nightglow() functions and that got it ticking again. Hopefully I didn't miss anything else and have implemented everything correctly. I'm still seeing the lag when changing images, so perhaps I'll rethink using the lock as the method of changing modes. Either way, I'm learning a lot.

  • One thing I don't fully understand is why we need Bangle.on('lock', on => { draw(); });

    That creates an event which calls draw every time lock state changes, i.e. when watch is locked or unlocked. This is used so that draw is done immediately after state change. Without this draw would happen at next queued draw, i.e. with up to 250 ms delay with your current 250ms interval.

    ... if we're going to call the draw function right afterward anyway.

    That draw(); at end is so that first draw when app starts is immediate. This also starts queued draws when queueDraw is called during that draw.

    I'm still seeing the lag when changing images

    I don't understand why that would happen. Can you show your daylight() and nightglow() functions?

About

Avatar for malaire @malaire started