From 52ab525e9fc792c45919dd7f47644f46cd4398b1 Mon Sep 17 00:00:00 2001 From: Simone Margaritelli <evilsocket@gmail.com> Date: Mon, 30 Sep 2019 20:54:05 +0200 Subject: [PATCH] fixed bogus refresh policies that caused issues with waveshare displays --- sdcard/rootfs/root/pwnagotchi/config.yml | 2 - .../scripts/pwnagotchi/ui/display.py | 47 ++++++------------- .../pwnagotchi/ui/waveshare/v2/waveshare.py | 2 +- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/sdcard/rootfs/root/pwnagotchi/config.yml b/sdcard/rootfs/root/pwnagotchi/config.yml index 1fb846e..bc914a6 100644 --- a/sdcard/rootfs/root/pwnagotchi/config.yml +++ b/sdcard/rootfs/root/pwnagotchi/config.yml @@ -98,8 +98,6 @@ ui: type: 'waveshare_2' # Possible options red/yellow/black (black used for monocromatic displays) color: 'black' - # How often to do a full refresh 0 all the time, -1 never - refresh: 50 video: enabled: true address: '10.0.0.2' diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/display.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/display.py index c530caa..c9d72c4 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/display.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/display.py @@ -1,7 +1,7 @@ import _thread from threading import Lock -import io +import shutil import core import os import pwnagotchi @@ -13,7 +13,6 @@ from http.server import BaseHTTPRequestHandler, HTTPServer class VideoHandler(BaseHTTPRequestHandler): _lock = Lock() - _buffer = None _index = """<html> <head> <title>%s</title> @@ -36,36 +35,31 @@ class VideoHandler(BaseHTTPRequestHandler): @staticmethod def render(img): with VideoHandler._lock: - writer = io.BytesIO() - img.save(writer, format='PNG') - VideoHandler._buffer = writer.getvalue() + img.save("/root/pwnagotchi.png", format='PNG') def log_message(self, format, *args): return - def _w(self, data): - try: - self.wfile.write(data) - except: - pass - def do_GET(self): - if self._buffer is None: - self.send_response(404) - - elif self.path == '/': + if self.path == '/': self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() - self._w(bytes(self._index % (pwnagotchi.name(), 1000), "utf8")) + try: + self.wfile.write(bytes(self._index % (pwnagotchi.name(), 1000), "utf8")) + except: + pass elif self.path.startswith('/ui'): with self._lock: self.send_response(200) self.send_header('Content-type', 'image/png') - self.send_header('Content-length', '%d' % len(self._buffer)) self.end_headers() - self._w(self._buffer) + try: + with open("/root/pwnagotchi.png", 'rb') as fp: + shutil.copyfileobj(fp, self.wfile) + except: + pass else: self.send_response(404) @@ -80,8 +74,6 @@ 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.full_refresh_count = 0 - self.full_refresh_trigger = config['ui']['display']['refresh'] self._render_cb = None self._display = None @@ -139,7 +131,7 @@ class Display(View): self._display.Clear(0xFF) self._display.init(self._display.lut_partial_update) self._render_cb = self._waveshare_render - + elif self._is_waveshare2(): from pwnagotchi.ui.waveshare.v2.waveshare import EPD # core.log("display module started") @@ -148,7 +140,7 @@ class Display(View): 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) @@ -198,24 +190,15 @@ class Display(View): def _waveshare_render(self): buf = self._display.getbuffer(self.canvas) if self._is_waveshare1: - if self.full_refresh_trigger >= 0 and self.full_refresh_count == self.full_refresh_trigger: - self._display.Clear(0x00) self._display.display(buf) elif self._is_waveshare2: - if self.full_refresh_trigger >= 0 and self.full_refresh_count == self.full_refresh_trigger: - self._display.Clear(BLACK) self._display.displayPartial(buf) - self._display.sleep() - if self.full_refresh_trigger >= 0 and self.full_refresh_count == self.full_refresh_trigger: - self.full_refresh_count = 0 - elif self.full_refresh_trigger >= 0: - self.full_refresh_count += 1 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) + self.canvas = (img if self._rotation == 0 else img.rotate(self._rotation)) if self._render_cb is not None: self._render_cb() diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/waveshare/v2/waveshare.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/waveshare/v2/waveshare.py index 3286a3f..6c3ed04 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/waveshare/v2/waveshare.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/ui/waveshare/v2/waveshare.py @@ -335,4 +335,4 @@ class EPD: self.send_data(0x01) delay_ms(100) - ### END OF FILE ### + ### END OF FILE ### \ No newline at end of file