Skip to content

Commit

Permalink
Starting to work on better brigthness control
Browse files Browse the repository at this point in the history
  • Loading branch information
brickbots committed Feb 2, 2025
1 parent bec012a commit d4df6e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
28 changes: 26 additions & 2 deletions python/PiFinder/displays.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import namedtuple

import numpy as np
from PIL import Image
from PIL import Image, ImageChops

import luma.core.device
from luma.core.interface.serial import spi
Expand Down Expand Up @@ -41,6 +41,7 @@ class DisplayBase:
large_font_size = 15
huge_font_size = 35
device = luma.core.device.device
brightness = 255

def __init__(self):
self.colors = Colors(self.color_mask, self.resolution)
Expand All @@ -64,6 +65,9 @@ def __init__(self):
def set_brightness(self, brightness: int) -> None:
return None

def write_to_screen(self, image_to_display: Image.Image) -> None:
self.device.display(image_to_display.convert(self.device.mode))


class DisplayPygame_128(DisplayBase):
resolution = (128, 128)
Expand Down Expand Up @@ -115,14 +119,34 @@ def __init__(self):
width=self.resolution[0], height=self.resolution[1], rotate=0, mode="RGB"
)
self.device = device_serial
self.brightness_mult_image = Image.new(
"RGB",
(self.resolution[0], self.resolution[1]),
(self.brightness, self.brightness, self.brightness),
)

super().__init__()

def set_brightness(self, level):
"""
Sets oled brightness
0-255
"""
self.device.contrast(level)
self.brightness = level
#self.device.contrast(int(level/2))
self.device.contrast(255)
self.brightness_mult_image = Image.new(
"RGB",
(self.resolution[0], self.resolution[1]),
(self.brightness, self.brightness, self.brightness),
)
print("bb: " + str(level))

def write_to_screen(self, image_to_display: Image.Image) -> None:
image_to_display = ImageChops.multiply(
image_to_display.convert("RGB"), self.brightness_mult_image
)
super().write_to_screen(image_to_display)


class DisplayST7789_128(DisplayBase):
Expand Down
7 changes: 4 additions & 3 deletions python/PiFinder/ui/menu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,12 @@ def update_screen(self, screen_image: Image.Image) -> None:
if time.time() < self.ui_state.message_timeout():
return None

screen_to_display = screen_image.convert(self.display_class.device.mode)
self.display_class.device.display(screen_to_display)
# screen_to_display = screen_image.convert(self.display_class.device.mode)
# self.display_class.device.display(screen_to_display)
self.display_class.write_to_screen(screen_image)

if self.shared_state:
self.shared_state.set_screen(screen_to_display)
self.shared_state.set_screen(screen_image)

def key_number(self, number):
if self.help_images is not None:
Expand Down

0 comments on commit d4df6e3

Please sign in to comment.