Add side-dependent options

This commit is contained in:
regicidal.plutophage 2023-03-04 22:01:57 +00:00
parent 95e028d9dd
commit fbb0b23e3f

View File

@ -37,23 +37,24 @@ class OledData:
line_spacing=0.75, line_spacing=0.75,
inverted=False, inverted=False,
layer=None, layer=None,
side=None,
): ):
_x = 0 _x = 0
_x_anchor = 0.0 _x_anchor = 0.0
_y_anchor = 0.0 _y_anchor = 0.0
if x_anchor == 'left' or x_anchor == 'l': if x_anchor == 'left' or x_anchor == 'L':
_x_anchor = 0.0 _x_anchor = 0.0
elif x_anchor == 'middle' or x_anchor == 'm': elif x_anchor == 'middle' or x_anchor == 'M':
_x_anchor = 0.5 _x_anchor = 0.5
elif x_anchor == 'right' or x_anchor == 'r': elif x_anchor == 'right' or x_anchor == 'R':
_x_anchor = 1.0 _x_anchor = 1.0
else: else:
_x_anchor = 0.0 _x_anchor = 0.0
if y_anchor == 'top' or y_anchor == 't': if y_anchor == 'top' or y_anchor == 'T':
_y_anchor = 0.0 _y_anchor = 0.0
elif y_anchor == 'middle' or y_anchor == 'm': elif y_anchor == 'middle' or y_anchor == 'M':
_y_anchor = 0.5 _y_anchor = 0.5
elif y_anchor == 'bottom' or y_anchor == 'b': elif y_anchor == 'bottom' or y_anchor == 'B':
_y_anchor = 1.0 _y_anchor = 1.0
else: else:
_y_anchor = 0.0 _y_anchor = 0.0
@ -70,24 +71,26 @@ class OledData:
0: text, 0: text,
1: _x, 1: _x,
2: y, 2: y,
3: layer, 3: side,
4: OledEntryType.TXT, 4: layer,
5: _x_anchor, 5: OledEntryType.TXT,
6: _y_anchor, 6: _x_anchor,
7: direction, 7: _y_anchor,
8: line_spacing, 8: direction,
9: inverted, 9: line_spacing,
10: inverted,
} }
@staticmethod @staticmethod
def oled_image_entry(x=0, y=0, image='', layer=None): def oled_image_entry(x=0, y=0, image='', layer=None, side=None):
odb = displayio.OnDiskBitmap(image) odb = displayio.OnDiskBitmap(image)
return { return {
0: odb, 0: odb,
1: x, 1: x,
2: y, 2: y,
3: layer, 3: side,
4: OledEntryType.IMG, 4: layer,
5: OledEntryType.IMG,
} }
@ -97,7 +100,10 @@ class Oled(Extension):
views, views,
width=128, width=128,
height=32, height=32,
split=None,
flip: bool = False, flip: bool = False,
flip_left: bool = False,
flip_right: bool = False,
device_address=0x3C, device_address=0x3C,
brightness=0.8, brightness=0.8,
brightness_step=0.1, brightness_step=0.1,
@ -107,7 +113,9 @@ class Oled(Extension):
powersave_off_time=60, powersave_off_time=60,
): ):
displayio.release_displays() displayio.release_displays()
self.rotation = 180 if flip else 0 self._flip = flip
self._flip_left = flip_left
self._flip_right = flip_right
self._views = views.data self._views = views.data
self._width = width self._width = width
self._height = height self._height = height
@ -127,7 +135,7 @@ class Oled(Extension):
self._powersave_off_time_ms = ( self._powersave_off_time_ms = (
powersave_off_time * 1000 if powersave_off_time else None powersave_off_time * 1000 if powersave_off_time else None
) )
gc.collect() self._split = split
make_key( make_key(
names=('OLED_BRI',), on_press=self._oled_bri, on_release=handler_passthrough names=('OLED_BRI',), on_press=self._oled_bri, on_release=handler_passthrough
@ -141,30 +149,33 @@ class Oled(Extension):
for view in self._views: for view in self._views:
if self._dark is False: if self._dark is False:
if view[3] == layer or view[3] is None: if view[3] == self.split_side or view[3] is None:
if view[4] == OledEntryType.TXT: if view[4] == layer or view[4] is None:
splash.append( if view[5] == OledEntryType.TXT:
label.Label( splash.append(
terminalio.FONT, label.Label(
text=view[0], terminalio.FONT,
color=0xFFFFFF if not view[9] else 0x000000, text=view[0],
background_color=0x000000 if not view[9] else 0xFFFFFF, color=0xFFFFFF if not view[10] else 0x000000,
anchor_point=(view[5], view[6]), background_color=0x000000
anchored_position=(view[1], view[2]), if not view[10]
label_direction=view[7], else 0xFFFFFF,
line_spacing=view[8], anchor_point=(view[6], view[7]),
padding_left=1, anchored_position=(view[1], view[2]),
label_direction=view[8],
line_spacing=view[9],
padding_left=1,
)
) )
) elif view[5] == OledEntryType.IMG:
elif view[4] == OledEntryType.IMG: splash.append(
splash.append( displayio.TileGrid(
displayio.TileGrid( view[0],
view[0], pixel_shader=view[0].pixel_shader,
pixel_shader=view[0].pixel_shader, x=view[1],
x=view[1], y=view[2],
y=view[2], )
) )
)
gc.collect() gc.collect()
self._display.show(splash) self._display.show(splash)
@ -179,16 +190,25 @@ class Oled(Extension):
return return
def during_bootup(self, keyboard): def during_bootup(self, keyboard):
if self._split.split_side == 1:
self.split_side = 'L'
self._flip = self._flip_left
elif self._split.split_side == 2:
self.split_side = 'R'
self._flip = self._flip_right
else:
self.split_side = None
displayio.release_displays() displayio.release_displays()
i2c = busio.I2C(keyboard.SCL, keyboard.SDA) i2c = busio.I2C(keyboard.SCL, keyboard.SDA)
self._display = adafruit_displayio_ssd1306.SSD1306( self._display = adafruit_displayio_ssd1306.SSD1306(
displayio.I2CDisplay(i2c, device_address=self._device_address), displayio.I2CDisplay(i2c, device_address=self._device_address),
width=self._width, width=self._width,
height=self._height, height=self._height,
rotation=self.rotation, rotation=180 if self._flip else 0,
brightness=self._brightness, brightness=self._brightness,
) )
self.render_oled(0) self.render_oled(0)
print(self.split_side)
return return
def before_matrix_scan(self, sandbox): def before_matrix_scan(self, sandbox):