• Hi Gordon,

    Here's the problem I found with 1v99 cutting edge that I mentioned in my previous post.
    It only happens in 1v99 cutting edge and the exact same code works perfectly fine in 1v99 release.

    Basically, I run the code below on my puck to make it act as HID keyboard and type some string on a long press and [Enter] on a short press.

    var kb = require("ble_hid_keyboard");
    
    var kbTimer = null;
    var keys2type = [];
    
    function kbTyper() {
      if (kbTimer) {
        console.log("Clearing kbTimer until finished typing");
        clearInterval(kbTimer);
        kbTimer = null;
      }
    
      if (keys2type.length) {
        let keys = keys2type.pop();
    
        // Type with NRF.sendHIDReport()
        //NRF.sendHIDReport(keys, function() {
        //  NRF.sendHIDReport([0,0,0,0,0,0,0,0], function() {
        //    startKbTimer();
        //  });
        //});
        
        // Type with kb.tap()
        kb.tap(keys[0], keys[1], function() {
          startKbTimer();
        });
      }
    }
    
    function startKbTimer() {
      if (!kbTimer && keys2type.length) {
        console.log("Starting kbTimer");
        kbTimer = setInterval(kbTyper, 5);
      }
    }
    
    function btnPressed(e) {
      var duration = e.time - e.lastTime;
      console.log("e.state: " + e.state);
      console.log("e.time: " + e.time);
      console.log("e.lastTime: " + e.lastTime);
      console.log("duration: " + duration);
      
      // If button is depressed
      if (e.state){
      }
      // If button is released
      else {
        if (duration < 0.30) {
          digitalPulse(LED1,1,50);
          // Send 'ENTER'
          kb.tap(kb.KEY.ENTER, 0, function() {});
          console.log("[Short press]");
        } else {
          digitalPulse(LED2,1,50);
          // Schedule keys for typing with NRF.sendHIDReport()
          //keys2type = [];
          //keys2type.push([0,0,4,0,0,0,0,0]);
          //keys2type.push([0,0,5,0,0,0,0,0]);
          //keys2type.push([0,0,6,0,0,0,0,0]);
          //keys2type.push([0,0,6,0,0,0,0,0]);
          //keys2type.push([0,0,7,0,0,0,0,0]);
          //keys2type.push([0,0,8,0,0,0,0,0]);
          //keys2type.push([0,0,9,0,0,0,0,0]);
          //keys2type.push([0,0,10,0,0,0,0,0]);
          //keys2type.push([0,0,11,0,0,0,0,0]);
          //keys2type.push([0,0,12,0,0,0,0,0]);
          //keys2type = keys2type.reverse();
          
          // Schedule keys for typing with kb.tap()
          keys2type = [];
          keys2type.push([kb.KEY.A,0]);
          keys2type.push([kb.KEY.B,0]);
          keys2type.push([kb.KEY.C,0]);
          keys2type.push([kb.KEY.D,0]);
          keys2type.push([kb.KEY.E,0]);
          keys2type.push([kb.KEY.F,0]);
          keys2type.push([kb.KEY.G,0]);
          keys2type.push([kb.KEY.H,0]);
          keys2type.push([kb.KEY.I,0]);
          keys2type.push([kb.KEY.J,0]);
          keys2type = keys2type.reverse();
          // Start the keyboard typer
          startKbTimer();
          console.log("[Long press]");
        }
      }
    }
    
    var refusedMac = [];
    
    function onInit() {
      NRF.setServices(undefined, { hid : kb.report });
      
      // trigger btnPressed whenever the button is pressed
      setWatch(btnPressed, BTN, {edge:"both",repeat:true,debounce:50});
      
    }
    

    Short press creates no problems, so I'll ignore that scenario.
    Long press produces the following results on 1v99 release (in IDE console):

    >
    e.state: true
    e.time: 29.25888061523
    e.lastTime: undefined
    duration: NaN
    e.state: false
    e.time: 31.44192504882
    e.lastTime: 29.25888061523
    duration: 2.18304443359
    Starting kbTimer
    [Long press]
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    Starting kbTimer
    Clearing kbTimer
    >abcdefghij 
    
    

    Exact same code on 1v99 cutting edge does the following

    >
    e.state: true
    e.time: 31.09606933593
    e.lastTime: 26.1181640625
    duration: 4.97790527343
    e.state: false
    e.time: 32.39065551757
    e.lastTime: 31.09606933593
    duration: 1.29458618164
    Starting kbTimer
    [Long press]
    Clearing kbTimer
    Uncaught Error: Got BLE error code 12292
     at line 1 col 55
    NRF.sendHIDReport([0,0,0,0,0,0,0,0],funcĀ­tion(){a&&a()})
                                                          ^
    in function called from system
    >aaaaaaaaaaaaaaaa<keeps typing continuously...)
    
    

    You may notice that there is couple of commented out chunks of code that uses NRF.sendHIDReport() for typing instead of kb.tap(). I tried it as well and had the same error, but it looked something like this:

    Uncaught Error: Got BLE error code 12292
     at line ... col ...
          });
           ^
    

    Kind regards :)

About

Avatar for Gelo @Gelo started