7bc9afae33
Follows lib/esp32-lua-api: gui -> screen, node -> tree, settings and input split into screen/sys/touch/buttons. Settings is one provider lighter, with timezone on Sys and rotation and theme on Gui, which now applies and persists a rotation in one call. The calibration screen stashes the rotation it borrows rather than relying on a transient setter.
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
#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 <TFT_eSPI.h>
|
|
#include <XPT2046_Touchscreen.h>
|
|
#include <lua/runtime.h>
|
|
|
|
#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;
|
|
};
|