You are reading a single comment by @tronic98776 and its replies. Click here to read the full conversation.
  • Hello

    And thanks in advance for any help. I'm quite new to coding JS, but always keen to learn.

    I'm trying to programme my Puck.js to connect to another device as BLE HID Keyboard. I have successfully got this working and I am able to send a character or two to the device after pressing the button on the puck. What I now want to do is send a whole word or sentence from the button press. Here is where I am having issues. I have tried creating many different functions to do this, but none of it seems to work successfully. I seem to reach a maximum series of characters (7), before strange things happen like the the seventh character repeating endlessly.

    I tried mapping each of the kb.tap commands to an individual function, but this didn't help things and then I tried using the low level commands too, but this also resulted in the same issues. I'm also a bit confused as to why the example given in the puck tutorial has an "a" followed by "A", but rather than them being separate lines within the function, they are nested within one another (this is likely due to my lack of JS experience), but I couldn't find reference to this practice anywhere.

    On my code below you can see I tried to construct a sequence of A,B,C,D,E,F,G,H... to send to my connected device. There are several functions in there that I tried; sendCap, sendLowLevel, sendNewTest and myCommand, none of which worked.

    function onInit() {
    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    function sendLowA() {
      kb.tap(kb.KEY.A, 0);
    }
      
    function sendLowB() {
      kb.tap(kb.KEY.B, 0);
    }
      
    function sendLowC() {
      kb.tap(kb.KEY.C, 0);
    }
      
    function sendLowD() {
      kb.tap(kb.KEY.D, 0);
    }
      
    function sendLowE() {
      kb.tap(kb.KEY.E, 0);
    }
    
    function sendCap() {
      // Send 'a'
      kb.tap(kb.KEY.A, 0, function() {
        // Followed by 'b'
        kb.tap(kb.KEY.B, 0, function() {
        // Followed by 'c'
        kb.tap(kb.KEY.C, 0, function() {
        // Followed by 'd'
        kb.tap(kb.KEY.D, 0, function() {
        // Followed by 'e'
        kb.tap(kb.KEY.E, 0, function() {
        // Followed by 'f'
        kb.tap(kb.KEY.F, 0, function() {
        // Followed by 'g'
        kb.tap(kb.KEY.G, 0, function() {
        // Followed by 'h'
        kb.tap(kb.KEY.H, 0, function() {
        // Followed by 'i'
        kb.tap(kb.KEY.I, 0);
        });
        });
        });
        });
        });
        });
        });
        });
      
    }
      
    function sendLowLevel() {
      NRF.sendHIDReport([2,0,4, 5, 6, 7, 8, 9, 10, 11 ], function() {
      NRF.sendHIDReport([2,0,5], function() {
      NRF.sendHIDReport([2,0,4], function() {
      NRF.sendHIDReport([0,0,0]);
    });
    });
    });
    }
      
    function sendNewTest() {
      NRF.sendHIDReport([2,0,4], function() {
      NRF.sendHIDReport([0,0,0]);
    });
      NRF.sendHIDReport([2,0,5], function() {
      NRF.sendHIDReport([0,0,0]);
    });
      NRF.sendHIDReport([2,0,6], function() {
      NRF.sendHIDReport([0,0,0]);
    });
      NRF.sendHIDReport([2,0,7], function() {
      NRF.sendHIDReport([0,0,0]);
    });
      NRF.sendHIDReport([2,0,8], function() {
      NRF.sendHIDReport([0,0,0]);
    });
      NRF.sendHIDReport([2,0,9], function() {
      NRF.sendHIDReport([0,0,0]);
    });
      NRF.sendHIDReport([2,0,10], function() {
      NRF.sendHIDReport([0,0,0]);
    });
      NRF.sendHIDReport([2,0,11], function() {
      NRF.sendHIDReport([0,0,0]);
    });
      
    }
      
    function myCommand() {
      sendLowA();
      sendLowB();
      sendLowC();
    }
      
    // trigger btnPressed whenever the button is pressed
    setWatch(sendNewTest, BTN, {edge:"rising",repeat:true,debounce:50})­;}
    
    
    // flash the blue LED to indicate button press
     // digitalWrite(LED3, true);
      //setTimeout("digitalWrite(LED3, 0);", 100);```
    
About

Avatar for tronic98776 @tronic98776 started