Chorus32-ESP32LapTimer
Chorus32-ESP32LapTimer copied to clipboard
Implement module multiplexing
This implements multiplexing and fixes #49 Another way too large one, sorry! It might still contains a few unrelated changes, which need to be removed.
The most notable change is, that we have to differentiate between pilots and modules. All active pilots are pushed into a queue and if there is a pilot in the queue it gets assigned to a module if:
- The module hasn't switched in MULTIPLEX_STAY_TIME_US + MIN_TUNE_TIME_US
- The waiting client has been without a module for at least MULTIPLEX_STAY_TIME_US + MIN_TUNE_TIME_US
- The intention is, that with 4 modules and 5 pilots we prevent switching of all modules
If no multiplexing is needed the queue is empty and only the initial assignment will occur.
This also powers down all unused modules if the number of activated pilots is less than the number of modules and allows any pilot combination to be activated with minimal module usage (for example enabling pilot 2 and 5 only powers module 1 and 2): By default it enables as many pilots as modules are configured, so the default shouldn't change.
I experimented a little bit with filtering (like dynamically adjust the dt or use the average sampling rate), but I had the best result with just using the normal sampling frequency and just ignore the tune time. In my first tests there was only a very minor difference when using a 2nd order bessel lowpass in comparison to a 1st order lowpass.
As my other modules are still on the way I was only able to test it with a single module installed.