Looks great. Do you think we should have the extra asString though? I'd be tempted just to always return a Uint8Array.
I'd be happy to add functions to the 1v72 release of Espruino for easy string/array conversion (could do this today) - which would avoid all that code duplication.
I'm thinking:
I2C.readFrom to return a Uint8Array
OneWire.read to take an optional argument for length, and to return a Uint8Array if it's nonzero
E.asUint8Array to convert all arguments to a Uint8Array, eg: (1,2,511) -> [1,2,255] or (1,[3,4],"Hello") -> [1,3,4,72,101,...]
E.asString which works like E.asUint8Array, but creates a string.
That's all code that exists anyway (SPI.write uses it to convert whatever args it has to strings).
Any thoughts on the names? I'm not too happy with asString/asUint8Array.
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.
Looks great. Do you think we should have the extra
asString
though? I'd be tempted just to always return a Uint8Array.I'd be happy to add functions to the 1v72 release of Espruino for easy string/array conversion (could do this today) - which would avoid all that code duplication.
I'm thinking:
E.asUint8Array
to convert all arguments to a Uint8Array, eg:(1,2,511) -> [1,2,255]
or(1,[3,4],"Hello") -> [1,3,4,72,101,...]
E.asString
which works likeE.asUint8Array
, but creates a string.That's all code that exists anyway (
SPI.write
uses it to convert whatever args it has to strings).Any thoughts on the names? I'm not too happy with asString/asUint8Array.