Skip to content

Commit

Permalink
chores(lua): generate keys definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic authored and pfeerick committed Dec 9, 2023
1 parent ecd50cf commit 6ca58c7
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 139 deletions.
3 changes: 3 additions & 0 deletions radio/src/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ set(SRC ${SRC}

AddHWGenTarget(${HW_DESC_JSON} lua_inputs lua_inputs.inc)
AddHWGenTarget(${HW_DESC_JSON} lua_mixsrc lua_mixsrc.inc)
AddHWGenTarget(${HW_DESC_JSON} lua_keys lua_keys.inc)

set(SRC ${SRC}
${CMAKE_CURRENT_BINARY_DIR}/lua_inputs.inc
${CMAKE_CURRENT_BINARY_DIR}/lua_mixsrc.inc
${CMAKE_CURRENT_BINARY_DIR}/lua_keys.inc
)

# helper target for testing purposes
add_custom_target(lua_inputs DEPENDS ${HW_DESC_JSON} lua_inputs.inc)
add_custom_target(lua_mixsrc DEPENDS ${HW_DESC_JSON} lua_mixsrc.inc)
add_custom_target(lua_keys DEPENDS ${HW_DESC_JSON} lua_keys.inc)

if(GUI_DIR STREQUAL colorlcd)
set(SRC ${SRC} lua/api_colorlcd.cpp lua/widgets.cpp)
Expand Down
141 changes: 2 additions & 139 deletions radio/src/lua/api_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3155,145 +3155,8 @@ LROT_BEGIN(etxcst, NULL, 0)
LROT_NUMENTRY( FIXEDWIDTH, FIXEDWIDTH )
#endif

// Virtual events
#if defined(ROTARY_ENCODER_NAVIGATION) || defined(USE_TRIMS_AS_BUTTOS)
LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_ROTARY_LEFT )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_ROTARY_RIGHT )
LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_ROTARY_LEFT )
LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_ROTARY_RIGHT )
LROT_NUMENTRY( ROTENC_LOWSPEED, ROTENC_LOWSPEED )
LROT_NUMENTRY( ROTENC_MIDSPEED, ROTENC_MIDSPEED )
LROT_NUMENTRY( ROTENC_HIGHSPEED, ROTENC_HIGHSPEED )
#elif defined(PCBX9D) || defined(PCBX9DP) || defined(RADIO_T8) || defined(RADIO_COMMANDO8)// key reverted between field nav and value change
LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_KEY_FIRST(KEY_PLUS) )
LROT_NUMENTRY( EVT_VIRTUAL_PREV_REPT, EVT_KEY_REPT(KEY_PLUS) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_KEY_FIRST(KEY_MINUS) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_REPT, EVT_KEY_REPT(KEY_MINUS) )
LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_KEY_FIRST(KEY_MINUS) )
LROT_NUMENTRY( EVT_VIRTUAL_DEC_REPT, EVT_KEY_REPT(KEY_MINUS) )
LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_KEY_FIRST(KEY_PLUS) )
LROT_NUMENTRY( EVT_VIRTUAL_INC_REPT, EVT_KEY_REPT(KEY_PLUS) )
#else
LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_KEY_FIRST(KEY_UP) )
LROT_NUMENTRY( EVT_VIRTUAL_PREV_REPT, EVT_KEY_REPT(KEY_UP) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_KEY_FIRST(KEY_DOWN) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_REPT, EVT_KEY_REPT(KEY_DOWN) )
LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_KEY_FIRST(KEY_DOWN) )
LROT_NUMENTRY( EVT_VIRTUAL_DEC_REPT, EVT_KEY_REPT(KEY_DOWN) )
LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_KEY_FIRST(KEY_UP) )
LROT_NUMENTRY( EVT_VIRTUAL_INC_REPT, EVT_KEY_REPT(KEY_UP) )
#endif

#if defined(NAVIGATION_9X)
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_LEFT) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_LEFT) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_RIGHT) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_RIGHT) )
LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) )
#elif defined(NAVIGATION_XLITE)
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_LEFT) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_LONG(KEY_RIGHT) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_SHIFT) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_SHIFT) )
LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) )
#elif defined(NAVIGATION_X7) || defined(NAVIGATION_X9D)
#if defined(RADIO_TX12) || defined(RADIO_TX12MK2) || defined(RADIO_BOXER) || defined(RADIO_ZORRO) || defined(RADIO_POCKET) || defined(RADIO_T8) || defined(RADIO_COMMANDO8) || defined(RADIO_MT12)
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_BREAK(KEY_PAGEUP) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGEDN) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_MODEL) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_MODEL) )
#else
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_PAGE) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGE) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_MENU) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_MENU) )
#endif
LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) )
#elif defined(COLORLCD)
#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_BREAK(KEY_PAGEUP) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGEDN) )
#else
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_PAGEDN) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGEDN) )
#endif
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_MODEL) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_MODEL) )
LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) )
#endif

// key events
LROT_NUMENTRY( EVT_EXIT_BREAK, EVT_KEY_BREAK(KEY_EXIT) )

