• Hmm. Something's getting stuck, I think.

    With this stripped-down code on 1v92.91; after a power cycle and an E.setBootCode("");, an upload and a refresh, I get Error 13313 when clicking. However, if I Remove (ie. unpair and forget) the Puck with Opt-click on the menu bar, it works okay.

    var hid = require("ble_hid_keyboard");
    
    var is_connected = false;
    
    var ad_values = {};
    var ad_options = { name: "Page-Turn-o-Matic 4000" };
    
    function on_connect () {
      digitalPulse(LED3, true, 100);
      is_connected = true;
    }
    
    function on_disconnect() {
      digitalPulse(LED1, true, 100);
      is_connected = false;
    }
    
    function btn_released() {
      if (is_connected) {
        digitalPulse(LED2, true, 100);
        hid.tap(hid.KEY.RIGHT, 0);
      }
      else
        digitalPulse(LED1, true, 500);
    }
    
    
    
    function init () {
      NRF.on('connect', on_connect);
      NRF.on('disconnect', on_disconnect);
    
      clearWatch();
    
      setTimeout(function () {
        setWatch(btn_released, BTN, { repeat:true, edge:'falling', debounce : 50 });
    
        NRF.disconnect();
    
     //   ad_values[0x180F] = Math.round(Puck.getBatteryPercentage());­
        NRF.setAdvertising(ad_values, ad_options);
        NRF.setServices(undefined, { hid : hid.report });
      }, 3000);
    }
    
    E.on('init', init);
    

    I'll start putting stuff back in, bit-by-bit, and unpair if/when it goes bad. It's times like these I really wish Puck had a USB port.

About

Avatar for tom.gidden @tom.gidden started