2019-10-21 14:01:21 +02:00
|
|
|
import os
|
2019-10-03 17:06:40 +02:00
|
|
|
import logging
|
2019-10-22 20:53:15 +03:00
|
|
|
import threading
|
2019-09-19 15:15:46 +02:00
|
|
|
|
2019-10-22 20:53:15 +03:00
|
|
|
import pwnagotchi.plugins as plugins
|
2019-10-15 11:50:09 +02:00
|
|
|
import pwnagotchi.ui.hw as hw
|
|
|
|
from pwnagotchi.ui.view import View
|
2019-09-19 15:15:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Display(View):
|
|
|
|
def __init__(self, config, state={}):
|
2019-10-15 11:50:09 +02:00
|
|
|
super(Display, self).__init__(config, hw.display_for(config), state)
|
2019-10-20 15:41:06 +02:00
|
|
|
config = config['ui']['display']
|
2019-09-19 15:15:46 +02:00
|
|
|
|
2019-10-20 15:41:06 +02:00
|
|
|
self._enabled = config['enabled']
|
|
|
|
self._rotation = config['rotation']
|
2019-09-19 15:15:46 +02:00
|
|
|
|
2019-10-20 15:41:06 +02:00
|
|
|
self.init_display()
|
2019-09-19 15:15:46 +02:00
|
|
|
|
2019-10-22 20:53:15 +03:00
|
|
|
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()
|
|
|
|
|
2019-10-12 17:47:51 +02:00
|
|
|
def is_inky(self):
|
2019-10-15 11:50:09 +02:00
|
|
|
return self._implementation.name == 'inky'
|
2019-09-28 20:17:45 +02:00
|
|
|
|
2019-10-12 17:47:51 +02:00
|
|
|
def is_papirus(self):
|
2019-10-15 11:50:09 +02:00
|
|
|
return self._implementation.name == 'papirus'
|
2019-09-29 06:23:38 +01:00
|
|
|
|
2019-10-12 17:47:51 +02:00
|
|
|
def is_waveshare_v1(self):
|
2019-10-15 11:50:09 +02:00
|
|
|
return self._implementation.name == 'waveshare_1'
|
2019-09-29 14:18:33 +02:00
|
|
|
|
2019-10-12 17:47:51 +02:00
|
|
|
def is_waveshare_v2(self):
|
2019-10-15 11:50:09 +02:00
|
|
|
return self._implementation.name == 'waveshare_2'
|
2019-09-28 20:17:45 +02:00
|
|
|
|
2019-10-20 21:27:10 +02:00
|
|
|
def is_waveshare27inch(self):
|
|
|
|
return self._implementation.name == 'waveshare27inch'
|
2019-11-05 14:26:35 +01:00
|
|
|
|
2019-10-23 00:11:25 -07:00
|
|
|
def is_waveshare29inch(self):
|
|
|
|
return self._implementation.name == 'waveshare29inch'
|
2019-10-20 21:27:10 +02:00
|
|
|
|
2019-10-14 16:38:57 +02:00
|
|
|
def is_oledhat(self):
|
2019-10-15 11:50:09 +02:00
|
|
|
return self._implementation.name == 'oledhat'
|
2019-10-14 16:38:57 +02:00
|
|
|
|
2019-10-19 04:49:38 +01:00
|
|
|
def is_lcdhat(self):
|
|
|
|
return self._implementation.name == 'lcdhat'
|
|
|
|
|
2019-10-26 12:52:07 -05:00
|
|
|
def is_dfrobot(self):
|
2019-10-27 16:02:00 +01:00
|
|
|
return self._implementation.name == 'dfrobot'
|
|
|
|
|
2019-12-06 03:24:01 +03:00
|
|
|
def is_waveshare144lcd(self):
|
|
|
|
return self._implementation.name == 'waveshare144lcd'
|
|
|
|
|
2019-10-27 16:02:00 +01:00
|
|
|
def is_waveshare154inch(self):
|
|
|
|
return self._implementation.name == 'waveshare154inch'
|
2019-10-26 12:52:07 -05:00
|
|
|
|
2019-10-27 12:47:15 -07:00
|
|
|
def is_waveshare213d(self):
|
|
|
|
return self._implementation.name == 'waveshare213d'
|
|
|
|
|
2019-12-11 23:08:29 +04:00
|
|
|
def is_waveshare213bc(self):
|
|
|
|
return self._implementation.name == 'waveshare213bc'
|
|
|
|
|
2019-11-11 14:15:48 +01:00
|
|
|
def is_spotpear24inch(self):
|
|
|
|
return self._implementation.name == 'spotpear24inch'
|
|
|
|
|
2019-10-12 17:47:51 +02:00
|
|
|
def is_waveshare_any(self):
|
|
|
|
return self.is_waveshare_v1() or self.is_waveshare_v2()
|
2019-10-03 22:59:57 +02:00
|
|
|
|
2019-10-15 11:50:09 +02:00
|
|
|
def init_display(self):
|
|
|
|
if self._enabled:
|
|
|
|
self._implementation.initialize()
|
|
|
|
plugins.on('display_setup', self._implementation)
|
2019-09-28 19:24:28 +02:00
|
|
|
else:
|
2019-10-15 11:50:09 +02:00
|
|
|
logging.warning("display module is disabled")
|
2019-09-19 15:15:46 +02:00
|
|
|
self.on_render(self._on_view_rendered)
|
|
|
|
|
2019-10-03 22:59:57 +02:00
|
|
|
def clear(self):
|
2019-10-15 11:50:09 +02:00
|
|
|
self._implementation.clear()
|
2019-10-03 01:25:07 -07:00
|
|
|
|
2019-10-03 17:06:40 +02:00
|
|
|
def image(self):
|
|
|
|
img = None
|
|
|
|
if self._canvas is not None:
|
|
|
|
img = self._canvas if self._rotation == 0 else self._canvas.rotate(-self._rotation)
|
|
|
|
return img
|
2019-10-01 22:03:52 +02:00
|
|
|
|
2019-10-22 20:53:15 +03:00
|
|
|
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)
|
|
|
|
|
2019-09-19 15:15:46 +02:00
|
|
|
def _on_view_rendered(self, img):
|
2019-10-21 14:01:21 +02:00
|
|
|
try:
|
2019-11-12 21:19:31 +01:00
|
|
|
if self._config['ui']['web']['on_frame'] != '':
|
|
|
|
os.system(self._config['ui']['web']['on_frame'])
|
2019-10-21 14:01:21 +02:00
|
|
|
except Exception as e:
|
|
|
|
logging.error("%s" % e)
|
|
|
|
|
2019-09-19 15:15:46 +02:00
|
|
|
if self._enabled:
|
2019-10-03 17:06:40 +02:00
|
|
|
self._canvas = (img if self._rotation == 0 else img.rotate(self._rotation))
|
2019-10-15 11:50:09 +02:00
|
|
|
if self._implementation is not None:
|
2019-10-22 20:53:15 +03:00
|
|
|
self._canvas_next = self._canvas
|
|
|
|
self._canvas_next_event.set()
|