• 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 :)

  • By the way, does 1v99 release preceed 1v99 cutting edge, or is it the other way around?

  • Ok, just saw this other thread about exact same error: http://forum.espruino.com/conversations/­325524/

    I can confidently say that this doesn't happen in 1v99 release...

  • does 1v99 release preceed 1v99 cutting edge, or is it the other way around?

    Yes - 1v99 is older than the cutting edge.

    So looking at the code, you're not actually calling tap until you've had the callback to the last one? As you say, that sure seems like it should be fine. I'll take a look.

  • Ok, just tried this, with the console.log on Serial... If you try:

        console.log("[tap]");
        kb.tap(..., function() {
          console.log("[tap done]");
           ...
        });
    

    both places you call tap then you can see that you can definitely get it into a position where you're calling .tap before the last one has finished, which will cause an error:

    [tap]
    [tap done]
    Starting kbTimer
    Clearing kbTimer until finished typing
    [tap]
    e.state: true
    e.time: 1538038837.98822593688
    e.lastTime: 1538038837.25543785095
    duration: 0.73278808593
    [tap done]
    Starting kbTimer
    Clearing kbTimer until finished typing
    [tap]
    e.state: false
    e.time: 1538038838.10324668884
    e.lastTime: 1538038837.98822593688
    duration: 0.11502075195
    [tap]
    [Short press]
    Uncaught Error: BLE HID already sending
     at line 1 col 55
    NRF.sendHIDReport([0,0,0,0,0,0,0,0],func­tion(){a&&a()})
                                                          ^
    in function called from system
    [tap done]
    

    However, no BLE error code 12292.

    What I'm pretty sure is happening is a few things are all conspiring against you:

    • After some inactivity, Espruino will now enter a low-bandwidth, low-power mode. (can be fixed with NRF.setConnectionInterval as that post you linked shows
    • First thing you do after a button press is print a load of stuff over Bluetooth. This uses up most of the available TX slots (apart from one for HID)
    • The HID report is sent - all TX slots are used up, but that's fine
    • Not all of the TX packets get sent the next time (possibly because of negotiation to exit the low power mode)
    • Espruino gets notified that TX packets were sent - it has no way of knowing which ones, so it assumes HID has been sent and tells your code.
    • Your code sends another HID packet, but it fails this time because there are no free TX slots

    Basically there's not much I can do about it apart from to only send one TX packet at a time instead of 5, reducing Espruino's TX speed by a factor of 5 - so that is what I've done. Hopefully if you try a cutting edge build now it'll be fixed.

    I don't think on the whole people will notice too much as it's really the RX speed that's the killer.

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

Uncaught Error: Got BLE error code 12292 in 1v99 cutting edge but not in release

Posted by Avatar for Gelo @Gelo

Actions