Bangle.js 2: Event handler not reset

Posted on
  • Hi,

    I'm using espruino -d Bangle.js -w index.js to connect to my Bangle.js in watch mode. Everytime I change the file in my local IDE, it is re-uploaded and re-executed like expected.

    I've noticed that sometimes after I changed the file and it gets uploaded, the console shows

     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v17 (c) 2021 G.Williams
    
    >
    >Upload Complete
    

    while sometimes only

    >Upload Complete
    

    is shown, especially when I'm working on a larger file.

    In the latter case, however, the state on the watch is not reset correctly and event handlers are added up. For example, this code

    Bangle.on('touch', function (zone, e) {
      console.log(e);
    });
    console.log("Ready");
    

    makes the log message appear multiple times after multiple file uploads.

    When I long-press the button and then trigger a re-upload, the state is reset correctly.

    Is there anything I can do to re-initialize the event handlers before each re-upload in watch mode?

    Unfortunately, the small code example above does not reproduce the problem. It only happens with some larger code file.

    Kind regards,
    Johannes

  • Just realized that I can recreate the issue in the web IDE with the same code, see attachment.
    After uploading the code multiple times, the event is logged multiple time on the console.

  • The issue is you've defined a function called reset which overwrites the Bangle's built-in reset function (which is used to reset the device and is called at upload time before the upload).

    So when it goes to reset the watch, that gets called and it doesn't actually get reset!

    If you just rename the reset function it should all work great :)

  • Aaargh! 🤦 Thanks!

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

Bangle.js 2: Event handler not reset

Posted by Avatar for neshanjo @neshanjo

Actions