@@ -37,6 +37,39 @@ inline bool LuaScript_compare_nocase(LuaScript first, LuaScript second)
37
37
return strcasecmp (first.label .c_str (), second.label .c_str ()) < 0 ;
38
38
}
39
39
40
+ void displayRadioTool (uint8_t index)
41
+ {
42
+ if (index >= menuVerticalOffset) {
43
+ uint8_t lineIndex = index - menuVerticalOffset;
44
+ if (lineIndex < NUM_BODY_LINES) {
45
+ int8_t sub = menuVerticalPosition - HEADER_LINE;
46
+ LcdFlags attr = (sub == index ? INVERS : 0 );
47
+ coord_t y = MENU_HEADER_HEIGHT + lineIndex * FH;
48
+ lcdDrawNumber (3 , y, index + 1 , LEADING0 | LEFT, 2 );
49
+ lcdDrawText (3 * FW, y, reusableBuffer.radioTools .script [index].label , (sub == index ? INVERS : 0 ));
50
+ if (attr && s_editMode > 0 ) {
51
+ s_editMode = 0 ;
52
+ killAllEvents ();
53
+ if (reusableBuffer.radioTools .script [index].tool != nullptr ) {
54
+ g_moduleIdx = reusableBuffer.radioTools .script [index].module ;
55
+ pushMenu (reusableBuffer.radioTools .script [index].tool );
56
+ }
57
+ else if (reusableBuffer.radioTools .script [index].path != nullptr ) {
58
+ char toolName[RADIO_TOOL_NAME_MAXLEN + 1 ];
59
+ if (!readToolName (toolName, reusableBuffer.radioTools .script [index].path )) {
60
+ strAppendFilename (toolName, getBasename (reusableBuffer.radioTools .script [index].path ), RADIO_TOOL_NAME_MAXLEN);
61
+ }
62
+ char toolPath[FF_MAX_LFN];
63
+ strcpy (toolPath, reusableBuffer.radioTools .script [index].path );
64
+ *((char *)getBasename (toolPath)-1 ) = ' \0 ' ;
65
+ f_chdir (toolPath);
66
+ luaExec (reusableBuffer.radioTools .script [index].path );
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+
40
73
bool addRadioTool (uint8_t index, const char * label)
41
74
{
42
75
if (index >= menuVerticalOffset) {
@@ -57,6 +90,20 @@ bool addRadioTool(uint8_t index, const char * label)
57
90
return false ;
58
91
}
59
92
93
+ void addRadioModuleToolHandler (uint8_t index, const char * label, void (* tool)(event_t ), uint8_t module)
94
+ {
95
+ if (index >= menuVerticalOffset) {
96
+ uint8_t lineIndex = index - menuVerticalOffset;
97
+ if (lineIndex < NUM_BODY_LINES) {
98
+ memclear (&reusableBuffer.radioTools .script [index], sizeof (reusableBuffer.radioTools .script [0 ]));
99
+ strncpy (reusableBuffer.radioTools .script [index].label , label, sizeof (reusableBuffer.radioTools .script [0 ]));
100
+ reusableBuffer.radioTools .script [index].tool = tool;
101
+ reusableBuffer.radioTools .script [index].module = module ;
102
+ }
103
+ }
104
+ addRadioTool (index, label);
105
+ }
106
+
60
107
void addRadioModuleTool (uint8_t index, const char * label, void (* tool)(event_t ), uint8_t module)
61
108
{
62
109
if (addRadioTool (index, label)) {
@@ -97,12 +144,36 @@ void addRadioScriptTool(uint8_t index, const char * path)
97
144
luaExec (path);
98
145
}
99
146
}
147
+
148
+ void addRadioScriptToolHandler (std::vector<LuaScript> luaScripts)
149
+ {
150
+ uint8_t index = 0 ;
151
+ for (auto luaScript : luaScripts) {
152
+ memclear (&reusableBuffer.radioTools .script [index], sizeof (reusableBuffer.radioTools .script [0 ]));
153
+ strncpy (reusableBuffer.radioTools .script [index].path , luaScript.path .c_str (), sizeof (reusableBuffer.radioTools .script [0 ].path ));
154
+ strncpy (reusableBuffer.radioTools .script [index].label , luaScript.label .c_str (), sizeof (reusableBuffer.radioTools .script [0 ].label ));
155
+ addRadioTool (index++, luaScript.label .c_str ());
156
+ }
157
+ }
158
+
159
+ void addRadioScriptToolHandler (uint8_t index, const char * path)
160
+ {
161
+ if (index >= menuVerticalOffset) {
162
+ uint8_t lineIndex = index - menuVerticalOffset;
163
+ if (lineIndex < NUM_BODY_LINES) {
164
+ memclear (&reusableBuffer.radioTools .script [index], sizeof (reusableBuffer.radioTools .script [0 ]));
165
+ strncpy (reusableBuffer.radioTools .script [index].path , path, sizeof (reusableBuffer.radioTools .script [0 ].path ));
166
+ }
167
+ addRadioScriptTool (index, path);
168
+ }
169
+ }
100
170
#endif
101
171
102
172
void menuRadioTools (event_t event)
103
173
{
104
174
if (event == EVT_ENTRY || event == EVT_ENTRY_UP) {
105
175
memclear (&reusableBuffer.radioTools , sizeof (reusableBuffer.radioTools ));
176
+ reusableBuffer.radioTools .oldOffset = 0xFF ;
106
177
#if defined(PXX2)
107
178
for (uint8_t module = 0 ; module < NUM_MODULES; module ++) {
108
179
if (isModulePXX2 (module ) && (module == INTERNAL_MODULE ? modulePortPowered (INTERNAL_MODULE) : modulePortPowered (EXTERNAL_MODULE))) {
@@ -116,6 +187,13 @@ void menuRadioTools(event_t event)
116
187
117
188
uint8_t index = 0 ;
118
189
190
+ if (reusableBuffer.radioTools .oldOffset == menuVerticalOffset) {
191
+ for (uint8_t line =0 ; line < reusableBuffer.radioTools .linesCount ; line++) {
192
+ displayRadioTool (line);
193
+ }
194
+ return ;
195
+ }
196
+
119
197
#if defined(LUA)
120
198
FILINFO fno;
121
199
DIR dir;
@@ -150,22 +228,22 @@ void menuRadioTools(event_t event)
150
228
f_closedir (&dir);
151
229
152
230
std::sort (luaScripts.begin (), luaScripts.end (), LuaScript_compare_nocase);
153
- addRadioScriptTool (luaScripts);
231
+ addRadioScriptToolHandler (luaScripts);
154
232
index += luaScripts.size ();
155
233
}
156
234
#endif
157
235
158
236
#if defined(INTERNAL_MODULE_PXX2)
159
237
if (isPXX2ModuleOptionAvailable (reusableBuffer.radioTools .modules [INTERNAL_MODULE].information .modelID , MODULE_OPTION_SPECTRUM_ANALYSER))
160
- addRadioModuleTool (index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
238
+ addRadioModuleToolHandler (index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
161
239
162
240
if (isPXX2ModuleOptionAvailable (reusableBuffer.radioTools .modules [INTERNAL_MODULE].information .modelID , MODULE_OPTION_POWER_METER))
163
- addRadioModuleTool (index++, STR_POWER_METER_INT, menuRadioPowerMeter, INTERNAL_MODULE);
241
+ addRadioModuleToolHandler (index++, STR_POWER_METER_INT, menuRadioPowerMeter, INTERNAL_MODULE);
164
242
#endif
165
243
166
244
#if defined(HARDWARE_INTERNAL_MODULE) && defined(MULTIMODULE)
167
245
if (g_eeGeneral.internalModule == MODULE_TYPE_MULTIMODULE)
168
- addRadioModuleTool (index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
246
+ addRadioModuleToolHandler (index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
169
247
#endif
170
248
171
249
#if defined(HARDWARE_EXTERNAL_MODULE)
@@ -181,16 +259,16 @@ void menuRadioTools(event_t event)
181
259
has_spectrum_analyser = true ;
182
260
#endif
183
261
if (has_spectrum_analyser)
184
- addRadioModuleTool (index++, STR_SPECTRUM_ANALYSER_EXT, menuRadioSpectrumAnalyser, EXTERNAL_MODULE);
262
+ addRadioModuleToolHandler (index++, STR_SPECTRUM_ANALYSER_EXT, menuRadioSpectrumAnalyser, EXTERNAL_MODULE);
185
263
#endif
186
264
#if defined(PXX2)
187
265
if (isPXX2ModuleOptionAvailable (reusableBuffer.radioTools .modules [EXTERNAL_MODULE].information .modelID , MODULE_OPTION_POWER_METER))
188
- addRadioModuleTool (index++, STR_POWER_METER_EXT, menuRadioPowerMeter, EXTERNAL_MODULE);
266
+ addRadioModuleToolHandler (index++, STR_POWER_METER_EXT, menuRadioPowerMeter, EXTERNAL_MODULE);
189
267
#endif
190
268
191
269
#if defined(GHOST)
192
270
if (isModuleGhost (EXTERNAL_MODULE))
193
- addRadioModuleTool (index++, " Ghost Menu" , menuGhostModuleConfig, EXTERNAL_MODULE);
271
+ addRadioModuleToolHandler (index++, " Ghost Menu" , menuGhostModuleConfig, EXTERNAL_MODULE);
194
272
#endif
195
273
196
274
#endif
@@ -200,4 +278,5 @@ void menuRadioTools(event_t event)
200
278
}
201
279
202
280
reusableBuffer.radioTools .linesCount = index;
281
+ reusableBuffer.radioTools .oldOffset = menuVerticalOffset;
203
282
}
0 commit comments