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
|
2023-09-01 01:17:31 +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']
|
2023-09-01 01:17:31 +02:00
|
|
|
|
2019-10-20 15:41:06 +02:00
|
|
|
self._enabled = config['enabled']
|
|
|
|
self._rotation = config['rotation']
|
2023-09-01 01:17:31 +02:00
|
|
|
|
2019-10-20 15:41:06 +02:00
|
|
|
self.init_display()
|
2023-09-01 01:17:31 +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()
|
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_lcdhat(self):
|
|
|
|
return self._implementation.name == 'lcdhat'
|
2019-09-28 20:17:45 +02:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare144lcd(self):
|
|
|
|
return self._implementation.name == 'waveshare144lcd'
|
|
|
|
|
|
|
|
def is_oledhat(self):
|
|
|
|
return self._implementation.name == 'oledhat'
|
|
|
|
|
|
|
|
def is_waveshare1in02(self):
|
|
|
|
return self._implementation.name == 'waveshare1in02'
|
|
|
|
|
|
|
|
def is_waveshare1in54(self):
|
|
|
|
return self._implementation.name == 'waveshare1in54'
|
|
|
|
|
|
|
|
def is_waveshare1in54V2(self):
|
|
|
|
return self._implementation.name == 'waveshare1in54_v2'
|
|
|
|
|
|
|
|
def is_waveshare1in54b(self):
|
|
|
|
return self._implementation.name == 'waveshare1in54b'
|
|
|
|
|
|
|
|
def is_waveshare1in54bV22(self):
|
|
|
|
return self._implementation.name == 'waveshare1in54b_v2'
|
|
|
|
|
|
|
|
def is_waveshare1in54c(self):
|
|
|
|
return self._implementation.name == 'waveshare1in54c'
|
|
|
|
|
|
|
|
def is_waveshare1in64g(self):
|
|
|
|
return self._implementation.name == 'waveshare1in64g'
|
|
|
|
|
|
|
|
def is_waveshare2in7(self):
|
|
|
|
return self._implementation.name == 'waveshare2in7'
|
|
|
|
|
|
|
|
def is_waveshare2in7V2(self):
|
|
|
|
return self._implementation.name == 'waveshare2in7_v2'
|
|
|
|
|
|
|
|
def is_waveshare2in9(self):
|
|
|
|
return self._implementation.name == 'waveshare2in9'
|
|
|
|
|
|
|
|
def is_waveshare2in9V2(self):
|
|
|
|
return self._implementation.name == 'waveshare2in9_v2'
|
|
|
|
|
|
|
|
def is_waveshare2in9bV3(self):
|
|
|
|
return self._implementation.name == 'waveshare2in9b_v3'
|
|
|
|
|
|
|
|
def is_waveshare2in9bV4(self):
|
|
|
|
return self._implementation.name == 'waveshare2in9b_v4'
|
|
|
|
|
|
|
|
def is_waveshare2in9bc(self):
|
|
|
|
return self._implementation.name == 'waveshare2in9bc'
|
|
|
|
|
|
|
|
def is_waveshare2in9d(self):
|
|
|
|
return self._implementation.name == 'waveshare2in9d'
|
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
|
|
|
|
2022-01-11 00:18:07 +00:00
|
|
|
def is_waveshare_v3(self):
|
|
|
|
return self._implementation.name == 'waveshare_3'
|
|
|
|
|
2023-11-28 15:33:23 +01:00
|
|
|
def is_waveshare_v4(self):
|
|
|
|
return self._implementation.name == 'waveshare_4'
|
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare2in13b_v3(self):
|
|
|
|
return self._implementation.name == 'waveshare2in13b_v3'
|
2019-11-05 14:26:35 +01:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare2in13b_v4(self):
|
|
|
|
return self._implementation.name == 'waveshare2in13b_v4'
|
2023-11-27 10:52:04 +01:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare2in13bc(self):
|
|
|
|
return self._implementation.name == 'waveshare2in13bc'
|
2023-09-01 01:17:31 +02:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare2in13d(self):
|
|
|
|
return self._implementation.name == 'waveshare2in13d'
|
2019-10-14 16:38:57 +02:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare2in23g(self):
|
|
|
|
return self._implementation.name == 'waveshare2in23g'
|
2019-10-19 04:49:38 +01:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare2in36g(self):
|
|
|
|
return self._implementation.name == 'waveshare2in36g'
|
2020-04-17 09:27:58 -05:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare2in66(self):
|
|
|
|
return self._implementation.name == 'waveshare2in66'
|
2019-10-27 16:02:00 +01:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare2in66g(self):
|
|
|
|
return self._implementation.name == 'waveshare2in66g'
|
|
|
|
|
|
|
|
def is_waveshare3in0g(self):
|
|
|
|
return self._implementation.name == 'waveshare3in0g'
|
|
|
|
|
|
|
|
def is_waveshare3in7(self):
|
|
|
|
return self._implementation.name == 'waveshare3in7'
|
|
|
|
|
|
|
|
def is_waveshare3in52(self):
|
|
|
|
return self._implementation.name == 'waveshare3in52'
|
|
|
|
|
|
|
|
def is_waveshare4in01f(self):
|
|
|
|
return self._implementation.name == 'waveshare4in01f'
|
|
|
|
|
|
|
|
def is_waveshare4in2(self):
|
|
|
|
return self._implementation.name == 'waveshare4in2'
|
|
|
|
|
|
|
|
def is_waveshare4in2V2(self):
|
|
|
|
return self._implementation.name == 'waveshare4in2_v2'
|
|
|
|
|
|
|
|
def is_waveshare4in2bV2(self):
|
|
|
|
return self._implementation.name == 'waveshare4in2b_v2'
|
|
|
|
|
|
|
|
def is_waveshare4in2bc(self):
|
|
|
|
return self._implementation.name == 'waveshare4in2bc'
|
|
|
|
|
|
|
|
def is_waveshare4in26(self):
|
|
|
|
return self._implementation.name == 'waveshare4in26'
|
|
|
|
|
|
|
|
def is_waveshare4in37g(self):
|
|
|
|
return self._implementation.name == 'waveshare4in37g'
|
|
|
|
|
|
|
|
def is_waveshare5in65f(self):
|
|
|
|
return self._implementation.name == 'waveshare5in65f'
|
|
|
|
|
|
|
|
def is_waveshare5in83(self):
|
|
|
|
return self._implementation.name == 'waveshare5in83'
|
|
|
|
|
|
|
|
def is_waveshare5in83V2(self):
|
|
|
|
return self._implementation.name == 'waveshare5in83_v2'
|
|
|
|
|
|
|
|
def is_waveshare5in83bV2(self):
|
|
|
|
return self._implementation.name == 'waveshare5in83b_v2'
|
|
|
|
|
|
|
|
def is_waveshare5in83bc(self):
|
|
|
|
return self._implementation.name == 'waveshare5in83bc'
|
|
|
|
|
|
|
|
def is_waveshare7in3f(self):
|
|
|
|
return self._implementation.name == 'waveshare7in3f'
|
2019-12-06 03:24:01 +03:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare7in3g(self):
|
|
|
|
return self._implementation.name == 'waveshare7in3g'
|
2019-10-26 12:52:07 -05:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare7in5(self):
|
|
|
|
return self._implementation.name == 'waveshare7in5'
|
2019-10-27 12:47:15 -07:00
|
|
|
|
2024-01-12 18:42:47 +01:00
|
|
|
def is_waveshare7in5HD(self):
|
|
|
|
return self._implementation.name == 'waveshare7in5_HD'
|
|
|
|
|
|
|
|
def is_waveshare7in5V2(self):
|
|
|
|
return self._implementation.name == 'waveshare7in5_v2'
|
|
|
|
|
|
|
|
def is_waveshare7in5bHD(self):
|
|
|
|
return self._implementation.name == 'waveshare7in5b_HD'
|
|
|
|
|
|
|
|
def is_waveshare7in5bV2(self):
|
|
|
|
return self._implementation.name == 'waveshare7in5b_v2'
|
|
|
|
|
|
|
|
def is_waveshare7in5bc(self):
|
|
|
|
return self._implementation.name == 'waveshare7in5bc'
|
|
|
|
|
|
|
|
def is_waveshare13in3k(self):
|
|
|
|
return self._implementation.name == 'waveshare13in3k'
|
|
|
|
|
|
|
|
def is_inky(self):
|
|
|
|
return self._implementation.name == 'inky'
|
|
|
|
|
|
|
|
def is_papirus(self):
|
|
|
|
return self._implementation.name == 'papirus'
|
|
|
|
|
|
|
|
def is_dfrobot_v1(self):
|
|
|
|
return self._implementation.name == 'dfrobot_v1'
|
|
|
|
|
|
|
|
def is_dfrobot_v2(self):
|
|
|
|
return self._implementation.name == 'dfrobot_v2'
|
2019-12-11 23:08:29 +04:00
|
|
|
|
2019-11-11 14:15:48 +01:00
|
|
|
def is_spotpear24inch(self):
|
|
|
|
return self._implementation.name == 'spotpear24inch'
|
2023-07-28 22:15:59 +02:00
|
|
|
|
2023-09-01 01:17:31 +02:00
|
|
|
def is_displayhatmini(self):
|
|
|
|
return self._implementation.name == 'displayhatmini'
|
|
|
|
|
|
|
|
def is_waveshare35lcd(self):
|
|
|
|
return self._implementation.name == 'waveshare35lcd'
|
2019-11-11 14:15:48 +01:00
|
|
|
|
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()
|
2023-07-28 22:15:59 +02:00
|
|
|
self._canvas_next_event.clear()
|
2019-10-22 20:53:15 +03:00
|
|
|
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)
|
2023-09-01 01:17:31 +02:00
|
|
|
|
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
|
2023-09-01 01:17:31 +02:00
|
|
|
self._canvas_next_event.set()
|