You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • 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
    • 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.


Avatar for Gordon @Gordon started