...and made me conclude that this is the one reason - co-concluding w/ @Gordon:
re: 'which isn't actually in the code you pasted up'
indeed... :[ - because if the IDE settings are installation default with sandbox set, then the following application code uploads just fine - because there is no issue in the module - and it runs as expected (after issuing run(); in the console):
Module code (as in initially posted by @Robin in post #1 w/ semicolon (;) removed from 3rd line, since Espruinio IDE editor complains... :))
Above application code uses the method mode (I call it this way). It works because you added .create() plain function as property to the exports object which is the carrier to expose your exported .create() function. Since the exports is at the same time the constructor function (class) , I'm curious if it can be used in class mode as well:
// testLEDApp2.js - uses module testLED.js in 'class mode'
var testLED = new (require("testLED"))([B3]);
var iId = null;
function onInit() {
console.log("testLEDApp2 (testLED module in class mode)");
iId = setInterval(function(){
testLED.testUR();
},1000);
}
function run() { onInit(); }
function stop() { if (iId) iId = clearInterval(iId); }
***Just make sure that precedence to the Espruino interpreter with parentheses to get the module first and then apply 'new' to it - object return by it . ***
Also be aware that now an array with a pin (as first element) has to be passed in the constructor function with new to allow the constructor to work (and the upload not to fail, because - as said again - construction is executed on upload, since code is in level 0... and [sic: now rambling] I'm saying here again as said in many other places, that executing application code in Level 0 is 'bad' / calls for troubles, because it is executed and creates all kinds of havoc, timing, things not initialized when running disconnected, etc... therefore, the application code again in a more safe way, with execution of application code in onInit(){...} or triggered in onInit()) :
// testLEDApp3.js - uses module testLED.js in 'class mode'
var TestLED = require("testLED"); // get class (1st Upper)
var testLED; // instance of TestLED (1st lowercase)
var iId = null;
function onInit() {
console.log("testLEDApp2 (testLED module in class mode)");
testLED = new TestLED([B3]);
iId = setInterval(function(){
testLED.testUR();
},1000);
}
function run() { onInit(); }
function stop() { if (iId) iId = clearInterval(iId); }
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.
For me, things do still not add up...
...and made me conclude that this is the one reason - co-concluding w/ @Gordon:
indeed... :[ - because if the IDE settings are installation default with sandbox set, then the following application code uploads just fine - because there is no issue in the module - and it runs as expected (after issuing
run();
in the console):Module code (as in initially posted by @Robin in post #1 w/ semicolon (;) removed from
3rd
line, since Espruinio IDE editor complains... :))Application code:
Console output as expected:
Above application code uses the method mode (I call it this way). It works because you added
.create()
plain function as property to the exports object which is the carrier to expose your exported.create()
function. Since the exports is at the same time the constructor function (class) , I'm curious if it can be used in class mode as well:And guess what, it woks, as console output shows:
***Just make sure that precedence to the Espruino interpreter with parentheses to get the module first and then apply 'new' to it - object return by it . ***
Also be aware that now an array with a pin (as first element) has to be passed in the constructor function with new to allow the constructor to work (and the upload not to fail, because - as said again - construction is executed on upload, since code is in level 0... and [sic: now rambling] I'm saying here again as said in many other places, that executing application code in Level 0 is 'bad' / calls for troubles, because it is executed and creates all kinds of havoc, timing, things not initialized when running disconnected, etc... therefore, the application code again in a more safe way, with execution of application code in onInit(){...} or triggered in onInit()) :
And example of how to test the module inline as instructed by espruino.com/Writing+Modules:
NB: I'm PICO, and I approve this post! ...eh: code! ;-)