If the loop() took more than the required time, don't delay further (#6496)

This commit is contained in:
Clyde Stubbs 2024-04-08 17:56:08 +10:00 committed by GitHub
parent d6352b3be4
commit e6b1187689
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,13 +81,11 @@ void Application::loop() {
const uint32_t now = millis();
if (HighFrequencyLoopRequester::is_high_frequency()) {
auto elapsed = now - this->last_loop_;
if (elapsed >= this->loop_interval_ || HighFrequencyLoopRequester::is_high_frequency()) {
yield();
} else {
uint32_t delay_time = this->loop_interval_;
if (now - this->last_loop_ < this->loop_interval_)
delay_time = this->loop_interval_ - (now - this->last_loop_);
uint32_t delay_time = this->loop_interval_ - elapsed;
uint32_t next_schedule = this->scheduler.next_schedule_in().value_or(delay_time);
// next_schedule is max 0.5*delay_time
// otherwise interval=0 schedules result in constant looping with almost no sleep