@@ -37,64 +37,53 @@ 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
- static LcdFlags dispTool (uint8_t index, const char * label )
40
+ static LcdFlags dispTool (uint8_t index)
41
41
{
42
42
int8_t sub = menuVerticalPosition - HEADER_LINE;
43
43
LcdFlags attr = (sub == index ? INVERS : 0 );
44
44
coord_t y = MENU_HEADER_HEIGHT + (index - menuVerticalOffset) * FH;
45
45
lcdDrawNumber (3 , y, index + 1 , LEADING0 | LEFT, 2 );
46
- lcdDrawText (3 * FW, y, reusableBuffer.radioTools .script [index ].label , attr);
46
+ lcdDrawText (3 * FW, y, reusableBuffer.radioTools .script [index - menuVerticalOffset ].label , attr);
47
47
return attr;
48
48
}
49
49
50
50
void displayRadioTool (uint8_t index)
51
51
{
52
- if (index >= menuVerticalOffset) {
53
- if ((index - menuVerticalOffset) < NUM_BODY_LINES) {
54
- auto attr = dispTool (index , reusableBuffer.radioTools .script [index ].label );
55
- if (attr && s_editMode > 0 ) {
56
- s_editMode = 0 ;
57
- killAllEvents ();
58
- if (reusableBuffer.radioTools .script [index ].tool != nullptr ) {
59
- g_moduleIdx = reusableBuffer.radioTools .script [index ].module ;
60
- pushMenu (reusableBuffer.radioTools .script [index ].tool );
61
- }
62
- else if (reusableBuffer.radioTools .script [index ].path [0 ]) {
63
- char toolPath[FF_MAX_LFN];
64
- strcpy (toolPath, reusableBuffer.radioTools .script [index ].path );
65
- *((char *)getBasename (toolPath)-1 ) = ' \0 ' ;
66
- f_chdir (toolPath);
67
- luaExec (reusableBuffer.radioTools .script [index ].path );
68
- }
69
- }
52
+ auto attr = dispTool (index );
53
+ if (attr && s_editMode > 0 ) {
54
+ s_editMode = 0 ;
55
+ killAllEvents ();
56
+ if (reusableBuffer.radioTools .script [index - menuVerticalOffset].tool != nullptr ) {
57
+ g_moduleIdx = reusableBuffer.radioTools .script [index - menuVerticalOffset].module ;
58
+ pushMenu (reusableBuffer.radioTools .script [index - menuVerticalOffset].tool );
59
+ }
60
+ else if (reusableBuffer.radioTools .script [index - menuVerticalOffset].path [0 ]) {
61
+ char toolPath[FF_MAX_LFN];
62
+ strcpy (toolPath, reusableBuffer.radioTools .script [index - menuVerticalOffset].path );
63
+ *((char *)getBasename (toolPath)-1 ) = ' \0 ' ;
64
+ f_chdir (toolPath);
65
+ luaExec (reusableBuffer.radioTools .script [index - menuVerticalOffset].path );
70
66
}
71
67
}
72
68
}
73
69
74
70
void addRadioTool (uint8_t index, const char * label)
75
71
{
76
- if (index >= menuVerticalOffset) {
77
- if ((index - menuVerticalOffset) < NUM_BODY_LINES) {
78
- strncpy (reusableBuffer.radioTools .script [index ].label , label, sizeof (reusableBuffer.radioTools .script [0 ].label ));
79
- auto attr = dispTool (index , label);
80
- if (attr && s_editMode > 0 ) {
81
- s_editMode = 0 ;
82
- killAllEvents ();
83
- }
84
- }
72
+ strAppend (reusableBuffer.radioTools .script [index - menuVerticalOffset].label , label, TOOL_NAME_MAX_LEN);
73
+ auto attr = dispTool (index );
74
+ if (attr && s_editMode > 0 ) {
75
+ s_editMode = 0 ;
76
+ killAllEvents ();
85
77
}
86
78
}
87
79
88
80
void addRadioModuleToolHandler (uint8_t index, const char * label, void (* tool)(event_t ), uint8_t module)
89
81
{
90
- if (index >= menuVerticalOffset) {
91
- uint8_t lineIndex = index - menuVerticalOffset;
92
- if (lineIndex < NUM_BODY_LINES) {
93
- memclear (&reusableBuffer.radioTools .script [index ], sizeof (reusableBuffer.radioTools .script [0 ]));
94
- reusableBuffer.radioTools .script [index ].tool = tool;
95
- reusableBuffer.radioTools .script [index ].module = module;
96
- addRadioTool (index , label);
97
- }
82
+ if (index >= menuVerticalOffset && index < menuVerticalOffset + NUM_BODY_LINES) {
83
+ memclear (&reusableBuffer.radioTools .script [index - menuVerticalOffset], sizeof (reusableBuffer.radioTools .script [0 ]));
84
+ reusableBuffer.radioTools .script [index - menuVerticalOffset].tool = tool;
85
+ reusableBuffer.radioTools .script [index - menuVerticalOffset].module = module;
86
+ addRadioTool (index , label);
98
87
}
99
88
}
100
89
@@ -103,9 +92,12 @@ void addRadioScriptToolHandler(std::vector<LuaScript> luaScripts)
103
92
{
104
93
uint8_t index = 0 ;
105
94
for (auto luaScript : luaScripts) {
106
- memclear (&reusableBuffer.radioTools .script [index ], sizeof (reusableBuffer.radioTools .script [0 ]));
107
- strncpy (reusableBuffer.radioTools .script [index ].path , luaScript.path .c_str (), sizeof (reusableBuffer.radioTools .script [0 ].path ));
108
- addRadioTool (index ++, luaScript.label .c_str ());
95
+ if (index >= menuVerticalOffset && index < menuVerticalOffset + NUM_BODY_LINES) {
96
+ memclear (&reusableBuffer.radioTools .script [index - menuVerticalOffset], sizeof (reusableBuffer.radioTools .script [0 ]));
97
+ strAppend (reusableBuffer.radioTools .script [index - menuVerticalOffset].path , luaScript.path .c_str (), TOOL_PATH_MAX_LEN);
98
+ addRadioTool (index , luaScript.label .c_str ());
99
+ }
100
+ index += 1 ;
109
101
}
110
102
}
111
103
#endif
@@ -130,7 +122,9 @@ void menuRadioTools(event_t event)
130
122
131
123
if (reusableBuffer.radioTools .oldOffset == menuVerticalOffset) {
132
124
for (uint8_t line = 0 ; line < reusableBuffer.radioTools .linesCount ; line++) {
133
- displayRadioTool (line);
125
+ if (line >= menuVerticalOffset && line < menuVerticalOffset + NUM_BODY_LINES) {
126
+ displayRadioTool (line);
127
+ }
134
128
}
135
129
return ;
136
130
}
0 commit comments