• Hi - is it the full reboot you're worried about? Rather than just the change in apps?

    The full reboot is actually handled by the watchdog timer, which I believe is set up in https://github.com/espruino/Espruino/blo­b/912aecb676c78e8fc0282775b46c7ad48c428a­30/targets/nrf5x_dfu/main.c#L207

    When you hold the button, it stops kicking the watchdog and then eventually the watchdog times out and reboots the device.

    As far as I know once it's set you're stuck with it until the next reboot, so you would have to update the bootloader to fix it.

    ... or you could modify the Bangle.js code to just kick the watchdog for longer after the button is pressed (but you run the risk that if that code were to break, you would be unable to hard-reboot the bangle)

  • or you could modify the Bangle.js code to just kick the watchdog for longer after the button is pressed (but you run the risk that if that code were to break, you would be unable to hard-reboot the bangle)

    if you would schedule one timeout at button press to kick once after e.g. 4 seconds it could work to increase to 5+4 seconds and could be safer than setInterval or some random kicking, something like this (just remove print parts)

    var wdTm;
    setWatch(function(e) {
      if (wdTm) {clearTimeout(wdTm);wdTm=0;print("WD kick cleared");}
      if (e.state){
      wdTm = setTimeout(()=>{E.kickWatchdog();wdTm=0;­print("WD kicked");},4000);
      print("BTN Pressed");
      }
    }, BTN, {edge:"both", debounce:50, repeat:true});
    

    however I am not sure how this works when apps are started/killed and where this piece of code should be to work all the time

  • Hi

    So i tried this as i after thinking found it quite neat.

    As i wanted to kick the watchdog several times i tried something a little more elaborate - as you can see below.

    Key problem is that it does not work. Initially i set the interval to 3000 miliseconds and it would never get called. Now it is at 500 and it get's called and kicks the watchdog twice.
    After that none of the debug lines is printing more.
    So it seems to me that there is some code which after the button has been pressed between 1 and 1,5 seconds will effectively clear all intervals and times.

    I also tested directly with your code example and it has the same problem. The function set in setTimeout never gets called.

    I have nothing but a blank v15 firmware running on the watch (i have uploaded an additional app, but this happens on the standard clock without my app have ever been opened)

    let wdTm;
    let wdKc;
    let wdBw;
    if (wdBw) {
      clearWatch(wdBw);
      wdBw=0;
    }
    wdBw = setWatch(function(e) {
        if (wdTm) {
          clearInterval(wdTm);
          wdTm=0;
          console.log("WD clear");
          //print("WD kick cleared");
        }
      wdKc=0;
      console.log("button touched");
      if (e.state){
          console.log("setting interval");
        wdTm = setInterval(function () {
            console.log("in interval");
            if (BTN.read() && wdKc < 7) {
              E.kickWatchdog();
              console.log("watchdog kicked");
              wdKc++;
            } else {
              clearInterval(wdTm);
              console.log("WD clear by interval");
            }
        },500);
        console.log("interval set");
        }
    }, BTN, {edge:"both", debounce:50, repeat:true});
    
About

Avatar for fanoush @fanoush started