diff --git a/modules/c/presto/presto.c b/modules/c/presto/presto.c index ec63546..8ad8849 100644 --- a/modules/c/presto/presto.c +++ b/modules/c/presto/presto.c @@ -36,7 +36,7 @@ MP_DEFINE_CONST_OBJ_TYPE( /***** Globals Table *****/ static const mp_map_elem_t presto_globals_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_presto) }, + { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR__presto) }, { MP_OBJ_NEW_QSTR(MP_QSTR_Presto), (mp_obj_t)&Presto_type }, }; diff --git a/modules/py_frozen/backlight.py b/modules/py_frozen/backlight.py index bdd7d18..503bd2c 100644 --- a/modules/py_frozen/backlight.py +++ b/modules/py_frozen/backlight.py @@ -39,6 +39,12 @@ def zone(index, x, y): self.bl = plasma.WS2812(7, 0, 0, 33) self.bl.start() + def clear(self): + self.bl.clear() + + def set_rgb(self, i, r, g, b): + self.bl.set_rgb(i, r, g, b) + @micropython.native def update(self): mv = self.mv diff --git a/modules/py_frozen/ezwifi.py b/modules/py_frozen/ezwifi.py index 89991f8..32f8ad2 100644 --- a/modules/py_frozen/ezwifi.py +++ b/modules/py_frozen/ezwifi.py @@ -50,13 +50,17 @@ def _callback(self, handler_name, *args, **kwargs): def _log(self, text, level=LogLevel.INFO): self._callback(LogLevel.text[level], text) or (self._verbose and print(text)) - def on(self, handler_name): + def on(self, handler_name, handler=None): if handler_name not in self._events.keys(): raise ValueError(f"Invalid event: \"{handler_name}\"") def _on(handler): self._events[handler_name] = handler + if handler is not None: + _on(handler) + return True + return _on def error(self): diff --git a/modules/py_frozen/presto.py b/modules/py_frozen/presto.py new file mode 100644 index 0000000..6f0ec94 --- /dev/null +++ b/modules/py_frozen/presto.py @@ -0,0 +1,64 @@ +import asyncio +import _presto +from touch import FT6236 +from backlight import Reactive +from ezwifi import EzWiFi + +from collections import namedtuple +from picographics import PicoGraphics, DISPLAY_PRESTO, DISPLAY_PRESTO_FULL_RES + + +Touch = namedtuple("touch", ("x", "y", "touched")) + + +class Presto(): + def __init__(self, full_res=False, reactive_backlight=False, direct_to_fb=False): + # WiFi - *must* happen before Presto bringup + # Note: Forces WiFi details to be in secrets.py + self.wifi = EzWiFi() + + # Touch Input + self.touch = FT6236(full_res=full_res) + + # Display Driver & PicoGraphics + self.presto = _presto.Presto(full_res=full_res) + self.buffer = None if (full_res and not direct_to_fb) else memoryview(self.presto) + self.display = PicoGraphics(DISPLAY_PRESTO_FULL_RES if full_res else DISPLAY_PRESTO, buffer=self.buffer) + self.width, self.height = self.display.get_bounds() + + # Reactive Backlight + self.backlight = Reactive(memoryview(self.presto), self.width, self.height) if reactive_backlight else None + + @property + def touch_a(self): + return Touch(self.touch.x, self.touch.y, self.touch.state) + + @property + def touch_b(self): + return Touch(self.touch.x2, self.touch.y2, self.touch.state2) + + @property + def touch_delta(self): + return self.touch.distance, self.touch.angle + + async def async_connect(self): + await self.wifi.connect() + + def connect(self): + return asyncio.get_event_loop().run_until_complete(self.wifi.connect()) + + def update(self): + self.presto.update(self.display) + try: + self.backlight.update() + except AttributeError: + pass + self.touch.poll() + + def clear(self): + self.display.clear() + self.presto.update(self.display) + try: + self.backlight.bl.clear() + except AttributeError: + pass