75b3a2c490
Namespaces were shared across features: `settings` was written by core, the
panel and touch, and `input` by touch and buttons. That made "does this
firmware implement the whole feature?" a question no pointer could answer.
Each namespace now belongs to exactly one feature or to core, so a feature is
a provider pointer and the compiler validates completeness:
gui, node -> screen, tree, under the screen feature
settings -> screen (rotation, theme), sys (timezone),
touch (calibration)
input -> touch, buttons
Runtime::open() no longer requires a GuiProvider; a firmware without one runs
with no screen/tree globals and reports sys.hasFeature("screen") false.
Rotation is one value again: GuiProvider::setRotation applies and persists, so
an app rotating the panel transiently puts the old value back itself.
85 lines
2.3 KiB
C++
85 lines
2.3 KiB
C++
#include "../helpers.h"
|
|
|
|
namespace esp32lua {
|
|
namespace bindings {
|
|
namespace {
|
|
|
|
int getButtons(lua_State* state) {
|
|
pushStrings(state, Runtime::from(state)->buttons().buttons());
|
|
return 1;
|
|
}
|
|
|
|
int isAnyPressed(lua_State* state) {
|
|
lua_pushboolean(state, Runtime::from(state)->buttons().isAnyPressed());
|
|
return 1;
|
|
}
|
|
|
|
int isPressed(lua_State* state) {
|
|
const std::string button = checkString(state, 1);
|
|
lua_pushboolean(state, Runtime::from(state)->buttons().isPressed(button));
|
|
return 1;
|
|
}
|
|
|
|
int wasPressed(lua_State* state) {
|
|
const std::string button = checkString(state, 1);
|
|
lua_pushboolean(state, Runtime::from(state)->buttons().wasPressed(button));
|
|
return 1;
|
|
}
|
|
|
|
int wasReleased(lua_State* state) {
|
|
const std::string button = checkString(state, 1);
|
|
lua_pushboolean(state, Runtime::from(state)->buttons().wasReleased(button));
|
|
return 1;
|
|
}
|
|
|
|
// @lua-module buttons ButtonsLib
|
|
// @lua-preamble ---@alias Button "up"|"down"|"left"|"right"|"confirm"|"back"
|
|
// @lua-preamble
|
|
// @lua-preamble -- Roles, not physical buttons: a device maps whatever hardware
|
|
// it has onto them, and
|
|
// @lua-preamble -- up/down/left/right are the directions tree.moveFocus already
|
|
// takes.
|
|
const luaL_Reg FUNCTIONS[] = {
|
|
// ---Returns the roles this device reports, so an app can label only the
|
|
// actions it has.
|
|
// @return Button[]
|
|
{"getAll", getButtons},
|
|
// ---Whether any button is held.
|
|
// @return boolean
|
|
{"isAnyPressed", isAnyPressed},
|
|
// ---Whether a button is held.
|
|
// @param button Button
|
|
// @return boolean
|
|
{"isPressed", isPressed},
|
|
// ---Whether a button went down since the last poll.
|
|
// @param button Button
|
|
// @return boolean
|
|
{"wasPressed", wasPressed},
|
|
// ---Whether a button came up since the last poll.
|
|
// @param button Button
|
|
// @return boolean
|
|
{"wasReleased", wasReleased},
|
|
{nullptr, nullptr},
|
|
};
|
|
|
|
} // namespace
|
|
|
|
void registerButtons(lua_State* state) {
|
|
luaL_newlib(state, FUNCTIONS);
|
|
lua_setglobal(state, "buttons");
|
|
}
|
|
|
|
} // namespace bindings
|
|
} // namespace esp32lua
|
|
|
|
// @lua-global
|
|
// ---Fired when a button goes down.
|
|
// @param button Button
|
|
// @lua-fn on_button_down
|
|
// ---Fired when a button comes up.
|
|
// @param button Button
|
|
// @lua-fn on_button_up
|
|
// ---Tap alias, fired on release like a click, after on_button_up.
|
|
// @param button Button
|
|
// @lua-fn on_button
|