Replace the queued communications with deferred delays. #34
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.
The queued communications was, I believe, intended to ensure that
different parts of the system could issues the commands to the
display asynchronously and not have them trample on one another.
However, it was not effective with my flagship device, and almost
never produced an uncorrupted display.
The queue seems unnecessary, and complicates the logic of the
display communications. It has been removed, so that the operations
all happen when they are requested by clients, rather than being
delayed by an arbitrary amount of time by being queued. Instead,
all the operations have been protected by a mutex, similar to the
prior code, but surrounding the entire operation that must be
sequenced in order.
My own investigation implied that there needed to be a delay
between the bitmap data and the next command sent. It's not clear
why, but with this delay in place, the results were never corrupted.
Inserting the delay immediately after the bitmap data send would
work to allow the data to be sent uncorrupted, but it would force
there to always be a delay even when there would be time between
the bitmap and the next command. Instead the delay is deferred
until we try to send the next command - at which point we will
sleep. This means that the delay is amortised into subsequent
work.
The results are solid on my flagship model with a 0.02s delay. It
is possible that this is high, and it could be reduced. It is
possible that this does not work on model A devices, but I cannot
test this at this time. The necessary changes have been made to
the code, but I just have to hope they work.
Here's it working (tested 4 times to be sure):
WorkingTuringDisplay.mp4