Can I require another module from within a module?
You can, yes - but if you require multiple modules then multiple ones will be included, which probably isn't what you want.
var USBHost = require("USBHost").connect(require("max3421").connect(SPI1, A0, ...));
This is probably what you want... If it's an issue it could always be shortened to require("USBHostMax3421") with another module later on as you note.
I'm not sure how to handle interupts and gpio querries
Yes, setWatch is fine - an no real issues with modules, no.
delay
For 60ms I'd say setTimeout and callbacks would be preferable (I really try not to use hard delays for anything more than a few milliseconds). I tend to use callback(err) so if error is undefined it's ok.
However promises might be good. They're fine on Espruino and while they might be overkill for the 60ms delay, you may find they actually save you loads of time and effort when you're looking at doing the actual USB negotiation stuff - and if you use them for everything the the API it'll make it seem much cleaner.
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.
You can, yes - but if you require multiple modules then multiple ones will be included, which probably isn't what you want.
This is probably what you want... If it's an issue it could always be shortened to
require("USBHostMax3421")
with another module later on as you note.Yes,
setWatch
is fine - an no real issues with modules, no.For 60ms I'd say setTimeout and callbacks would be preferable (I really try not to use hard delays for anything more than a few milliseconds). I tend to use
callback(err)
so if error is undefined it's ok.However promises might be good. They're fine on Espruino and while they might be overkill for the 60ms delay, you may find they actually save you loads of time and effort when you're looking at doing the actual USB negotiation stuff - and if you use them for everything the the API it'll make it seem much cleaner.