Fix "OSError: [Errno 9] Bad file descriptor" for Waveshare EPDs - #728
Open
motschel123 wants to merge 2 commits into
Open
Fix "OSError: [Errno 9] Bad file descriptor" for Waveshare EPDs#728motschel123 wants to merge 2 commits into
motschel123 wants to merge 2 commits into
Conversation
…o 9] Bad file descriptor"
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent OSError: [Errno 9] Bad file descriptor when updating Waveshare EPDs multiple times by reinitializing the EPD/SPI setup after the display is put to sleep (since some Waveshare drivers close the SPI FD during sleep()).
Changes:
- Persist the dynamically imported Waveshare EPD module on the
WaveshareDisplayinstance for reuse. - Add a
reinitialize_display()helper intended to recreate theEPD()instance and run its init method again. - Document the rationale for reinitialization in-code.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Waveshare EPDs fully close the SPI file descriptor when being put to sleep.
This result in
OSError: [Errno 9] Bad file descriptorwhen diplay_image is called a second time. See #452, #259.It can be discussed whether this is a bug in the waveshare drivers or intended behavior. However the fix proposed in #259 has been an open PR (waveshareteam/e-Paper#406) for half a year now without any reactions, so it can be assumed to not get fixed.
So heres the fix for this implementation:
The epd_module.EPD() constructor has to be called again for each display_image step.
For this i implemented a small reinitialize_display function for the waveshare_display which recreates the epd_display each time display_image is called.
To safe resources I made the dynamic module import an Object field to be reusable.
I can confirm this code to work for the epd13in3k model and this model alone, as it's the only one I own.
But when looking into the waveshare epd drivers, the relevant piece of code is present for every model.