-
Notifications
You must be signed in to change notification settings - Fork 11
Load Bitcoin address on successful WebUSB connection #21
Conversation
* Define a `send_command` function in the arduino sketch which sends a "command" and a "payload" across the WebUSB serial conection to the frontend. They are delimited by a "," which is a bit hacky ... * Update App.state.address we receive an "addr" command.
port.onReceiveError = this.handleSerialError.bind(this) | ||
|
||
// Try to load our bitcoin address | ||
let textEncoder = new TextEncoder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is becoming "callback hell". We'll need to refactor soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can include it in some kind of "device" class with isConnected(), connect(), requestMasterPublicKey() etc methods. The easiest way to get rid of the callback hell right now is to switch to async/await syntax.
@@ -33,6 +41,11 @@ void show(String msg, bool done=true){ | |||
} | |||
} | |||
|
|||
void send_command(String command, String payload) { | |||
String combined = command + String(",") + payload; | |||
Serial.println(combined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ","-delimiting is hacky
Perhaps we don't want to use Serial.println. The frontend gets some messages that seem to be just new-line characters and this could be why ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea to pass command code with the response. ","-delimiting is ok for now.
It makes sense to switch to raw binary packets later with a form like <command_code>
I would like to keep human-readable format also, for debugging, but binary is usually more efficient and easier to work with.
@@ -33,6 +41,11 @@ void show(String msg, bool done=true){ | |||
} | |||
} | |||
|
|||
void send_command(String command, String payload) { | |||
String combined = command + String(",") + payload; | |||
Serial.println(combined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea to pass command code with the response. ","-delimiting is ok for now.
It makes sense to switch to raw binary packets later with a form like <command_code>
I would like to keep human-readable format also, for debugging, but binary is usually more efficient and easier to work with.
port.onReceiveError = this.handleSerialError.bind(this) | ||
|
||
// Try to load our bitcoin address | ||
let textEncoder = new TextEncoder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can include it in some kind of "device" class with isConnected(), connect(), requestMasterPublicKey() etc methods. The easiest way to get rid of the callback hell right now is to switch to async/await syntax.
send_command
function in the arduino sketchwhich sends a "command" and a "payload" across the WebUSB serial
conection to the frontend. They are delimited by a "," which is
a bit hacky ...