Skip to content
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

Fix long Ticker period conversion: cast ms to uint64_t when calculating us #3175

Merged
merged 2 commits into from
Sep 5, 2019

Conversation

full-stack-ex
Copy link
Contributor

Long duration was truncated when calculating milliseconds * 1000. ESP32 only: functions esp_timer_start_* require microseconds as uint64_t. ESP8266 is not affected as it uses a different API.

@@ -43,9 +43,9 @@ void Ticker::_attach_ms(uint32_t milliseconds, bool repeat, callback_with_arg_t
}
esp_timer_create(&_timerConfig, &_timer);
if (repeat) {
esp_timer_start_periodic(_timer, milliseconds * 1000);
esp_timer_start_periodic(_timer, ((uint64_t)milliseconds) * 1000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add "ULL" to the 1000 as well to also force cast there. This is also done in the millis() function as seen here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 1000ULL added. Prior change (the uint64_t cast) reverted as redundant. Tested: Ticker used to fire after 900+ seconds, now it hasn't fired for 1342s, and counting.

@me-no-dev me-no-dev merged commit 2a7e509 into espressif:master Sep 5, 2019
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.

3 participants