Skip to content

HardwareSerial's flush() method to override the method of the base class Print #2254

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jan 22, 2024

Conversation

ilolis
Copy link
Contributor

@ilolis ilolis commented Jan 19, 2024

This PR addresses the following bugs/features

  • Bug: Fixing issue with base class Print's void flush() method not being overridden by derivative HardwareSerial's void flush(uint32_t timeout = 0) method.

The base class Print defines void flush(), while the derivative HardwareSerial defines void flush(uint32_t timeout = 0). The issue was that when using the base class instance pointer, the virtual function of the derivative was not being called. This PR resolves this.

I might be missing something since I am new to this project, so please feel free to correct me :)

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.

LGTM
Thanls @ilolis

@fpistm fpistm added this to the 2.8.0 milestone Jan 22, 2024
@fpistm
Copy link
Member

fpistm commented Jan 22, 2024

Tested with:

Stream &myStream = Serial; 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  myStream.println(sensorValue);
  myStream.flush();
  delay(1);  // delay in between reads for stability
}

@fpistm fpistm merged commit 49b8eef into stm32duino:main Jan 22, 2024
tadtruex pushed a commit to TadAtThayer/Arduino_Core_STM32 that referenced this pull request Apr 23, 2024
…ass Print (stm32duino#2254)

* add flush() method to HardwareSerial

* remove default argument
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants