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

Merged
merged 1 commit into from
Apr 25, 2025

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");
}

@fpistm fpistm added the enhancement New feature or request label Apr 17, 2025
@fpistm fpistm added this to the 2.11.0 milestone Apr 17, 2025
@fpistm
Copy link
Member

fpistm commented Apr 22, 2025

Hi @patricklaf
Thanks for the PR.
It makes sense.
I've made a commit on top of your change to go further in the logic:
fpistm@e07f5af

Please, could you check it and give your feedback.
If ok for you could you add it to your PR and squash all commits in one?

@patricklaf patricklaf closed this Apr 24, 2025
@github-project-automation github-project-automation bot moved this from In progress to Done in STM32 core based on ST HAL Apr 24, 2025
@patricklaf patricklaf reopened this Apr 24, 2025
@github-project-automation github-project-automation bot moved this from Done to In progress in STM32 core based on ST HAL Apr 24, 2025
Signed-off-by: patricklaf <[email protected]>
@fpistm fpistm self-requested a review April 24, 2025 08:10
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

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

Thanks @patricklaf
LGTM

@github-project-automation github-project-automation bot moved this from In progress to Reviewer approved in STM32 core based on ST HAL Apr 25, 2025
@fpistm fpistm merged commit 6a98725 into stm32duino:main Apr 25, 2025
24 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer approved to Done in STM32 core based on ST HAL Apr 25, 2025
@patricklaf
Copy link
Contributor Author

Thank you @fpistm for your help.

@patricklaf patricklaf deleted the patricklaf-serial branch April 26, 2025 09:02
@fpistm
Copy link
Member

fpistm commented Apr 26, 2025

Welcome and thanks to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

2 participants