#if defined(KEYS_GPIO_REG_ENTER)
KEY_EVENTS(ENTER, KEY_ENTER)
#endif

#if defined(KEYS_GPIO_REG_MENU)
KEY_EVENTS(MENU, KEY_MENU)
#endif

#if defined(KEYS_GPIO_REG_RIGHT) && defined(COLORLCD) || defined(USE_HATS_AS_KEYS)
KEY_EVENTS(TELEM, KEY_TELE)
#elif defined(KEYS_GPIO_REG_RIGHT)
KEY_EVENTS(RIGHT, KEY_RIGHT)
#endif

#if defined(KEYS_GPIO_REG_UP) && defined(COLORLCD) || defined(USE_HATS_AS_KEYS)
KEY_EVENTS(MODEL, KEY_MODEL)
#elif defined(KEYS_GPIO_REG_UP)
KEY_EVENTS(UP, KEY_UP)
#endif

#if defined(KEYS_GPIO_REG_LEFT) && defined(COLORLCD) || defined(USE_HATS_AS_KEYS)
KEY_EVENTS(SYS, KEY_SYS)
#elif defined(KEYS_GPIO_REG_LEFT)
KEY_EVENTS(LEFT, KEY_LEFT)
#endif

#if defined(KEYS_GPIO_REG_DOWN) && defined(COLORLCD)
LROT_NUMENTRY( EVT_RTN_FIRST, EVT_KEY_BREAK(KEY_EXIT) )
#elif defined(KEYS_GPIO_REG_DOWN)
KEY_EVENTS(DOWN, KEY_DOWN)
#endif

#if defined(KEYS_GPIO_REG_PAGEUP) || defined(USE_HATS_AS_KEYS)
KEY_EVENTS(PAGEUP, KEY_PAGEUP)
#endif

#if defined(KEYS_GPIO_REG_PAGEDN) || defined(USE_HATS_AS_KEYS)
KEY_EVENTS(PAGEDN, KEY_PAGEDN)
#endif

#if defined(KEYS_GPIO_REG_PAGE)
KEY_EVENTS(PAGE, KEY_PAGE)
#endif

#if defined(KEYS_GPIO_REG_SHIFT)
KEY_EVENTS(SHIFT, KEY_SHIFT)
#endif

#if defined(KEYS_GPIO_REG_PLUS)
KEY_EVENTS(PLUS, KEY_PLUS)
#endif

#if defined(KEYS_GPIO_REG_MINUS)
KEY_EVENTS(MINUS, KEY_MINUS)
#endif

#if defined(ROTARY_ENCODER_NAVIGATION) || defined(USE_HATS_AS_KEYS)
KEY_EVENTS(ROT, KEY_ENTER)
LROT_NUMENTRY( EVT_ROT_LEFT, EVT_ROTARY_LEFT )
LROT_NUMENTRY( EVT_ROT_RIGHT, EVT_ROTARY_RIGHT )
#endif
// Key events
#include "lua_keys.inc"

// touch events
#if defined(HARDWARE_TOUCH)
Expand Down
139 changes: 139 additions & 0 deletions radio/util/hw_defs/lua_keys.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
//
// WARNING: DO NOT EDIT THIS FILE
// This file has been generated from the target's JSON hardware description
//

{% set key_plus = keys | selectattr("key","==","KEY_PLUS") | first %}
{% set key_up = keys | selectattr("key","==","KEY_UP") | first %}
{% set key_shift = keys | selectattr("key","==","KEY_SHIFT") | first %}
{% set key_page = keys | selectattr("key","==","KEY_PAGE") | first %}
{% set key_pageup = keys | selectattr("key","==","KEY_PAGEUP") | first %}
{% set key_model = keys | selectattr("key","==","KEY_MODEL") | first %}
{% set key_menu = keys | selectattr("key","==","KEY_MENU") | first %}
{% set key_tele = keys | selectattr("key","==","KEY_TELE") | first %}
{% set key_sys = keys | selectattr("key","==","KEY_SYS") | first %}

{% if key_plus %}
LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_KEY_FIRST(KEY_PLUS) )
LROT_NUMENTRY( EVT_VIRTUAL_PREV_REPT, EVT_KEY_REPT(KEY_PLUS) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_KEY_FIRST(KEY_MINUS) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_REPT, EVT_KEY_REPT(KEY_MINUS) )
LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_KEY_FIRST(KEY_MINUS) )
LROT_NUMENTRY( EVT_VIRTUAL_DEC_REPT, EVT_KEY_REPT(KEY_MINUS) )
LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_KEY_FIRST(KEY_PLUS) )
LROT_NUMENTRY( EVT_VIRTUAL_INC_REPT, EVT_KEY_REPT(KEY_PLUS) )
{% elif key_up %}
LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_KEY_FIRST(KEY_UP) )
LROT_NUMENTRY( EVT_VIRTUAL_PREV_REPT, EVT_KEY_REPT(KEY_UP) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_KEY_FIRST(KEY_DOWN) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_REPT, EVT_KEY_REPT(KEY_DOWN) )
LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_KEY_FIRST(KEY_DOWN) )
LROT_NUMENTRY( EVT_VIRTUAL_DEC_REPT, EVT_KEY_REPT(KEY_DOWN) )
LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_KEY_FIRST(KEY_UP) )
LROT_NUMENTRY( EVT_VIRTUAL_INC_REPT, EVT_KEY_REPT(KEY_UP) )
{% else %}
LROT_NUMENTRY( EVT_VIRTUAL_PREV, EVT_ROTARY_LEFT )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT, EVT_ROTARY_RIGHT )
LROT_NUMENTRY( EVT_VIRTUAL_DEC, EVT_ROTARY_LEFT )
LROT_NUMENTRY( EVT_VIRTUAL_INC, EVT_ROTARY_RIGHT )
LROT_NUMENTRY( ROTENC_LOWSPEED, ROTENC_LOWSPEED )
LROT_NUMENTRY( ROTENC_MIDSPEED, ROTENC_MIDSPEED )
LROT_NUMENTRY( ROTENC_HIGHSPEED, ROTENC_HIGHSPEED )
{% endif %}

{% if key_shift %}
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_LEFT) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_LONG(KEY_RIGHT) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_SHIFT) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_SHIFT) )
{% elif key_up %}
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_LEFT) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_LEFT) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_RIGHT) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_RIGHT) )
{% else %}
{% if key_page %}
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_PAGE) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGE) )
{% elif key_pageup %}
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_BREAK(KEY_PAGEUP) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGEDN) )
{% else %}
LROT_NUMENTRY( EVT_VIRTUAL_PREV_PAGE, EVT_KEY_LONG(KEY_PAGEDN) )
LROT_NUMENTRY( EVT_VIRTUAL_NEXT_PAGE, EVT_KEY_BREAK(KEY_PAGEDN) )
{% endif %}

{% if key_model %}
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_MODEL) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_MODEL) )
{% else %}
LROT_NUMENTRY( EVT_VIRTUAL_MENU, EVT_KEY_BREAK(KEY_MENU) )
LROT_NUMENTRY( EVT_VIRTUAL_MENU_LONG, EVT_KEY_LONG(KEY_MENU) )
{% endif %}
{% endif %}

LROT_NUMENTRY( EVT_VIRTUAL_ENTER, EVT_KEY_BREAK(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_ENTER_LONG, EVT_KEY_LONG(KEY_ENTER) )
LROT_NUMENTRY( EVT_VIRTUAL_EXIT, EVT_KEY_BREAK(KEY_EXIT) )


LROT_NUMENTRY( EVT_EXIT_BREAK, EVT_KEY_BREAK(KEY_EXIT) )

{% macro key_event(name, key) %}
{ "EVT_{{ name }}_FIRST", LRO_NUMVAL(EVT_KEY_FIRST({{ key }})) },
{ "EVT_{{ name }}_BREAK", LRO_NUMVAL(EVT_KEY_BREAK({{ key }})) },
{ "EVT_{{ name }}_LONG", LRO_NUMVAL(EVT_KEY_LONG({{ key }})) },
{ "EVT_{{ name }}_REPT", LRO_NUMVAL(EVT_KEY_REPT({{ key }})) },
{% endmacro %}

{{ key_event('ENTER','KEY_ENTER') }}

{% if key_menu %}
{{ key_event('MENU','KEY_MENU') }}
{% endif %}

{% if key_tele %}
{{ key_event('TELEM','KEY_TELE') }}
{% endif %}

{% if key_model %}
{{ key_event('MODEL','KEY_MODEL') }}
{% endif %}

{% if key_sys %}
{{ key_event('SYS','KEY_SYS') }}
{% endif %}

{% if key_up %}
{{ key_event('UP', 'KEY_UP') }}
{{ key_event('DOWN', 'KEY_DOWN') }}
{{ key_event('LEFT', 'KEY_LEFT') }}
{{ key_event('RIGHT', 'KEY_RIGHT') }}
{% endif %}

{% if key_page %}
{{ key_event('PAGE', 'KEY_PAGE') }}
{% endif %}

{% if key_pageup %}
{{ key_event('PAGEUP', 'KEY_PAGEUP') }}
{% endif %}

{% if key_pagedn %}
{{ key_event('PAGEDN', 'KEY_PAGEDN') }}
{% endif %}

{% if key_plus %}
{{ key_event('PLUS', 'KEY_PLUS') }}
{{ key_event('MINUS', 'KEY_MINUS') }}
{% endif %}

{% if key_shift %}
{{ key_event('SHIFT', 'KEY_SHIFT') }}
{% endif %}

{% if (not key_plus) and (not key_up) %}
{{ key_event('ROT', 'KEY_ENTER') }}
LROT_NUMENTRY( EVT_ROT_LEFT, EVT_ROTARY_LEFT )
LROT_NUMENTRY( EVT_ROT_RIGHT, EVT_ROTARY_RIGHT )
{% endif %}

0 comments on commit 6ca58c7

Please sign in to comment.