78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
import busio
|
|
import terminalio
|
|
import displayio
|
|
import adafruit_displayio_ssd1306
|
|
import time
|
|
from adafruit_display_text import label
|
|
from kmk.modules import Module
|
|
|
|
|
|
|
|
class Oled(Module):
|
|
def __init__(self):
|
|
self.pins = None
|
|
self.label = label.Label(font=terminalio.FONT, text="", color = 0xFFFFFF)
|
|
displayio.release_displays()
|
|
self.lock_values = ['x', 'x', 'x']
|
|
self.old_locks_values = None
|
|
self.locks = None
|
|
self.layer_labels = {
|
|
0: "Def",
|
|
1: "RGB"
|
|
}
|
|
self.refresh_rate = 0.2
|
|
self.last_update = time.monotonic()
|
|
|
|
|
|
|
|
def _init_oled(self, pins):
|
|
self.bus = None
|
|
self._I2C = busio.I2C(scl=pins[0], sda=pins[1])
|
|
self.display_bus = displayio.I2CDisplay(i2c_bus=self._I2C, device_address=60)
|
|
self.display = adafruit_displayio_ssd1306.SSD1306(self.display_bus, width=128, height=32)
|
|
self.label.text = "INIT"
|
|
self.label.x = 1
|
|
self.label.y = 5
|
|
self.display.rotation = 90
|
|
self.display.show(self.label)
|
|
|
|
def _update_locks(self):
|
|
self.lock_values[0] = 'N' if self.locks.get_num_lock() else 'n'
|
|
self.lock_values[1] = 'C' if self.locks.get_caps_lock() else 'c'
|
|
self.lock_values[2] = 'S' if self.locks.get_scroll_lock() else 's'
|
|
|
|
def write_text(self, text, label):
|
|
pass
|
|
|
|
def during_bootup(self, keyboard):
|
|
self._init_oled(self.pins)
|
|
return
|
|
|
|
def after_hid_send(self, keyboard):
|
|
t = time.monotonic()
|
|
if self.last_update + self.refresh_rate < t:
|
|
self._update_locks()
|
|
self.label.text = f"{self.lock_values[0]}|{self.lock_values[1]}|{self.lock_values[2]}\n{self.layer_labels[keyboard.sandbox.active_layers[0]]}"
|
|
self.last_update = t
|
|
# if self.lock_values != self.old_locks_values:
|
|
# self.label.text = f"{self.lock_values[0]} {self.lock_values[1]} {self.lock_values[2]}\n{self.layer_labels[keyboard.sandbox.active_layers[0]]}"
|
|
# self.old_locks_values = self.lock_values
|
|
return
|
|
|
|
def before_hid_send(self, keyboard):
|
|
return
|
|
|
|
def before_matrix_scan(self, keyboard):
|
|
|
|
return
|
|
|
|
def after_matrix_scan(self, keyboard):
|
|
return
|
|
|
|
def on_powersave_enable(self, keyboard):
|
|
self.display.sleep()
|
|
return super()
|
|
|
|
def on_powersave_disable(self, keyboard):
|
|
self.display.wake()
|
|
return |