// 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"); }