Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update renderer to use readline parser and tagged serial data #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

widget-
Copy link

@widget- widget- commented Jun 1, 2021

Also sets the style of the bars to fill up the screen space, though it could probably be done a little better using flexbox or something.

It also sets the baud rate to 115200 because 9600 isn't fast enough to keep up.

The arduino firmware will end up needing these changes to match:

# serial.h

void printValues() {
+ Serial.print("v");
  for (int i = 0; i < NUM_STEPS; i++) {
    Serial.print(" ");
    Serial.print(padValues[i]);
  }
  Serial.print("\n");
}

void printThresholds() {
+ Serial.print("t");
  for (int i = 0; i < NUM_STEPS; i++) {
    Serial.print(" ");
    Serial.print(THRESHOLDS[i]);
  }
  Serial.print("\n");
}
# config.h

  // Serial baud rate
- #define BAUD_RATE 9600
+ #define BAUD_RATE 115200

@widget-
Copy link
Author

widget- commented Jun 1, 2021

Oh and my editor reformatted the whole thing. If you have a preferred style I can switch to that.

initializePort(event.target.value);
});
});
const ports = await serialport.list();
Copy link
Author

@widget- widget- Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you await stuff you don't need to .then() it anymore. It's a little confusing but it automatically does that in the background so that you can pretend it's blocking code even though Javascript can't block.

activePort = new serialport(portName, {
baudRate: baudRate,
});
parser = activePort.pipe(new Readline({ delimiter: "\n" }));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parser bit is new. Incoming data goes through parser but outgoing data still goes through activePort.

let intervalHandle;

// HTML elements
let stepDivElements = [];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed all these to make it clear that they're HTML elements.

canvas.width,
3
);
let canvasWidth = canvas.clientWidth;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the canvas sizes are dynamic now, we can fetch them with this instead of using their default values which won't ever scale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant