From 79ba5102d7b39456593830508e7645f10424c77e Mon Sep 17 00:00:00 2001 From: Simone Margaritelli <evilsocket@gmail.com> Date: Sat, 12 Oct 2019 17:47:51 +0200 Subject: [PATCH] fix: cosmetic fixes for inky displays --- pwnagotchi/plugins/default/grid.py | 9 ++++++--- pwnagotchi/ui/display.py | 32 +++++++++++++++--------------- pwnagotchi/ui/view.py | 11 +++++----- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/pwnagotchi/plugins/default/grid.py b/pwnagotchi/plugins/default/grid.py index 1236181..a1ecd22 100644 --- a/pwnagotchi/plugins/default/grid.py +++ b/pwnagotchi/plugins/default/grid.py @@ -128,11 +128,14 @@ def grid_inbox(): def on_ui_update(ui): new_value = ' %d (%d)' % (UNREAD_MESSAGES, TOTAL_MESSAGES) - if not ui.has_element('mailbox'): - logging.debug("add mailbox") + if not ui.has_element('mailbox') and TOTAL_MESSAGES > 0: + if ui.is_inky(): + pos=(80, 0) + else: + pos=(100,0) ui.add_element('mailbox', LabeledValue(color=BLACK, label='MSG', value=new_value, - position=(100, 0), + position=pos, label_font=fonts.Bold, text_font=fonts.Medium)) ui.set('mailbox', new_value) diff --git a/pwnagotchi/ui/display.py b/pwnagotchi/ui/display.py index 232ff7e..ff7ee5e 100644 --- a/pwnagotchi/ui/display.py +++ b/pwnagotchi/ui/display.py @@ -118,30 +118,30 @@ class Display(View): else: logging.info("could not get ip of usb0, video server not starting") - def _is_inky(self): + def is_inky(self): return self._display_type in ('inkyphat', 'inky') - def _is_papirus(self): + def is_papirus(self): return self._display_type in ('papirus', 'papi') - def _is_waveshare_v1(self): + def is_waveshare_v1(self): return self._display_type in ('waveshare_1', 'ws_1', 'waveshare1', 'ws1') - def _is_waveshare_v2(self): + def is_waveshare_v2(self): return self._display_type in ('waveshare_2', 'ws_2', 'waveshare2', 'ws2') - def _is_waveshare(self): - return self._is_waveshare_v1() or self._is_waveshare_v2() + def is_waveshare_any(self): + return self.is_waveshare_v1() or self.is_waveshare_v2() def _init_display(self): - if self._is_inky(): + if self.is_inky(): logging.info("initializing inky display") from inky import InkyPHAT self._display = InkyPHAT(self._display_color) self._display.set_border(InkyPHAT.BLACK) self._render_cb = self._inky_render - elif self._is_papirus(): + elif self.is_papirus(): logging.info("initializing papirus display") from pwnagotchi.ui.papirus.epd import EPD os.environ['EPD_SIZE'] = '2.0' @@ -149,7 +149,7 @@ class Display(View): self._display.clear() self._render_cb = self._papirus_render - elif self._is_waveshare_v1(): + elif self.is_waveshare_v1(): if self._display_color == 'black': logging.info("initializing waveshare v1 display in monochromatic mode") from pwnagotchi.ui.waveshare.v1.epd2in13 import EPD @@ -167,7 +167,7 @@ class Display(View): self._display.Clear() self._render_cb = self._waveshare_bc_render - elif self._is_waveshare_v2(): + elif self.is_waveshare_v2(): logging.info("initializing waveshare v2 display") from pwnagotchi.ui.waveshare.v2.waveshare import EPD self._display = EPD() @@ -186,11 +186,11 @@ class Display(View): def clear(self): if self._display is None: logging.error("no display object created") - elif self._is_inky(): + elif self.is_inky(): self._display.Clear() - elif self._is_papirus(): + elif self.is_papirus(): self._display.clear() - elif self._is_waveshare(): + elif self.is_waveshare_any(): self._display.Clear(WHITE) else: logging.critical("unknown display type %s" % self._display_type) @@ -224,7 +224,7 @@ class Display(View): try: self._display.show() except: - print("") + logging.exception("error while rendering on inky") def _papirus_render(self): self._display.display(self._canvas) @@ -232,9 +232,9 @@ class Display(View): def _waveshare_render(self): buf = self._display.getbuffer(self._canvas) - if self._is_waveshare_v1(): + if self.is_waveshare_v1(): self._display.display(buf) - elif self._is_waveshare_v2(): + elif self.is_waveshare_v2(): self._display.displayPartial(buf) def _waveshare_bc_render(self): diff --git a/pwnagotchi/ui/view.py b/pwnagotchi/ui/view.py index 6f92d07..faa3f71 100644 --- a/pwnagotchi/ui/view.py +++ b/pwnagotchi/ui/view.py @@ -2,7 +2,7 @@ import _thread from threading import Lock import time import logging -from PIL import Image, ImageDraw +from PIL import ImageDraw import pwnagotchi.utils as utils import pwnagotchi.plugins as plugins @@ -17,6 +17,7 @@ WHITE = 0xff BLACK = 0x00 ROOT = None + def setup_display_specifics(config): width = 0 height = 0 @@ -25,13 +26,13 @@ def setup_display_specifics(config): status_pos = (0, 0) if config['ui']['display']['type'] in ('inky', 'inkyphat'): - fonts.setup(10, 8, 10, 25) + fonts.setup(10, 8, 10, 28) width = 212 height = 104 - face_pos = (0, int(height / 4)) - name_pos = (5, int(height * .15)) - status_pos = (int(width / 2) - 15, int(height * .15)) + face_pos = (0, 37) + name_pos = (5, 18) + status_pos = (102, 18) elif config['ui']['display']['type'] in ('papirus', 'papi'): fonts.setup(10, 8, 10, 23)