LCOV - code coverage report
Current view: top level - AP_Scripting - AP_Scripting_CRSFMenu.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 79 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 10 0.0 %

          Line data    Source code
       1             : #include "AP_Scripting_config.h"
       2             : 
       3             : #if AP_SCRIPTING_ENABLED
       4             : 
       5             : #include "AP_Scripting_CRSFMenu.h"
       6             : 
       7             : #if AP_CRSF_SCRIPTING_ENABLED
       8             : 
       9             : #include <AP_Scripting/lua_generated_bindings.h>
      10             : 
      11           0 : AP_CRSF_Telem::ScriptedParameter* CRSFMenu::add_parameter(uint8_t length, const char* data)
      12             : {
      13           0 :     return menu->add_parameter(length, data);
      14             : }
      15             : 
      16           0 : AP_CRSF_Telem::ScriptedMenu* CRSFMenu::add_menu(const char* menu_name)
      17             : {
      18           0 :     return menu->add_menu(menu_name, 2, menu->id);
      19             : }
      20             : 
      21           0 : int lua_CRSF_new_menu(lua_State *L)
      22             : {
      23           0 :     binding_argcheck(L, 1);
      24             : 
      25           0 :     const char * name = luaL_checkstring(L, 1);
      26             : 
      27             :     // create Lua object first in case of errors so we don't leak the menu
      28           0 :     auto *m = new_CRSFMenu(L);
      29             : 
      30           0 :     AP_CRSF_Telem::ScriptedMenu* menu = AP::crsf_telem()->add_menu(name);
      31             : 
      32           0 :     if (menu == nullptr) {
      33           0 :         return luaL_error(L, "out of memory");
      34             :     }
      35             : 
      36           0 :     *m = CRSFMenu(menu);
      37             : 
      38           0 :     return 1;
      39             : }
      40             : 
      41           0 : int lua_CRSF_get_menu_event(lua_State *L)
      42             : {
      43           0 :     binding_argcheck(L, 2);
      44             : 
      45           0 :     const uint8_t events = get_uint8_t(L, 2);
      46           0 :     uint8_t param = 0;
      47           0 :     AP_CRSF_Telem::ScriptedPayload payload {};
      48           0 :     const uint8_t data = static_cast<uint8_t>(AP::crsf_telem()->get_menu_event(
      49             :             events,
      50             :             param,
      51             :             payload));
      52             : 
      53             : #if 3 > LUA_MINSTACK
      54             :     luaL_checkstack(L, 3, nullptr);
      55             : #endif
      56             : 
      57           0 :     lua_pushinteger(L, param);
      58           0 :     lua_pushlstring(L, (const char*)payload.payload, payload.payload_length);
      59           0 :     lua_pushinteger(L, data);
      60           0 :     return 3;
      61             : }
      62             : 
      63           0 : int lua_CRSF_peek_menu_event(lua_State *L)
      64             : {
      65           0 :     binding_argcheck(L, 1);
      66             : 
      67           0 :     uint8_t param = 0;
      68           0 :     uint8_t events = 0;
      69           0 :     AP_CRSF_Telem::ScriptedPayload payload {};
      70           0 :     const uint8_t count = AP::crsf_telem()->peek_menu_event(param, payload, events);
      71             : 
      72             : #if 4 > LUA_MINSTACK
      73             :     luaL_checkstack(L, 4, nullptr);
      74             : #endif
      75             : 
      76           0 :     lua_pushinteger(L, count);
      77           0 :     lua_pushinteger(L, param);
      78           0 :     lua_pushlstring(L, (const char*)payload.payload, payload.payload_length);
      79           0 :     lua_pushinteger(L, events);
      80           0 :     return 4;
      81             : }
      82             : 
      83           0 : int lua_CRSF_send_response(lua_State *L)
      84             : {
      85           0 :     binding_argcheck(L, 2);
      86             : 
      87           0 :     size_t len = 0;
      88           0 :     const char * payload= luaL_checklstring(L, 2, &len);
      89           0 :     const bool data = static_cast<bool>(AP::crsf_telem()->send_write_response(
      90             :             len,
      91             :             payload));
      92             : 
      93           0 :     lua_pushboolean(L, data);
      94           0 :     return 1;
      95             : }
      96             : 
      97           0 : int lua_CRSF_add_parameter(lua_State *L)
      98             : {
      99           0 :     binding_argcheck(L, 2);
     100             : 
     101           0 :     CRSFMenu* ud = check_CRSFMenu(L, 1);
     102           0 :     size_t len = 0;
     103           0 :     const char * data = luaL_checklstring(L, 2, &len);
     104             : 
     105             :     // create Lua object first in case of errors so we don't leak the param
     106           0 :     auto *p = new_CRSFParameter(L);
     107             : 
     108           0 :     AP_CRSF_Telem::ScriptedParameter* param = ud->add_parameter(len, data);
     109             : 
     110           0 :     if (param) {
     111           0 :         *p = CRSFParameter(ud->get_menu(), param);
     112           0 :         return 1;
     113             :     }
     114           0 :     return 0;
     115             : }
     116             : 
     117           0 : int lua_CRSF_add_menu(lua_State *L)
     118             : {
     119           0 :     binding_argcheck(L, 2);
     120             : 
     121           0 :     CRSFMenu* ud = check_CRSFMenu(L, 1);
     122           0 :     const char * name = luaL_checkstring(L, 2);
     123             : 
     124             :     // create Lua object first in case of errors so we don't leak the menu
     125           0 :     auto *m = new_CRSFMenu(L);
     126             : 
     127           0 :     AP_CRSF_Telem::ScriptedMenu* menu = ud->add_menu(name);
     128             : 
     129           0 :     if (menu) {
     130           0 :         *m = CRSFMenu(menu);
     131           0 :         return 1;
     132             :     }
     133           0 :     return 0;
     134             : }
     135             : 
     136           0 : int lua_CRSF_add_root_menu(lua_State *L)
     137             : {
     138           0 :     binding_argcheck(L, 2);
     139             : 
     140           0 :     const char * name = luaL_checkstring(L, 2);
     141             : 
     142             :     // create Lua object first in case of errors so we don't leak the menu
     143           0 :     auto *m = new_CRSFMenu(L);
     144             : 
     145           0 :     AP_CRSF_Telem::ScriptedMenu* menu = AP::crsf_telem()->add_menu(name);
     146             : 
     147           0 :     if (menu) {
     148           0 :         *m = CRSFMenu(menu);
     149           0 :         return 1;
     150             :     }
     151           0 :     return 0;
     152             : }
     153             : 
     154           0 : int lua_CRSF_param_data(lua_State *L)
     155             : {
     156           0 :     binding_argcheck(L, 1);
     157             : 
     158           0 :     CRSFParameter * ud = check_CRSFParameter(L, 1);
     159           0 :     AP_CRSF_Telem::ScriptedParameter* param = ud->get_parameter();
     160           0 :     if (param == nullptr) {
     161           0 :         return luaL_error(L, "internal error: %s is null", "CRSFParameter");
     162             :     }
     163             : 
     164           0 :     lua_pushlstring(L, param->data, param->length);
     165           0 :     return 1;
     166             : }
     167             : 
     168             : #endif // AP_CRSF_SCRIPTING_ENABLED
     169             : #endif // AP_SCRIPTING_ENABLED

Generated by: LCOV version 1.14