Files
slate32/src/lua/bindings/input.cpp
T
evan b5146b8642 refactor(lua): give the status bar its own dirty tracking and split settings out of sys
The bar repainted itself whole every second. It now compares each field against what
it last painted, adds seconds and a memory percentage, and keys the cache on
gui.getRotation() and ui.themeName so rotation and theme changes still repaint it.
Invalidation lives entirely in Lua; the firmware's push flag and gfx/statusbar.h are gone.

Bindings follow getName/setName/isName, persisted preferences move from sys to a settings
table, and gui.setRotation takes degrees like settings does. A bar that dies mid-run now
keeps its rows reserved rather than silently resizing the running app.
2026-08-02 10:49:01 -04:00

55 lines
1.5 KiB
C++

// Touch panel reads. Coordinates are calibrated and rotated by LuaApp::mapTouch;
// the raw ADC pair is exposed separately because calibration cannot use itself.
#include "../bindings.h"
#include "../lua_app.h"
static int l_input_getTouch(lua_State* L) {
LuaApp* owner = app(L);
if (!owner->touch.touched()) {
lua_pushnil(L);
return 1;
}
TS_Point point = owner->touch.getPoint();
int16_t x, y;
owner->mapTouch(point, x, y);
lua_pushinteger(L, x);
lua_pushinteger(L, y);
return 2;
}
static int l_input_getRawTouch(lua_State* L) {
LuaApp* owner = app(L);
if (!owner->touch.touched()) {
lua_pushnil(L);
return 1;
}
TS_Point point = owner->touch.getPoint();
lua_pushinteger(L, point.y);
lua_pushinteger(L, point.x);
return 2;
}
static int l_input_touched(lua_State* L) {
lua_pushboolean(L, app(L)->touch.touched());
return 1;
}
void registerInput(lua_State* L) {
static const luaL_Reg lib[] = {
// --- Current touch point, calibrated and rotated.
// @return integer|nil X, or nil when the panel is not touched.
// @return integer|nil Y.
{"getTouch", l_input_getTouch},
// --- Current touch point as raw ADC readings, for calibration.
// @return integer|nil X, or nil when the panel is not touched.
// @return integer|nil Y.
{"getRawTouch", l_input_getRawTouch},
// --- Whether the panel is being touched.
// @return boolean
{"isTouched", l_input_touched},
{nullptr, nullptr}};
luaL_newlib(L, lib);
lua_setglobal(L, "input");
}