Skip to content

Update display_ssd1309_oled_128x64_i2c.py - #1538

Open
im-evo wants to merge 2 commits into
kizniche:masterfrom
im-evo:trixie-oled-fix
Open

Update display_ssd1309_oled_128x64_i2c.py#1538
im-evo wants to merge 2 commits into
kizniche:masterfrom
im-evo:trixie-oled-fix

Conversation

@im-evo

@im-evo im-evo commented May 28, 2026

Copy link
Copy Markdown

Made this function usable on Trixie and the screen more readable:

  1. Updated dependencies, removed some hardcoded versions that are no longer available:
  • Pillow==8.1.2->Pillow
  • libfreetype6-dev->libfreetype-dev
  • libtiff5->libtiff6
  1. Added DejaVu as a dependency/font and set it to be displayed

im-evo added 2 commits May 27, 2026 23:21
Making this function usable on trixie and the screen more readable:
Updated dependencies, removed some hardcoded versions that are no longer available
Added DejaVu as a font and set it to be displayed.
Removed EOL symbol causing static to fail
@kizniche

Copy link
Copy Markdown
Owner

Thanks for the PR. Did you verify this still works if the font doesn't exist at the specified location?

@im-evo

im-evo commented May 28, 2026

Copy link
Copy Markdown
Author

Thanks for the PR. Did you verify this still works if the font doesn't exist at the specified location?

No, it will fail. I added the font to the list of dependencies; dpkg -L specifies that path as a standard. If they change something in the upcoming releases, it will break.

I can add some error handling around it, like:

from PIL import ImageFont

font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono/DejaVuSansMono.ttf"
font_size = 9

try:
    # Attempt to load the preferred font
    self.font = ImageFont.truetype(font_path, font_size)
except (IOError, OSError) as e:
    # Log the issue directly to the Mycodo log system
    self.logger.warning(f"Could not load custom font at {font_path} ({e}). Falling back to default font.")
    # Fallback to ensure the display still functions
    self.font = ImageFont.load_default()

LMK if this is acceptable, and I'll update the PR.

Also, libfreetype and libtiff6 are statically linked in Pillow and probably not required here so can be dropped.

@kizniche

Copy link
Copy Markdown
Owner

I think having either a try/except or os.path.isfile() check would be good, as we can't expect every system to function as we expect, so should have a safe fallback.

As for the dependencies, I can't recall why they were included, but often they're added because at some time in the past when the module was made, they may have been required to be installed.

@kizniche

Copy link
Copy Markdown
Owner

I also forgot to mention, the Pillow dependency should be pegged to a version, specifically the version all the other modules use. Otherwise, the version will be changed whenever someone installs another module with the other version of Pillow specified. This goes for any pip package that is used by more than one module.

@im-evo

im-evo commented Jun 1, 2026

Copy link
Copy Markdown
Author

Hi Kyle,
I fixed that but then I got a little carried away and tried to utilize the full size of the screen. Right now it looks like this, with configurable thresholds for "Alarm state" and "Alarm" shown when there are no measurements, i.e. sensor disconnected. They also blink on screen refresh. Units and age are also configurable and can be hidden by a checkbox flag.

Let me know if you want this in the same PR, or if I should create a separate PR or even a separate display function for this.
IMG_6161

Adobe Express - IMG_6162

@kizniche

kizniche commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Does an upgrade break functionality for current users? If so, then it would be more appropriate as a separate module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants