Task-Tracker-Systems / Task-Tracker-Device

Sources for a task time recording device.
https://task-tracker-systems.github.io/Task-Tracker-Device/
MIT License
2 stars 0 forks source link

debounce buttons with a non-memorizing startup delay based on `std::thread` #114

Closed dhebbeker closed 6 months ago

dhebbeker commented 7 months ago

Introduce a new Worker class which is a wrapper around a std::thread and:

Resolves #113.

dhebbeker commented 6 months ago

My current attempt (f61d16bf3f29ddf3fdf1f871570fb94ebd1a93bd) is problematic as using functions from the C++ Standard Library within an ISR can cause problems.

For debouncing I may simply use millis(). But the question remains on how to do the actual work if I don't want to do this in the context of the ISR nor by starting a std::thread directly from within an ISR.

dhebbeker commented 6 months ago

See also:

dhebbeker commented 6 months ago

I moved the thread management outside of the ISR into a separate thread which continuously polls for signals set by the ISR. The signals are set by the ISR using std::atomic_flag which are lock-free.

This works in general. But it means that we have a polling thread which is not a good design (comment 1, comment 2, article (did not read yet)). It may become a problem when we want to use sleep modes for the processor for power saving. 🔋

dhebbeker commented 6 months ago

This is closed in favour of #116 which does not rely on polling.