Skip to content

feat (uart): implement proper operator bool() #2712

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

patricklaf
Copy link
Contributor

@patricklaf patricklaf commented Apr 15, 2025

This PR implements the HardwareSerial bool() operator.

Currently, the core blocks if there is a write to a closed HardwareSerial instance. The tx buffer will rapidly be full and the core waits forever for free space.

The bool() operator is a good way to check if the HardwareSerial object is opened and ready to transmit data but in the current implementation, it allways returns true.

The PR implements a complete bool() operator:

  • Returns true when the HardwareSerial object is ready.
  • Returns false when the HardwareSerial object is not ready.

Sample code:

Serial.begin();
if (Serial) {
  Serial.println("Serial is opened");
  Serial.flush();
}
Serial.end();
if (Serial) {
  Serial.println("Serial is closed. Never be printed");
}

Signed-off-by: patricklaf <[email protected]>
Signed-off-by: patricklaf <[email protected]>
Signed-off-by: patricklaf <[email protected]>
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