Skip to content

Convert LF to CRLF when writing to serial port #474

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

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ impl SerialPort {

impl fmt::Write for SerialPort {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.port.write_str(s).unwrap();
for char in s.bytes() {
match char {
b'\n' => self.port.write_str("\r\n").unwrap(),
byte => self.port.send(byte),
}
}
Comment on lines +20 to +25
Copy link
Member

Choose a reason for hiding this comment

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

Another fix for #473 might be to change the writeln! call to a write("...\r\n") call, this wouldn't work if the log message contains multi-line strings, so I think this solution is preferable.

Performance could certainly be improved a bit, but this code is not at all performance-critical, so let's keep things simple.

Ok(())
}
}
Loading