You are reading a single comment by @tronic98776 and its replies. Click here to read the full conversation.
  • Thank you @allObjects. I have this working now. Initially it had the same error, but after increasing the setTimeout from 1 to 50, it worked in the console. However, it would fail if anything was added to FIFO string whilst a send was in progress, but increasing the setTimeout to 100 has cured this.

    To get it to type the string over bluetooth I had to get rid of all the console.logs. Here is the code I have working now:

    
    function onInit() {
      var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    // setup of you convenience hidKeyBoardObject... (here or later)
    var hidKBD = ( { string: ""
                    
    , type: function(s) { 
        this.string += s; 
        if (this.string.length == s.length) { 
                          
                          
          this._send(this.string.charAt(0)); // get first char out
      } }
    ,   _send: function(c) {
           // console.log("About to send char",c);
            setTimeout(function(_){
                kb.tap(kb.KEY[c],0,_._sent.bind(_)); },100,this);
        }
    ,   _sent: function() {
            //console.log("Char",this.string.charAt(­0),"has been sent / tapped");
            this.string = this.string.substring(1);
            //console.log("Left to send / tap is",this.string);
            if (this.string.length > 0) {
              //  console.log("Since length of this.string //is",this.string.length
      //                     ,"and is > 0, next char 'in line' -"
                           //,this.string.charAt(0)," - has to be sent / tapped.");
                this._send(this.string.charAt(0));
            } //else {
              //  console.log("Since nothing is left to tap / send - all is tapped");
                //console.log("/ sent, (FIFO  is empty), nothing has to be done");
                //console.log(" anymore and  'logical recursion' stops/ends  here.");
            //}
        }
    });
    
    // setup and other code functions of yours (here or before hidKBD)
       // invoke your set up code as needed (init and getting connections)
       function startSend(){
         hidKBD.type("ABCCANNONBALL");}
      // hidKBD.type("XYZ");
    
    	
    setWatch(startSend, BTN, {edge:"rising",repeat:true,debounce:50})­;
    }
    
    
    
About

Avatar for tronic98776 @tronic98776 started