[NV14] Use trim hats to emulate key events when standalone lua script running (#985)
* Preliminary trims as keys for lua Largely based on open-flysky implementation * Add `isLuaStandaloneRunning()` * Add more virtual events * Tweak virtual events further * Finish remapping keys to virtual events * Move some virtuals to right trim hat * Add missing "defined" * Revert to common EVT_VIRTUAL_MENU mapping * Make keys/trims reset backlight like other radios
This commit is contained in:
@@ -2040,6 +2040,9 @@ const luaR_value_entry opentxConstants[] = {
|
||||
#if defined(KEYS_GPIO_REG_PGUP)
|
||||
{ "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_BREAK(KEY_PGUP) },
|
||||
{ "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_PGDN) },
|
||||
#elif defined(PCBNV14)
|
||||
{ "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_BREAK(KEY_LEFT) },
|
||||
{ "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_RIGHT) },
|
||||
#else
|
||||
{ "EVT_VIRTUAL_PREV_PAGE", EVT_KEY_LONG(KEY_PGDN) },
|
||||
{ "EVT_VIRTUAL_NEXT_PAGE", EVT_KEY_BREAK(KEY_PGDN) },
|
||||
|
||||
@@ -240,6 +240,9 @@ struct LuaMemTracer {
|
||||
|
||||
void * tracer_alloc(void * ud, void * ptr, size_t osize, size_t nsize);
|
||||
|
||||
inline bool isLuaStandaloneRunning() {
|
||||
return scriptInternalData[0].reference == SCRIPT_STANDALONE;
|
||||
}
|
||||
#else // defined(LUA)
|
||||
|
||||
#define luaInit()
|
||||
|
||||
@@ -144,18 +144,17 @@ void stop_trainer_capture();
|
||||
// Keys driver
|
||||
enum EnumKeys
|
||||
{
|
||||
KEY_ENTER,
|
||||
KEY_EXIT,
|
||||
KEY_PGUP,
|
||||
KEY_PGDN,
|
||||
KEY_ENTER,
|
||||
KEY_UP,
|
||||
KEY_DOWN,
|
||||
KEY_LEFT,
|
||||
KEY_RIGHT,
|
||||
KEY_MODEL,
|
||||
KEY_UP /*= KEY_MODEL*/,
|
||||
KEY_EXIT,
|
||||
KEY_DOWN /*= KEY_EXIT*/,
|
||||
KEY_TELEM,
|
||||
KEY_RIGHT = KEY_TELEM,
|
||||
KEY_RADIO,
|
||||
KEY_LEFT = KEY_RADIO,
|
||||
|
||||
KEY_TELEM,
|
||||
TRM_BASE,
|
||||
TRM_LH_DWN = TRM_BASE,
|
||||
TRM_LH_UP,
|
||||
|
||||
@@ -25,20 +25,32 @@
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
// Arrow keys on right trim joystick
|
||||
// is only supported within bootloader
|
||||
#if defined(BOOT)
|
||||
if (TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 1 << KEY_DOWN;
|
||||
if (TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 1 << KEY_UP;
|
||||
if (TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 1 << KEY_LEFT;
|
||||
if (TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 1 << KEY_RIGHT;
|
||||
bool getKeys = true;
|
||||
#if defined(LUA)
|
||||
if (!isLuaStandaloneRunning()) {
|
||||
getKeys = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (getKeys) {
|
||||
if (TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 1 << KEY_RADIO;
|
||||
if (TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
result |= 1 << KEY_MODEL;
|
||||
if (TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
|
||||
result |= 1 << KEY_TELEM;
|
||||
if (TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
|
||||
result |= 1 << KEY_PGUP;
|
||||
if (TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 1 << KEY_DOWN;
|
||||
if (TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 1 << KEY_UP;
|
||||
if (TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 1 << KEY_LEFT;
|
||||
if (TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 1 << KEY_RIGHT;
|
||||
}
|
||||
|
||||
// Enter and Exit are always supported
|
||||
if (TRIMS_GPIO_REG_RPRESS & TRIMS_GPIO_PIN_RPRESS)
|
||||
result |= 1 << KEY_ENTER;
|
||||
@@ -52,6 +64,13 @@ uint32_t readTrims()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
bool getTrim = true;
|
||||
#if defined(LUA)
|
||||
if (isLuaStandaloneRunning()) {
|
||||
getTrim = false;
|
||||
}
|
||||
#endif
|
||||
if(!getTrim) return result;
|
||||
if (TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 1 << (TRM_LH_DWN - TRM_BASE);
|
||||
if (TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
@@ -98,6 +117,11 @@ void readKeysAndTrims()
|
||||
for (i = 1; i <= 1 << (TRM_LAST-TRM_BASE); i <<= 1) {
|
||||
keys[index++].input(trims & i);
|
||||
}
|
||||
|
||||
if ((in || trims) && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) {
|
||||
// on keypress turn the light on
|
||||
resetBacklightTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(BOOT)
|
||||
|
||||
Reference in New Issue
Block a user