#pragma once // The firmware side of running a Lua app: the panel, the touch controller and // the frame pacing. The lua_State, the bindings, the node tree, app loading and // navigation history all belong to esp32lua::Runtime, and everything the user // sees -- chrome included -- is built by /.lua/main.lua. #include #include #include #include "providers.h" class LuaHost { public: LuaHost(TFT_eSPI& tft, XPT2046_Touchscreen& touch); // Starts the launcher, or reports the failure that stopped it. bool begin(); void loop(); bool running() const { return runtime.hasApp(); } // Called by the providers, which is why they hold a reference to the host. void applyRotation(); void mapTouch(const TS_Point& point, int16_t& x, int16_t& y) const; private: static constexpr uint32_t DRAW_INTERVAL_MS = 33; static constexpr int16_t PANEL_W = 320; static constexpr int16_t PANEL_H = 480; static constexpr int16_t MOVE_EPSILON_PX = 2; esp32lua::Providers wire(); // Every app starts the same way, whether it is the launcher at boot or a // route the running app asked for. void prepareForApp(); void settleNewApp(); void navigate(); void pollTouch(); void pollTimers(); void fail(const char* message); TFT_eSPI& tft; XPT2046_Touchscreen& touchPanel; slate::Log logProvider; slate::Sys sysProvider; slate::Fs fsProvider; slate::Gui guiProvider; slate::Http httpProvider; slate::Timer timerProvider; slate::Wifi wifiProvider; slate::Ble bleProvider; slate::Touch touchProvider; esp32lua::Runtime runtime; uint32_t nextDrawMs = 0; uint32_t lastDrawMs = 0; bool lastTouched = false; bool ignoreRelease = false; int16_t lastX = 0, lastY = 0; int16_t movedX = 0, movedY = 0; };