Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Load Bitcoin address on successful WebUSB connection #21

Merged
merged 2 commits into from
Aug 28, 2018

Conversation

justinmoon
Copy link
Contributor

  • Include the arduino-webusb library
  • 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.

* 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();
Copy link
Contributor Author

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.

Copy link
Member

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);
Copy link
Contributor Author

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 ...

Copy link
Member

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.

This was referenced Aug 28, 2018
Merged
@@ -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);
Copy link
Member

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();
Copy link
Member

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.

@stepansnigirev stepansnigirev merged commit 65b802d into master Aug 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants