diff --git a/sdcard/rootfs/root/pwnagotchi/config.yml b/sdcard/rootfs/root/pwnagotchi/config.yml index 7ff7ba4..e151e63 100644 --- a/sdcard/rootfs/root/pwnagotchi/config.yml +++ b/sdcard/rootfs/root/pwnagotchi/config.yml @@ -93,7 +93,7 @@ ui: enabled: true rotation: 180 # Possible options inkyphat/inky or waveshare/ws - type: 'ws' + type: 'waveshare' # Possible options red/yellow/black (black used for monocromatic displays) color: 'black' video: diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/display.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/display.py index a3adb1b..6d821a7 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/display.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/display.py @@ -79,6 +79,7 @@ class Display(View): self._video_address = config['ui']['display']['video']['address'] self._display_type = config['ui']['display']['type'] self._display_color = config['ui']['display']['color'] + self._render_cb = None self._display = None self._httpd = None self.canvas = None @@ -100,18 +101,26 @@ class Display(View): else: core.log("could not get ip of usb0, video server not starting") + def _is_inky(self): + return self._display_type in ('inkyphat', 'inky') + + def _is_waveshare(self): + return self._display_type in ('waveshare', 'ws') + def _init_display(self): - if self._display_type in ('inkyphat', 'inky'): + if self._is_inky(): from inky import InkyPHAT self._display = InkyPHAT(self._display_color) self._display.set_border(InkyPHAT.BLACK) - elif self._display_type in ('waveshare', 'ws'): + self._render_cb = self._inky_render + elif self._is_waveshare(): from pwnagotchi.ui.waveshare import EPD # core.log("display module started") self._display = EPD() self._display.init(self._display.FULL_UPDATE) self._display.Clear(WHITE) self._display.init(self._display.PART_UPDATE) + self._render_cb = self._waveshare_render else: core.log("unknown display type %s" % self._display_type) @@ -125,40 +134,44 @@ class Display(View): img = self.canvas if self._rotation == 0 else self.canvas.rotate(-self._rotation) return img + def _inky_render(self): + if self._display_color != 'mono': + display_colors = 3 + else: + display_colors = 2 + + imgbuf = self.canvas.convert('RGB').convert('P', palette=1, colors=display_colors) + + if self._display_color == 'red': + imgbuf.putpalette([ + 255, 255, 255, # index 0 is white + 0, 0, 0, # index 1 is black + 255, 0, 0 # index 2 is red + ]) + elif self._display_color == 'yellow': + imgbuf.putpalette([ + 255, 255, 255, # index 0 is white + 0, 0, 0, # index 1 is black + 255, 255, 0 # index 2 is yellow + ]) + else: + imgbuf.putpalette([ + 255, 255, 255, # index 0 is white + 0, 0, 0 # index 1 is black + ]) + + self._display.set_image(imgbuf) + self._display.show() + + def _waveshare_render(self): + buf = self._display.getbuffer(self.canvas) + self._display.displayPartial(buf) + def _on_view_rendered(self, img): # core.log("display::_on_view_rendered") VideoHandler.render(img) if self._enabled: self.canvas = img if self._rotation == 0 else img.rotate(self._rotation) - if self._display_type == 'inkyphat': - if self._display_color != 'mono': - display_colors = 3 - else: - display_colors = 2 - - imgbuf = self.canvas.convert('RGB').convert('P', palette=1, colors=display_colors) - - if self._display_color == 'red': - imgbuf.putpalette([ - 255, 255, 255, # index 0 is white - 0, 0, 0, # index 1 is black - 255, 0, 0 # index 2 is red - ]) - elif self._display_color == 'yellow': - imgbuf.putpalette([ - 255, 255, 255, # index 0 is white - 0, 0, 0, # index 1 is black - 255, 255, 0 #index 2 is yellow - ]) - else: - imgbuf.putpalette([ - 255, 255, 255, # index 0 is white - 0, 0, 0 # index 1 is black - ]) - - self._display.set_image(imgbuf) - self._display.show() - else: - buf = self._display.getbuffer(self.canvas) - self._display.displayPartial(buf) + if self._render_cb is not None: + self._render_cb() diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/view.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/view.py index 9b92219..1c49562 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/view.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/view.py @@ -15,6 +15,34 @@ from pwnagotchi.ui.state import State WHITE = 0xff BLACK = 0x00 + +def setup_display_specifics(config): + width = 0 + height = 0 + face_pos = (0, 0) + name_pos = (0, 0) + status_pos = (0, 0) + + if config['ui']['display']['type'] in ('inky', 'inkyphat'): + fonts.setup(10, 8, 10, 25) + + width = 212 + height = 104 + face_pos = (0, int(height / 4)) + name_pos = (int(width / 2) - 15, int(height * .15)) + status_pos = (int(width / 2) - 15, int(height * .30)) + elif config['ui']['display']['type'] in ('ws', 'waveshare'): + fonts.setup(10, 9, 10, 35) + + width = 250 + height = 122 + face_pos = (0, 40) + name_pos = (125, 20) + status_pos = (125, 35) + + return width, height, face_pos, name_pos, status_pos + + class View(object): def __init__(self, config, state={}): self._render_cbs = [] @@ -22,24 +50,8 @@ class View(object): self._canvas = None self._lock = Lock() - if config['ui']['display']['type'] in ('inky', 'inkyphat'): - self._width = 212 - self._height = 104 - - fonts.setup(10, 8, 10, 25) - - face_pos = (0, int(self._height / 4)) - name_pos = (int(self._width / 2) - 15, int(self._height * .15)) - status_pos = (int(self._width /2) - 15, int(self._height * .30)) - elif config['ui']['display']['type'] in ('ws', 'waveshare'): - self._width = 250 - self._height = 122 - - fonts.setup(10, 9, 10, 35) - - face_pos = (0, 40) - name_pos = (125, 20) - status_pos = (125, 35) + self._width, self._height, \ + face_pos, name_pos, status_pos = setup_display_specifics(config) self._state = State(state={ 'channel': LabeledValue(color=BLACK, label='CH', value='00', position=(0, 0), label_font=fonts.Bold, @@ -47,15 +59,18 @@ class View(object): 'aps': LabeledValue(color=BLACK, label='APS', value='0 (00)', position=(30, 0), label_font=fonts.Bold, text_font=fonts.Medium), - #'epoch': LabeledValue(color=BLACK, label='E', value='0000', position=(145, 0), label_font=fonts.Bold, + # 'epoch': LabeledValue(color=BLACK, label='E', value='0000', position=(145, 0), label_font=fonts.Bold, # text_font=fonts.Medium), - 'uptime': LabeledValue(color=BLACK, label='UP', value='00:00:00', position=(self._width - 65, 0), label_font=fonts.Bold, + 'uptime': LabeledValue(color=BLACK, label='UP', value='00:00:00', position=(self._width - 65, 0), + label_font=fonts.Bold, text_font=fonts.Medium), # 'square': Rect([1, 11, 124, 111]), 'line1': Line([0, int(self._height * .12), self._width, int(self._height * .12)], color=BLACK), - 'line2': Line([0, self._height - int(self._height * .12), self._width, self._height - int(self._height * .12)], color=BLACK), + 'line2': Line( + [0, self._height - int(self._height * .12), self._width, self._height - int(self._height * .12)], + color=BLACK), # 'histogram': Histogram([4, 94], color = BLACK), @@ -68,9 +83,11 @@ class View(object): # 'face2': Bitmap( '/root/pwnagotchi/data/images/face_happy.bmp', (0, 20)), 'status': Text(value=voice.default(), position=status_pos, color=BLACK, font=fonts.Medium), - 'shakes': LabeledValue(label='PWND ', value='0 (00)', color=BLACK, position=(0, self._height - int(self._height * .12) + 1), label_font=fonts.Bold, + 'shakes': LabeledValue(label='PWND ', value='0 (00)', color=BLACK, + position=(0, self._height - int(self._height * .12) + 1), label_font=fonts.Bold, text_font=fonts.Medium), - 'mode': Text(value='AUTO', position=(self._width - 25, self._height - int(self._height * .12) + 1), font=fonts.Bold, color=BLACK), + 'mode': Text(value='AUTO', position=(self._width - 25, self._height - int(self._height * .12) + 1), + font=fonts.Bold, color=BLACK), }) for key, value in state.items():