backlightTimeout and button behaviour

Posted on
  • Hi,

    Just a quick question about backlightTimeout...

    Bangle.setOptions({
      lockTimeout: 99999999999, //1157 days
      backlightTimeout: 10000 }); //10 seconds
    
    function buttonPressed() { 
     //   console.log("trigger");  
    }
    

    The behaviour isn't quite what I expected because when the backlight turns off it takes two button presses to get buttonPressed() to trigger. I'm assuming the Bangle is listening for a button press to turn the screen back on then and then normal behaviour resumes.

    This is how I'm handling the button press:
    setWatch(buttonPressed, (process.env.HWVERSION==2) ? BTN1 : BTN2, { repeat: true, edge: 'rising', debounce: 50 });

    I really need it to trigger buttonPressed on the first button press... is there an option that I'm missing, or perhaps an alternative way to handle the button press?

    Thanks.

  • Not saying it's ideal, but what happens if you use 'both' instead of 'rising'?

  • One thing you might be hitting is the timeout is a 32 bit integer, and 99999999999 is greater than can be stored in an int. If you want to disable the lock timeout, just use 0

    However if you leave the watch unlocked the touchscreen stays on which draws a lot of power - it'll run the Bangle's battery down in about a week.

    If the device is locked or the screen is off, the button event that unlocks the screen gets 'eaten', because in most cases you don't want a button press to (for instance) immediately start the launcher.

    What I'd suggest is you just respond to the watch being unlocked as well as handling the button press:

    function buttonPressed() { 
     //   console.log("trigger");  
    }
    
    Bangle.on("lock", locked => {
      if (!locked) buttonPressed();
    });
    setWatch(buttonPressed, (process.env.HWVERSION==2) ? BTN1 : BTN2, { repeat: true, edge: 'rising' });
    

    On 2v20 (when released) or cutting edge firmwares you can even go one further and ensure that the watch can be woken up by other things (like twisting) but only a button press fires your function:

    Bangle.on("lock", (locked,reason) => {
      if (!locked && reason=="button") buttonPressed();
    });
    
  • Yeh unfortunately changing the lock timeout to 0 didn't resolve the issue... I can't imagine what else it could be (firmware is 2v19 and I'm just using the WebIDE to write to RAM, I also did write to storage). My code is just what I posted. Same issue with what Ganblejs suggested; it does trigger double button presses but only once I've pressed to turn the backlight back on - it really does seem to be behaving like it's locked but it shouldn't be.

    In terms of Battery life, my target is to get 2+ days of battery. So something like turning off touch might not be necessary (but if nothing else works it might be a good second option).

    I can't help but feel there's something super obvious I'm missing.

  • I can't help but feel there's something super obvious I'm missing.

    What about the code example I posted? Surely that will work fine, without messing with the lock timeout?

    it really does seem to be behaving like it's locked but it shouldn't be.

    It eats the first press if it was locked or the backlight was off. Your backlight timeout is 10s so it could have been off.

  • "It eats the first press if it was locked or the backlight was off"

    Ah, that was my oversight.

    This seems to have fixed things:

    Bangle.setOptions({
      lockTimeout: 0, 
      backlightTimeout: 5000,
        wakeOnBTN1: false});
    
    function buttonPressed() { 
      
       console.log("trigger");
       Bangle.setLCDPower(1);
      
    }
    

    Thanks for your quick replies.

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

backlightTimeout and button behaviour

Posted by Avatar for user156427 @user156427

Actions