diff options
Diffstat (limited to 'oled.py')
-rw-r--r-- | oled.py | 69 |
1 files changed, 69 insertions, 0 deletions
@@ -0,0 +1,69 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import board +import busio + +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. + """ + + def __init__(self, keyboard, *args, **kwargs): + super().__init__(*args, **kwargs) + self._text = None + self.keyboard = keyboard + + @property + def text(self): + try: + return self.keyboard.keymap[0].name + except: + return self._text + + @text.setter + def text(self, value): + self._text = value + + +class CustomDisplay(Display): + """ Create a custom Display object which refresh the display everytime the + layout is updated + """ + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._prevLayers = None + + def during_bootup(self, keyboard): + super().during_bootup(keyboard) + self.keyboard = keyboard + + def before_matrix_scan(self, sandbox): + """ Override the default function with the layer name as a comparaison + key + """ + super().before_matrix_scan(sandbox) + if self.keyboard.keymap[0].name != self._prevLayers: + self.timer_start = ticks_ms() + self._prevLayers = self.keyboard.keymap[0].name + self.render(sandbox.active_layers[0]) + return + + + +def main(keyboard): + + driver = SSD1306( + i2c=busio.I2C(board.SCL, board.SDA), + ) + + display = CustomDisplay( + display=driver, + ) + display.entries = [ + NamedLayer(keyboard, text="", x=0, y=0), + ] + keyboard.extensions.append(display) |