From 5295692da9b2267f2f0556c9c447ec3ab83c4803 Mon Sep 17 00:00:00 2001 From: jayofelony Date: Sat, 15 Jun 2024 19:58:54 +0200 Subject: [PATCH] Added display inky phat v2 Signed-off-by: jayofelony --- pwnagotchi/ui/display.py | 3 + pwnagotchi/ui/hw/__init__.py | 4 ++ pwnagotchi/ui/hw/inkyv2.py | 56 +++++++++++++++ .../ui/hw/libs/pimoroni/inkyphatv2/inkyv2.py | 72 +++++++++++++++++++ pwnagotchi/utils.py | 3 + 5 files changed, 138 insertions(+) create mode 100644 pwnagotchi/ui/hw/inkyv2.py create mode 100644 pwnagotchi/ui/hw/libs/pimoroni/inkyphatv2/inkyv2.py diff --git a/pwnagotchi/ui/display.py b/pwnagotchi/ui/display.py index 28364f30..c64adcb9 100644 --- a/pwnagotchi/ui/display.py +++ b/pwnagotchi/ui/display.py @@ -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' diff --git a/pwnagotchi/ui/hw/__init__.py b/pwnagotchi/ui/hw/__init__.py index f966af6e..e7699c77 100644 --- a/pwnagotchi/ui/hw/__init__.py +++ b/pwnagotchi/ui/hw/__init__.py @@ -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) diff --git a/pwnagotchi/ui/hw/inkyv2.py b/pwnagotchi/ui/hw/inkyv2.py new file mode 100644 index 00000000..a037f224 --- /dev/null +++ b/pwnagotchi/ui/hw/inkyv2.py @@ -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() diff --git a/pwnagotchi/ui/hw/libs/pimoroni/inkyphatv2/inkyv2.py b/pwnagotchi/ui/hw/libs/pimoroni/inkyphatv2/inkyv2.py new file mode 100644 index 00000000..daf1b4d7 --- /dev/null +++ b/pwnagotchi/ui/hw/libs/pimoroni/inkyphatv2/inkyv2.py @@ -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) \ No newline at end of file diff --git a/pwnagotchi/utils.py b/pwnagotchi/utils.py index e17309b9..a8b4f72c 100644 --- a/pwnagotchi/utils.py +++ b/pwnagotchi/utils.py @@ -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'