diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-10-16 14:05:33 +0200 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-10-16 14:05:33 +0200 |
| commit | bcde30ff9e322278ebeb316bfa34af0328680bcf (patch) | |
| tree | e5b3192461f64fb998173feaf2511f3ae0c37fb0 /oled.py | |
| parent | f421547316803b545c678a8610954b1b14339b9d (diff) | |
pylint review + ergol key mappingmain
Diffstat (limited to 'oled.py')
| -rw-r--r-- | oled.py | 46 |
1 files changed, 42 insertions, 4 deletions
@@ -4,12 +4,14 @@ import board import busio +from kmk.extensions.lock_status import LockStatus from kmk.extensions.display import Display, TextEntry, ImageEntry from kmk.extensions.display.ssd1306 import SSD1306 -from supervisor import ticks_ms + class NamedLayer(TextEntry): - """ This is a named layer which return the name of the current mappng as text. + """ This is a named layer which return the name of the current mappng as + text. """ def __init__(self, keyboard, *args, **kwargs): @@ -21,7 +23,7 @@ class NamedLayer(TextEntry): def text(self): try: return self.keyboard.keymap[0].name - except: + except _: return self._text @text.setter @@ -29,6 +31,31 @@ class NamedLayer(TextEntry): self._text = value +class StatusLayer(TextEntry): + """ This layer display a status + """ + + def __init__(self, text, display, prop, *args, **kwargs): + super().__init__(*args, **kwargs) + self._text = text + self.display = display + self.property = prop + + @property + def text(self): + """ Return the name of the given property + """ + if getattr(self.display, self.property): + return "" + return f"{self._text}:Off" + + @text.setter + def text(self, value): + """ Ignore the text given + """ + pass + + class CustomDisplay(Display): """ Create a custom Display object which refresh the display everytime the layout is updated @@ -36,12 +63,22 @@ class CustomDisplay(Display): def __init__(self, *args, **kwargs): self.keyboard = None super().__init__(*args, **kwargs) + self.status = LockStatus() self._prevLayers = None + self.numlock = False + def during_bootup(self, keyboard): super().during_bootup(keyboard) + self.status.during_bootup(keyboard) self.keyboard = keyboard + def after_hid_send(self, sandbox): + self.status.after_hid_send(sandbox) + if self.status.report_updated: + self.numlock = self.status.get_num_lock() + self.render(sandbox.active_layers[0]) + def before_matrix_scan(self, sandbox): """ Override the default function with the layer name as a comparaison key @@ -50,7 +87,6 @@ class CustomDisplay(Display): if self.keyboard.keymap[0].name != self._prevLayers: self._prevLayers = self.keyboard.keymap[0].name self.render(sandbox.active_layers[0]) - return @property def timer_start(self): @@ -62,6 +98,7 @@ class CustomDisplay(Display): if self.keyboard: self.keyboard.keymap[0].timer_start = value + def main(keyboard): driver = SSD1306( @@ -73,5 +110,6 @@ def main(keyboard): ) display.entries = [ NamedLayer(keyboard, text="", x=0, y=0), + StatusLayer(text="Num", display=display, prop="numlock", x=0, y=20), ] keyboard.extensions.append(display) |
