Avatar for Gelo

Gelo

Member since Sep 2018 • Last active Oct 2018
  • 1 conversations
  • 6 comments

Most recent activity

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Gelo

    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...

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Gelo

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

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Gelo

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

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Gelo

    Hi Gordon,
    Sorry it took me a while to try things and gather all the info to post here.
    I've tried flashing 1v99 cutting edge and back to 1v99 stable countless times trying to figure out what's going on here.
    And in the process, I think I found a problem with cutting edge firmware. I'll post it in a separate thread.
    Back to the problem of puck not reconnecting.
    Cutting edge firware didn't help no matter what I did. It is definitely running as a keyboard and is working fine until the connection breaks and then never reconnects again unless I initiate connection from IDE, or completely remove the device in Windows settings and re-add it again.

    Then I found something even more interesting. I decided that I am going to always keep the puck next to my laptop and never separate them, and after a few hours I found that the Bluetooth was completely down on my Surface laptop. Inspecting Bluetooth in Windows Device Manager reviled that the driver crashed/stopped. Disabling and re-enabling the device didn't help. I had to either reboot the laptop or completely uninstall Bluetooth and run Bluetooth troubleshooter a few times to revive it.
    After revival, Bluetooth works for a few more hours and the story repeats itself.
    I've been doing since my last post trying to figure things out, but so far no clues that I can find anywhere, except that it only happens when the puck is connected. I don't even end up using it much, just a couple of time in the whole time and sometimes even not that, but the Bluetooth dies very reliably in just 3-4 hours each time every time.
    Not sure what to make of this.
    Anyone else experiencing this?

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Gelo

    Hi Gordon,
    Thanks for your reply.
    Yes, I'm on the latest firmware 1.99. I also tried re-flashing which didn't help.
    I'm aware of HID not being available immediately after I run the code. I am already re-paired and the Puck is definitely seen as HID keyboard, because it types and windows shows it as Bluetooth keyboard in the list of devices.
    I also thought that Windows should reconnect it, but it doesn't. Very weird.
    In case you want to know, the laptop is MS Surface Laptop with latest Win 10.

    I am thinking I could try re- flashing with cutting edge version?..
    Will let you know if it makes a difference.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for Gelo

    Hello community!

    I actually have a very similar problem, but I'm not doing anything with BLE at all (i.e. not trying to save power or anything).
    I just pair/connect my Puck to my Win 10 laptop as HID-keyboard and use it to automate a couple of things by pressing the button (just emit key presses).

    Here's how I initialize the Puck (the code pretty much straight out of HID tutorial):

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    // Define button press handler
    function btnPressed(e) {
          digitalPulse(LED1,1,50);
          // Send some key(s) here...
          kb.tap(kb.KEY.ENTER, 0, function() {});
    }
    
    function onInit() {
      // trigger btnPressed whenever the button is pressed
      setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50})­;
    }
    

    The problem:
    Because I often take my laptop and walk away from my desk where the Puck is, BLE connection breaks - this is expected. But when I come back to my desk, the connection never restores by itself. It shows as "paired" but not connected.
    I have to open IDE and initiate a connection to the Puck, which works fine, but is a real pain in the bum because this happens a LOT.

    Is this normal? My Bluetooth keyboard and headphones reconnect fine, and I would expect the Puck to do the same...

    Is there anything I can do to fix this?

    Thanks.

Actions