optimise mavlink SS packet size (#3029)
[ExpressLRS.git] / src / lib / LUA / lua.h
bloba5605d3b992be0efdbdb8b53f9dfb740c366f50b
1 #pragma once
4 #include "targets.h"
5 #include "crsf_protocol.h"
7 enum lua_Flags{
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,
10 LUA_FLAG_STATUS1,
11 //bit 2,3,4 are warning flags, change the tittle bar every 0.5s
12 LUA_FLAG_MODEL_MATCH,
13 LUA_FLAG_ISARMED,
14 LUA_FLAG_WARNING1,
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
26 } PACKED;
28 struct tagLuaDeviceProperties {
29 uint32_t serialNo;
30 uint32_t hardwareVer;
31 uint32_t softwareVer;
32 uint8_t fieldCnt; //number of field of params this device has
33 }PACKED;
35 struct luaItem_selection {
36 struct luaPropertiesCommon common;
37 uint8_t value;
38 const char* options; // selection options, separated by ';'
39 const char* units;
40 } PACKED;
42 enum luaCmdStep_e : uint8_t {
43 lcsIdle = 0,
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
56 } PACKED;
58 struct luaPropertiesInt8 {
59 union {
60 struct {
61 uint8_t value;
62 const uint8_t min;
63 const uint8_t max;
64 } u;
65 struct {
66 int8_t value;
67 const int8_t min;
68 const int8_t max;
69 } s;
71 } PACKED;
73 struct luaItem_int8 {
74 struct luaPropertiesCommon common;
75 struct luaPropertiesInt8 properties;
76 const char* const units;
77 } PACKED;
79 struct luaPropertiesInt16 {
80 union {
81 struct {
82 uint16_t value;
83 const uint16_t min;
84 const uint16_t max;
85 } u;
86 struct {
87 int16_t value;
88 const int16_t min;
89 const int16_t max;
90 } s;
92 } PACKED;
94 struct luaItem_int16 {
95 struct luaPropertiesCommon common;
96 struct luaPropertiesInt16 properties;
97 const char* const units;
98 } PACKED;
100 struct luaPropertiesFloat {
101 // value, min, max, and def are all signed, but stored as BE unsigned
102 uint32_t value;
103 const uint32_t min;
104 const uint32_t max;
105 const uint32_t def; // default value
106 const uint8_t precision;
107 const uint32_t step;
108 } PACKED;
110 struct luaItem_float {
111 struct luaPropertiesCommon common;
112 struct luaPropertiesFloat properties;
113 const char* const units;
114 } PACKED;
116 struct luaItem_string {
117 struct luaPropertiesCommon common;
118 const char* value;
119 } PACKED;
121 struct luaItem_folder {
122 struct luaPropertiesCommon common;
123 char* dyn_name;
124 } PACKED;
126 struct tagLuaElrsParams {
127 uint8_t pktsBad;
128 uint16_t pktsGood; // Big-Endian
129 uint8_t flags;
130 char msg[1]; // null-terminated string
131 } PACKED;
133 #ifdef TARGET_TX
134 void setLuaWarningFlag(lua_Flags flag, bool value);
135 uint8_t getLuaWarningFlags(void);
137 void luaRegisterDevicePingCallback(void (*callback)());
138 #endif
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"