queue throttling + slave latency and minor refactor #1235
Merged
+64
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We had an edge case that turned out to be a faulty hardware/driver, but it made me re-think some stuff in the interface.
None of these changes should modify normal behavior (assuming good BT connection)
3 things in this PR:
Refactor:
Extracted magic/hardcoded numbers to defines (for future unification with ESP SerialBLEInterface)
Slave latency:
With slave latency = 4: The peripheral can skip up to 4 consecutive events and only wake up on the 5th event (or earlier if it has data to send)
Slave latency only applies when both devices have nothing to send.
Lower power: Less BT radio-on time / lower CPU usage
Less frequent BLE interrupts
Queue throttling on error:
If our queue is full we keep hammering with full speed.
Our queue being full 99% of the time means spotty BT connection (other 1 percent is if we want to send a lot of data, but that should clear up in 1 or 2 tries)
Serialbleinterface now throttles down retries to every 250msec with queue full, until the queue is starting to move again (or the BT connection times out ofc)