5 #include "crsf_protocol.h"
8 //bit 0 and 1 are status flags, show up as the little icon in the lua top right corner
9 LUA_FLAG_CONNECTED
= 0,
11 //bit 2,3,4 are warning flags, change the tittle bar every 0.5s
15 //bit 5,6,7 are critical warning flag, block the lua screen until user confirm to suppress the warning.
16 LUA_FLAG_ERROR_CONNECTED
,
17 LUA_FLAG_ERROR_BAUDRATE
,
18 LUA_FLAG_CRITICAL_WARNING2
,
21 struct luaPropertiesCommon
{
22 const char* name
; // display name
23 crsf_value_type_e type
;
24 uint8_t id
; // Sequential id assigned by enumeration
25 uint8_t parent
; // id of parent folder
28 struct tagLuaDeviceProperties
{
32 uint8_t fieldCnt
; //number of field of params this device has
35 struct luaItem_selection
{
36 struct luaPropertiesCommon common
;
38 const char* options
; // selection options, separated by ';'
42 enum luaCmdStep_e
: uint8_t {
44 lcsClick
= 1, // user has clicked the command to execute
45 lcsExecuting
= 2, // command is executing
46 lcsAskConfirm
= 3, // command pending user OK
47 lcsConfirmed
= 4, // user has confirmed
48 lcsCancel
= 5, // user has requested cancel
49 lcsQuery
= 6, // UI is requesting status update
52 struct luaItem_command
{
53 struct luaPropertiesCommon common
;
54 luaCmdStep_e step
; // state
55 const char *info
; // status info to display
58 struct luaPropertiesInt8
{
74 struct luaPropertiesCommon common
;
75 struct luaPropertiesInt8 properties
;
76 const char* const units
;
79 struct luaPropertiesInt16
{
94 struct luaItem_int16
{
95 struct luaPropertiesCommon common
;
96 struct luaPropertiesInt16 properties
;
97 const char* const units
;
100 struct luaPropertiesFloat
{
101 // value, min, max, and def are all signed, but stored as BE unsigned
105 const uint32_t def
; // default value
106 const uint8_t precision
;
110 struct luaItem_float
{
111 struct luaPropertiesCommon common
;
112 struct luaPropertiesFloat properties
;
113 const char* const units
;
116 struct luaItem_string
{
117 struct luaPropertiesCommon common
;
121 struct luaItem_folder
{
122 struct luaPropertiesCommon common
;
126 struct tagLuaElrsParams
{
128 uint16_t pktsGood
; // Big-Endian
130 char msg
[1]; // null-terminated string
134 void setLuaWarningFlag(lua_Flags flag
, bool value
);
135 uint8_t getLuaWarningFlags(void);
137 void luaRegisterDevicePingCallback(void (*callback
)());
140 #define LUA_FIELD_HIDE(fld) { fld.common.type = (crsf_value_type_e)((uint8_t)fld.common.type | CRSF_FIELD_HIDDEN); }
141 #define LUA_FIELD_SHOW(fld) { fld.common.type = (crsf_value_type_e)((uint8_t)fld.common.type & ~CRSF_FIELD_HIDDEN); }
143 void sendLuaCommandResponse(struct luaItem_command
*cmd
, luaCmdStep_e step
, const char *message
);
145 extern void luaParamUpdateReq(uint8_t type
, uint8_t index
, uint8_t arg
);
146 extern bool luaHandleUpdateParameter();
148 typedef void (*luaCallback
)(struct luaPropertiesCommon
*item
, uint8_t arg
);
149 void registerLUAParameter(void *definition
, luaCallback callback
= nullptr, uint8_t parent
= 0);
151 uint8_t findLuaSelectionLabel(const void *luaStruct
, char *outarray
, uint8_t value
);
153 void sendLuaDevicePacket(void);
154 inline void setLuaTextSelectionValue(struct luaItem_selection
*luaStruct
, uint8_t newvalue
) {
155 luaStruct
->value
= newvalue
;
157 inline void setLuaUint8Value(struct luaItem_int8
*luaStruct
, uint8_t newvalue
) {
158 luaStruct
->properties
.u
.value
= newvalue
;
160 inline void setLuaInt8Value(struct luaItem_int8
*luaStruct
, int8_t newvalue
) {
161 luaStruct
->properties
.s
.value
= newvalue
;
163 inline void setLuaUint16Value(struct luaItem_int16
*luaStruct
, uint16_t newvalue
) {
164 luaStruct
->properties
.u
.value
= htobe16(newvalue
);
166 inline void setLuaInt16Value(struct luaItem_int16
*luaStruct
, int16_t newvalue
) {
167 luaStruct
->properties
.u
.value
= htobe16((uint16_t)newvalue
);
169 inline void setLuaFloatValue(struct luaItem_float
*luaStruct
, int32_t newvalue
) {
170 luaStruct
->properties
.value
= htobe32((uint32_t)newvalue
);
172 inline void setLuaStringValue(struct luaItem_string
*luaStruct
, const char *newvalue
) {
173 luaStruct
->value
= newvalue
;
176 #define LUASYM_ARROW_UP "\xc0"
177 #define LUASYM_ARROW_DN "\xc1"