You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • At first glance: I see that the actual keyboard tapping got lost...

    @tronic98776, can you explain me a bit more what you mean by

    laying around ... in an editor so I can get some output in the browser.

    If you mean by that that you made an html page with js and run it in chrome, you need to emulate the keyboard / the module that you pull in because you do not have the actual ble hardware that does the tap. You can do such an emulation....

    I you mean by that you use the Espruino IDE (in the browser) and use the puck, no special things are needed.

    For the latter, let's look how you can add a console log that preserves the previous function.

    ,   _send: function(c) {
            console.log("About to send char",c);
            kb.tap(kb.KEY[c],0,this._sent.bind(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.");
            }
        }
    

    Line 3 means: tap - send - this char c, and when done resume with _sent().

    Note why I put the commas as first thing of a thing and NOT at the end of a thing is so I can simply copy blocks from and to anywhere without worrying of the comma (except first), ... the comma is actually a continuation character for the parsing / tokenizing and has only to be there when something same follows... so I put the things together that 'belong' together...

    Regarding the kb.KEY[c] has nothing to do with the 'normal' understanding of arrays..., because after all, kb.KEYis not an array but an typical object with lots of lots of properties, andc` is NOT a number but a character (even if is the character 1 which looks like the number 1). The used approach is the addressing of an object property with the property name as variable:

    Given the JS object var obj = { propA: "A", propN: 1}; and string var propAName = "propA";, the following expressions obj.propA, obj["propA"] and obj[propAName] are all the very same... this is JS..

    Back to keyboard in the code example: KEY of kb.KEY is such an object - as you can see in the module http://www.espruino.com/modules/ble_hid_­keyboard.js - who's properties are now dynamically pulled w/ the variable c: if var c = "A";, then KEY[c] is the same as KEY.A and KEY["A"].

About

Avatar for allObjects @allObjects started