Hi, I have tried to work on this a bit and got confused by the use of connections in uart.js.
I would like to use the nice utility functions UART.write() and UART.eval() but do not want them to trigger their own connect event (that is showing up the select a port screen). I would like to connect only once when the user decides to and be able to all operations from there.
But using the connection.on("data", cb) pattern and the write() and eval() helper function from UART seems incompatible as the UART.write() and UART.eval() are using their own separate internal connection variable.
It feels not optimal to have to duplicate that part of the code: https://github.com/espruino/EspruinoWebTools/blob/13032d0e862d9976ed5eed33b42f07e93e6c25c3/uart.js#L403-L500 entirely to replicate the UART functionalities from a connection that I would open using the method described in https://www.espruino.com/Web+Bluetooth#two-way-communications
This is actually commented in the code by saying that the UART.connect function output a connection different from the one used by write() and eval(), see image attached.
I guess my questions are:
If that does not work, I guess I will have to reimplement something similar to write and eval functionality but with the connection.on("data", cb) working somehow on the with it.
I am guessing I am a bit confused with how connection works under the hood but I hope that makes some sense :)
Thanks in advance for any guidance on that!
© Espruino, powered by microcosm.
Report a problem