Merge pull request #362 from python273/add-non-blocking-screen-updating

Add non blocking display updating
This commit is contained in:
evilsocket 2019-10-23 12:52:02 +02:00 committed by GitHub
commit 7779ebc983
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 17 deletions

View File

@ -1,7 +1,8 @@
import os
import logging
import pwnagotchi.plugins as plugins
import threading
import pwnagotchi.plugins as plugins
import pwnagotchi.ui.hw as hw
import pwnagotchi.ui.web as web
from pwnagotchi.ui.view import View
@ -18,6 +19,14 @@ class Display(View):
self.init_display()
self._canvas_next_event = threading.Event()
self._canvas_next = None
self._render_thread_instance = threading.Thread(
target=self._render_thread,
daemon=True
)
self._render_thread_instance.start()
def is_inky(self):
return self._implementation.name == 'inky'
@ -59,6 +68,14 @@ class Display(View):
img = self._canvas if self._rotation == 0 else self._canvas.rotate(-self._rotation)
return img
def _render_thread(self):
"""Used for non-blocking screen updating."""
while True:
self._canvas_next_event.wait()
self._canvas_next_event.clear()
self._implementation.render(self._canvas_next)
def _on_view_rendered(self, img):
web.update_frame(img)
try:
@ -70,4 +87,5 @@ class Display(View):
if self._enabled:
self._canvas = (img if self._rotation == 0 else img.rotate(self._rotation))
if self._implementation is not None:
self._implementation.render(self._canvas)
self._canvas_next = self._canvas
self._canvas_next_event.set()

View File

@ -66,6 +66,7 @@ class EPD:
epdconfig.digital_write(self.cs_pin, GPIO.HIGH)
def ReadBusy(self):
epdconfig.delay_ms(20)
while(epdconfig.digital_read(self.busy_pin) == 0): # 0: idle, 1: busy
epdconfig.delay_ms(100)