1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#include "lua/lua_controls.hpp"
#include <memory>
#include <string>
#include "lua.hpp"
#include "esp_log.h"
#include "lauxlib.h"
#include "lua.h"
#include "lvgl.h"
#include "drivers/nvs.hpp"
#include "ui/ui_events.hpp"
namespace lua {
[[maybe_unused]] static constexpr char kTag[] = "lua_controls";
static auto controls_schemes(lua_State* L) -> int {
lua_newtable(L);
lua_pushliteral(L, "Buttons Only");
lua_rawseti(L, -2,
static_cast<int>(drivers::NvsStorage::InputModes::kButtonsOnly));
lua_pushliteral(L, "D-Pad");
lua_rawseti(
L, -2,
static_cast<int>(drivers::NvsStorage::InputModes::kDirectionalWheel));
lua_pushliteral(L, "Touchwheel");
lua_rawseti(
L, -2, static_cast<int>(drivers::NvsStorage::InputModes::kRotatingWheel));
return 1;
}
static auto locked_controls_schemes(lua_State* L) -> int {
lua_newtable(L);
lua_pushliteral(L, "Disabled");
lua_rawseti(
L, -2,
static_cast<int>(drivers::NvsStorage::LockedInputModes::kDisabled));
lua_pushliteral(L, "Volume Only");
lua_rawseti(
L, -2,
static_cast<int>(drivers::NvsStorage::LockedInputModes::kVolumeOnly));
return 1;
}
static auto haptics_modes(lua_State* L) -> int {
lua_newtable(L);
lua_pushliteral(L, "Disabled");
lua_rawseti(L, -2,
static_cast<int>(drivers::NvsStorage::HapticsModes::kDisabled));
lua_pushliteral(L, "Minimal");
lua_rawseti(
L, -2,
static_cast<int>(drivers::NvsStorage::HapticsModes::kMinimal));
lua_pushliteral(L, "Strong");
lua_rawseti(
L, -2, static_cast<int>(drivers::NvsStorage::HapticsModes::kStrong));
return 1;
}
static const struct luaL_Reg kControlsFuncs[] = {{"schemes", controls_schemes},
{"locked_schemes", locked_controls_schemes},
{"haptics_modes", haptics_modes},
{NULL, NULL}};
static auto lua_controls(lua_State* state) -> int {
luaL_newlib(state, kControlsFuncs);
return 1;
}
auto RegisterControlsModule(lua_State* s) -> void {
luaL_requiref(s, "controls", lua_controls, true);
lua_pop(s, 1);
}
} // namespace lua
|