You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Ok, so I checked into this and it actually is an issue with the amount of nesting. Not the stack as such but the execution scopes:

    Uncaught Error: Maximum number of scopes exceeded
    

    There's an issue open for this at the moment but I honestly didn't think people were really hitting it: https://github.com/espruino/Espruino/iss­ues/948

    If this has been causing a lot of problems then I could look into fixing it sooner rather than later though.

    While @allObjects has posted a good solution above, here's the complete code that I just tested and which seems to work ok.

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    function tapMultiple(keys, callback) {
      // no keys? we're done!
      if (keys.length==0) return callback();
      // tap a key
      kb.tap(keys[0], 0, function() { 
        // recurse with the remainder of the array
        tapMultiple(keys.slice(1), callback);
      });  
    }
    
    function sendCap() {
      tapMultiple([
        kb.KEY.A,kb.KEY.B,kb.KEY.C,
        kb.KEY.D,kb.KEY.E,kb.KEY.F,
        kb.KEY.G,kb.KEY.H,kb.KEY.I],
                 function() {
        // we're done!
      });
    }
    
    // trigger btnPressed whenever the button is pressed
    setWatch(sendCap, BTN, {edge:"rising",repeat:true,debounce:50})­;
    
About

Avatar for Gordon @Gordon started