I already connected an old keyboard to my test setup, but didn't found the time so far to go further than that. In fact - as you mentioned - some basic module for USB Host handling could be written easily. From there it should be fairly easy to get some keyboard demo working.
There are just a few questions left from my side:
Can I require another module from within a module? I have found something like that in the touchscreen example, but I'm not aware issues with this approach. The touchscreen example implicitly pre-connects the ADS7843.
Rather than this, I'd like to have something like passing an interface to the usb-host module. The code should look something like:
var USBHost = require("USBHost").connect(require("max3421").connect(SPI1, A0, ...));
in the end.
Within the module I would need a way to determin what module has been passed. If it is of type max3421 it use this internally.
This would have the advantage to write the code of USBHost as independend and reusable as possible.
Alternatively, I could write a module named USBHostMax3421, which kind of inherits from Max3421. The initialization would look like this then:
var USBHostMax3421 = require("USBHostMax3421").connect(SPI1, A0, ...));
This is probably easier in the beginning, but less flexible in the long run.
Also I'm not sure how to handle interupts and gpio querries. The original arduino code uses a loop to check periodically for 'tasks'. With Espruino this translates to watches, doesn't it? If I use them, are there known issues in regards of the use in modules?
And one last question. The original code uses delays at some point to wait that some capacitors are fully loaded. So far I have translated the code directly using some time burning hack. While the time is very little (60ms), I'd like to get rid of this. Now I wonder whether there are better alternatives?
The only alternative that comes to my mind is using callbacks like:
but that bloats the caller code and requires some more handling on that part.
Or should I use promises? While they look very smart, I tend not to use them in my web projects, because they used to be not fully supported by some browsers.
© Espruino, powered by microcosm.
Report a problem