Added display inky phat v2

Signed-off-by: jayofelony <oudshoorn.jeroen@gmail.com>
This commit is contained in:
jayofelony
2024-06-15 19:58:54 +02:00
parent 81c3581138
commit 5295692da9
5 changed files with 138 additions and 0 deletions

View File

@ -235,6 +235,9 @@ class Display(View):
def is_inky(self):
return self._implementation.name == 'inky'
def is_inkyv2(self):
return self._implementation.name == 'inkyv2'
def is_dummy_display(self):
return self._implementation.name == 'dummydisplay'

View File

@ -4,6 +4,10 @@ def display_for(config):
from pwnagotchi.ui.hw.inky import Inky
return Inky(config)
elif config['ui']['display']['type'] == 'inkyv2':
from pwnagotchi.ui.hw.inkyv2 import InkyV2
return InkyV2(config)
elif config['ui']['display']['type'] == 'wavesharelcd0in96':
from pwnagotchi.ui.hw.wavesharelcd0in96 import Wavesharelcd0in96
return Wavesharelcd0in96(config)

View File

@ -0,0 +1,56 @@
import logging
import pwnagotchi.ui.fonts as fonts
from pwnagotchi.ui.hw.base import DisplayImpl
class InkyV2(DisplayImpl):
def __init__(self, config):
super(InkyV2, self).__init__(config, 'inkyv2')
def layout(self):
fonts.setup(10, 8, 10, 28, 25, 9)
self._layout['width'] = 212
self._layout['height'] = 104
self._layout['face'] = (0, 37)
self._layout['name'] = (5, 18)
self._layout['channel'] = (0, 0)
self._layout['aps'] = (30, 0)
self._layout['uptime'] = (147, 0)
self._layout['line1'] = [0, 12, 212, 12]
self._layout['line2'] = [0, 92, 212, 92]
self._layout['friend_face'] = (0, 76)
self._layout['friend_name'] = (40, 78)
self._layout['shakes'] = (0, 93)
self._layout['mode'] = (187, 93)
self._layout['status'] = {
'pos': (102, 18),
'font': fonts.status_font(fonts.Small),
'max': 20
}
return self._layout
def initialize(self):
logging.info("initializing inky v2 display")
from pwnagotchi.ui.hw.libs.pimoroni.inkyphatv2.inkyv2 import InkyPHAT
self._display = InkyPHAT()
self._display.set_border(InkyPHAT.BLACK)
def render(self, canvas):
display_colors = 2
img_buffer = canvas.convert('RGB').convert('P', palette=1, colors=display_colors)
img_buffer.putpalette([
255, 255, 255, # index 0 is white
0, 0, 0 # index 1 is black
])
self._display.set_image(img_buffer)
try:
self._display.show()
except:
logging.exception("error while rendering on inky v2")
def clear(self):
self._display.Clear()

View File

@ -0,0 +1,72 @@
"""
`Inky pHAT`_ class and methods.
A getting started `tutorial`_ for the Inky pHAT is available on the pimoroni website.
The `pinout`_ for the Inky pHAT is documented on pinout.xyz
.. _`Inky pHAT`: https://shop.pimoroni.com/products/inky-phat
.. _`tutorial`: https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-inky-phat
.. _`pinout`: https://pinout.xyz/pinout/inky_phat
"""
from libs.pimoroni.inkyphatv2 import inky, inky_ssd1608
class InkyPHAT_SSD1608(inky_ssd1608.Inky):
"""Inky pHAT V2 (250x122 pixel) e-Ink Display Driver."""
WIDTH = 250
HEIGHT = 122
WHITE = 0
BLACK = 1
RED = 2
YELLOW = 2
def __init__(self, colour):
"""Initialise an Inky pHAT Display.
:param colour: one of red, black or yellow, default: black
"""
inky_ssd1608.Inky.__init__(
self,
resolution=(self.WIDTH, self.HEIGHT),
colour=colour,
h_flip=False,
v_flip=False)
class InkyPHAT(inky.Inky):
"""Inky pHAT e-Ink Display Driver.
:Example: ::
>>> from inky import InkyPHAT
>>> display = InkyPHAT('red')
>>> display.set_border(display.BLACK)
>>> for x in range(display.WIDTH):
>>> for y in range(display.HEIGHT):
>>> display.set_pixel(x, y, display.RED)
>>> display.show()
"""
WIDTH = 212
HEIGHT = 104
WHITE = 0
BLACK = 1
RED = 2
YELLOW = 2
def __init__(self, colour='black'):
"""Initialise an Inky pHAT Display.
:param str colour: one of 'red', 'black' or 'yellow', default: 'black'.
"""
inky.Inky.__init__(
self,
resolution=(self.WIDTH, self.HEIGHT),
colour=colour,
h_flip=False,
v_flip=False)

View File

@ -279,6 +279,9 @@ def load_config(args):
elif config['ui']['display']['type'] in ('inky', 'inkyphat'):
config['ui']['display']['type'] = 'inky'
elif config['ui']['display']['type'] in ('inkyv2', 'inkyphatv2'):
config['ui']['display']['type'] = 'inkyv2'
elif config['ui']['display']['type'] in ('papirus', 'papi'):
config['ui']['display']['type'] = 'papirus'