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/issues/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});
@Gordon started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
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/issues/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.