Disabling Hard Reset Puck.js

Posted on
  • I'm looking for a way to disable the hard-reset that is initiated by holding down the button on power up to clear out any previously saved code and bonding data. Is there a command I can add into my code that will prevent this function?

    I understand there are certain risks with doing this but I want to prevent the chance of erasing the code accidentally.

    I would like to still have the self-test function intact where you can power up the puck without loading the saved code and without deleting the saved code.

    many thanks

  • Sun 2020.02.09

    'power up the puck without loading the saved code and without deleting the saved code'

    Has an attempt been made to extend the startup call to onInit() been extended, such that a conditional step would then allow the saved code to then execute?

    Should additional assistance be required, please post your startup call to the onInit() function.

  • I'm afraid there isn't a way of disabling the removal of 'boot code' in Espruino at the moment, it's built into the firmware.

    However on a long-press, the only files that get removed are the ones created by E.setBootCode and save(). On http://www.espruino.com/Saving#combining­-options you'll see there are a few other files that get executed - .boot0/etc.

    If you write your code to .boot0 using require("Storage").write then it won't get erased by the long-press at boot, which should be what you want.

    I'm afraid bonding data will still be cleared though.

  • Thank you Gordon. That should be perfect. I'll give it a try.

  • I'm having trouble getting this to work. For eaxample here is what I'm trying to write to .boot0 and have it execute on device start-up, but it's not working for me:

    require("Storage").write(".boot0", `
    //function onInit() {
    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    function btnPressed() {
      // Send 'm'
      kb.tap(kb.KEY.M, 0);
      digitalWrite(LED3, true);
      setTimeout("digitalWrite(LED3, 0);", 100);
    // trigger btnPressed whenever the button is pressed
    setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50})­;

    So i have nothing in save(), so do not enter the save() command into the terminal, I just send the above code onto the puck via the IDE, then disconnect from the IDE and restart the puck by cycling the power.

    I have tried both including the onInit and leaving it commented out as above.

    Do I have something wrong, or is it something to do with the ble_hid_keyboard service not working from boot0?

  • Ahh - yes, it's because ble_hid_keyboard is a module, and you're not including that module.

    Maybe try using https://www.espruino.com/ide/ to write the code - I just pushed some changes I'd had locally that make this much easer.

    • Remove the require("Storage").write(".boot0", around your code
    • Click the down-arrow under the upload button
    • Choose the Storage option (if you don't see it, make sure to reload the page as you may still have the old IDE version)
    • Choose .boot0 under that menu (you'll only see it on your device because you already created it - otherwise you'll have to click the button to choose your own filename and type it in)
    • Click the upload button as normal.
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Disabling Hard Reset Puck.js

Posted by Avatar for tronic98776 @tronic98776