Skip to content

Commit

Permalink
add support for controlling display brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
klamann committed Sep 23, 2024
1 parent a227c48 commit fe4785c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/raspi_poe_mon/ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ def __init__(
fan_on_temp=60.0,
fan_off_temp=50.0,
frame_time=2.0,
brightness=100,
dry_run=False,
profiling=False,
):
self.fan_on_temp = fan_on_temp
self.fan_off_temp = fan_off_temp
self.frame_time = frame_time
self.profiling = profiling
self.poe_hat = PoeHat(dry_run=dry_run)
self.poe_hat = PoeHat(dry_run=dry_run, brightness=brightness)
self.display = IpDisplay(self.poe_hat)
self._frame_counter = 0
self._terminate = False
Expand Down
5 changes: 5 additions & 0 deletions src/raspi_poe_mon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def run(
float,
typer.Option(help="update the display every n seconds")
] = 2.0,
brightness: Annotated[
int,
typer.Option(min=0, max=100, help="brightness level of the display in percent")
] = 50,
verbose: Annotated[
bool,
typer.Option(help="log detailed status information")
Expand All @@ -88,6 +92,7 @@ def run(
fan_on_temp=fan_on_temp,
fan_off_temp=fan_off_temp,
frame_time=frame_time,
brightness=brightness,
dry_run=dry,
profiling=profiling,
)
Expand Down
4 changes: 3 additions & 1 deletion src/raspi_poe_mon/poe_hat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

class PoeHat:

def __init__(self, dry_run=False) -> None:
def __init__(self, dry_run=False, brightness=100) -> None:
self.dry_run = dry_run
self.brightness = brightness
self.i2c_fan: Optional[serial.i2c] = None
self.i2c_display: Optional[serial.i2c] = None
self.display: Optional[device.ssd1306] = None
Expand All @@ -29,6 +30,7 @@ def display_connect(self, force=False):
self.i2c_display = serial.i2c(port=1, address=0x3C)
if force or self.display is None:
self.display = device.ssd1306(serial_interface=self.i2c_display, width=128, height=32)
self.display.contrast(int(255 * self.brightness / 100))

def display_clear(self):
self.display_connect()
Expand Down

0 comments on commit fe4785c

Please sign in to comment.