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

Allow setting skip_unhandled_events on esp timer #526

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

julienvincent
Copy link
Contributor

Currently the esp timer service hardcodes the skip_unhandled_events flag to false which means there is no way to construct a timer that doesn't wake the device from light sleep.

This change introduces a skip_unhandled_events fn on the EspTimerService which allows changing the value of this timer flag.


I added this as a mutating fn on the timer service - but I wonder if it's a better design to make the new constructor accept this flag. I didn't want to change it's signature though to avoid introducing a breaking change.

@ivmarkov
Copy link
Collaborator

ivmarkov commented Dec 11, 2024

It is desirable to keep backwards compatibility in EspTimerService indeed. While we broke backwards compatibility just a couple of days ago in EspNow, EspNow is a bit of a niche, leaf-only code, while EspTimerService is used everywhere.

With that said, I don't think it is ideal to have the newly introduced flag on the global EspTimerService level. Isn't it better to introduce it (in the form of new functions) when you are creating a timer instead? I.e. with extra, new timer_* methods?

Copy link
Collaborator

@ivmarkov ivmarkov left a comment

Choose a reason for hiding this comment

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

As per my other comment.

@julienvincent
Copy link
Contributor Author

With that said, I don't think it is ideal to have the newly introduced flag on the global EspTimerService level. Isn't it better to introduce it (in the form of new functions) when you are creating a timer instead? I.e. with extra, new timer_* methods?

@ivmarkov Ok I tried this out but it just seems a bit messy to me. There then needs to be multiple new methods all doing the same thing sans flag.

See 8af264d for WIP implementation of the above.

Is this what you had in mind?

@ivmarkov
Copy link
Collaborator

With that said, I don't think it is ideal to have the newly introduced flag on the global EspTimerService level. Isn't it better to introduce it (in the form of new functions) when you are creating a timer instead? I.e. with extra, new timer_* methods?

@ivmarkov Ok I tried this out but it just seems a bit messy to me. There then needs to be multiple new methods all doing the same thing sans flag.

See 8af264d for WIP implementation of the above.

Is this what you had in mind?

Yes, that's what I had in mind.
It might be a bigger change, but it is still might be a bit less risky than your original suggestion, in that while the EspTimerService is not technically a singleton, it is used as such, and it might become a singleton in future.

If that happens, then you have to decide - for your whole app - if you want ALL timers to skip events or not skip events. Hence why I think it is better to have it on a per-timer level, which mostly follows the ESP IDF API/approach anyway.

If you could lower a bit the copy-pasted methods in your 8af264d (perhaps, by introducing an extra internal_* method or two), then I think that would be the better suggestion, yes.

@julienvincent julienvincent force-pushed the jv/unhandled-events-timer branch from 0fb6761 to 5b71693 Compare December 11, 2024 13:56
@julienvincent
Copy link
Contributor Author

Thanks for the explanation that all makes perfect sense.

I've made the requested changes, including deduplicating the timer_async implementation.

Currently the esp timer service hardcodes the `skip_unhandled_events`
flag to `false` which means there is no way to construct a timer that
doesn't wake the device from light sleep.

This commit introduces new `*_nowake` methods for each of the existing
`timer_*` methods which allow constructing timers with
`skip_unhandled_events` set to `true`.
@julienvincent julienvincent force-pushed the jv/unhandled-events-timer branch from 5b71693 to 31863d6 Compare December 11, 2024 14:01
@ivmarkov
Copy link
Collaborator

Thanks!

@ivmarkov ivmarkov merged commit 2ab28b1 into esp-rs:master Dec 11, 2024
15 checks passed
@julienvincent julienvincent deleted the jv/unhandled-events-timer branch December 11, 2024 21:08
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.

2 participants