forked from ExpressLRS/ExpressLRS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lua.h
156 lines (133 loc) · 4.39 KB
/
lua.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#pragma once
#include "targets.h"
#include "crsf_protocol.h"
#include <functional>
enum lua_Flags{
//bit 0 and 1 are status flags, show up as the little icon in the lua top right corner
LUA_FLAG_CONNECTED = 0,
LUA_FLAG_STATUS1,
//bit 2,3,4 are warning flags, change the tittle bar every 0.5s
LUA_FLAG_MODEL_MATCH,
LUA_FLAG_ISARMED,
LUA_FLAG_WARNING1,
//bit 5,6,7 are critical warning flag, block the lua screen until user confirm to suppress the warning.
LUA_FLAG_ERROR_CONNECTED,
LUA_FLAG_CRITICAL_WARNING1,
LUA_FLAG_CRITICAL_WARNING2,
};
struct luaPropertiesCommon {
const char* const name; // display name
const crsf_value_type_e type;
uint8_t id; // Sequential id assigned by enumeration
uint8_t parent; // id of parent folder
} PACKED;
struct tagLuaDeviceProperties {
uint32_t serialNo;
uint32_t hardwareVer;
uint32_t softwareVer;
uint8_t fieldCnt; //number of field of params this device has
}PACKED;
struct luaItem_selection {
struct luaPropertiesCommon common;
uint8_t value;
const char* options; // selection options, separated by ';'
const char* units;
} PACKED;
enum luaCmdStep_e : uint8_t {
lcsIdle = 0,
lcsClick = 1, // user has clicked the command to execute
lcsExecuting = 2, // command is executing
lcsAskConfirm = 3, // command pending user OK
lcsConfirmed = 4, // user has confirmed
lcsCancel = 5, // user has requested cancel
lcsQuery = 6, // UI is requesting status update
};
struct luaItem_command {
struct luaPropertiesCommon common;
luaCmdStep_e step; // state
const char *info; // status info to display
} PACKED;
struct luaPropertiesInt8 {
union {
struct {
int8_t value;
const int8_t min;
const int8_t max;
} s;
struct {
uint8_t value;
const uint8_t min;
const uint8_t max;
} u;
};
} PACKED;
struct luaItem_int8 {
struct luaPropertiesCommon common;
struct luaPropertiesInt8 properties;
const char* const units;
} PACKED;
struct luaPropertiesInt16 {
union {
struct {
int16_t value;
const int16_t min;
const int16_t max;
} s;
struct {
uint16_t value;
const uint16_t min;
const uint16_t max;
} u;
};
}PACKED;
struct luaItem_int16 {
struct luaPropertiesCommon common;
struct luaPropertiesInt16 properties;
const char* const units;
} PACKED;
struct luaItem_string {
const struct luaPropertiesCommon common;
const char* value;
} PACKED;
struct luaItem_folder {
const struct luaPropertiesCommon common;
char* dyn_name;
} PACKED;
struct tagLuaElrsParams {
uint8_t pktsBad;
uint16_t pktsGood; // Big-Endian
uint8_t flags;
char msg[1]; // null-terminated string
} PACKED;
#ifdef TARGET_TX
void setLuaWarningFlag(lua_Flags flag, bool value);
uint8_t getLuaWarningFlags(void);
void luaRegisterDevicePingCallback(void (*callback)());
#endif
void sendLuaCommandResponse(struct luaItem_command *cmd, luaCmdStep_e step, const char *message);
extern void ICACHE_RAM_ATTR luaParamUpdateReq();
extern bool luaHandleUpdateParameter();
typedef void (*luaCallback)(struct luaPropertiesCommon *item, uint8_t arg);
void registerLUAParameter(void *definition, luaCallback callback = nullptr, uint8_t parent = 0);
uint8_t findLuaSelectionLabel(const void *luaStruct, char *outarray, uint8_t value);
void sendLuaDevicePacket(void);
inline void setLuaTextSelectionValue(struct luaItem_selection *luaStruct, uint8_t newvalue) {
luaStruct->value = newvalue;
}
inline void setLuaUint8Value(struct luaItem_int8 *luaStruct, uint8_t newvalue) {
luaStruct->properties.u.value = newvalue;
}
inline void setLuaInt8Value(struct luaItem_int8 *luaStruct, int8_t newvalue) {
luaStruct->properties.s.value = newvalue;
}
inline void setLuaUint16Value(struct luaItem_int16 *luaStruct, uint16_t newvalue) {
luaStruct->properties.u.value = (newvalue >> 8) | (newvalue << 8);
}
inline void setLuaInt16Value(struct luaItem_int16 *luaStruct, int16_t newvalue) {
luaStruct->properties.s.value = (newvalue >> 8) | (newvalue << 8);
}
inline void setLuaStringValue(struct luaItem_string *luaStruct, const char *newvalue) {
luaStruct->value = newvalue;
}
#define LUASYM_ARROW_UP "\xc0"
#define LUASYM_ARROW_DN "\xc1"