fix(bw): radio tools list may display incorrect/corrupted names (#5806)
This commit is contained in:
+4
-2
@@ -698,12 +698,14 @@ union ReusableBuffer
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(NUM_BODY_LINES)
|
#if defined(NUM_BODY_LINES)
|
||||||
|
#define TOOL_NAME_MAX_LEN (LCD_W / FW)
|
||||||
|
#define TOOL_PATH_MAX_LEN (LEN_FILE_PATH_MAX + 10)
|
||||||
struct scriptInfo{
|
struct scriptInfo{
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
char label[(LCD_W / FW) + 1];
|
char label[TOOL_NAME_MAX_LEN + 1];
|
||||||
uint8_t module;
|
uint8_t module;
|
||||||
void (* tool)(event_t);
|
void (* tool)(event_t);
|
||||||
char path[LEN_FILE_PATH_MAX+10+1];
|
char path[TOOL_PATH_MAX_LEN + 1];
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -37,64 +37,53 @@ inline bool LuaScript_compare_nocase(LuaScript first, LuaScript second)
|
|||||||
return strcasecmp(first.label.c_str(), second.label.c_str()) < 0;
|
return strcasecmp(first.label.c_str(), second.label.c_str()) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static LcdFlags dispTool(uint8_t index, const char* label)
|
static LcdFlags dispTool(uint8_t index)
|
||||||
{
|
{
|
||||||
int8_t sub = menuVerticalPosition - HEADER_LINE;
|
int8_t sub = menuVerticalPosition - HEADER_LINE;
|
||||||
LcdFlags attr = (sub == index ? INVERS : 0);
|
LcdFlags attr = (sub == index ? INVERS : 0);
|
||||||
coord_t y = MENU_HEADER_HEIGHT + (index - menuVerticalOffset) * FH;
|
coord_t y = MENU_HEADER_HEIGHT + (index - menuVerticalOffset) * FH;
|
||||||
lcdDrawNumber(3, y, index + 1, LEADING0 | LEFT, 2);
|
lcdDrawNumber(3, y, index + 1, LEADING0 | LEFT, 2);
|
||||||
lcdDrawText(3 * FW, y, reusableBuffer.radioTools.script[index].label, attr);
|
lcdDrawText(3 * FW, y, reusableBuffer.radioTools.script[index - menuVerticalOffset].label, attr);
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayRadioTool(uint8_t index)
|
void displayRadioTool(uint8_t index)
|
||||||
{
|
{
|
||||||
if (index >= menuVerticalOffset) {
|
auto attr = dispTool(index);
|
||||||
if ((index - menuVerticalOffset) < NUM_BODY_LINES) {
|
if (attr && s_editMode > 0) {
|
||||||
auto attr = dispTool(index, reusableBuffer.radioTools.script[index].label);
|
s_editMode = 0;
|
||||||
if (attr && s_editMode > 0) {
|
killAllEvents();
|
||||||
s_editMode = 0;
|
if (reusableBuffer.radioTools.script[index - menuVerticalOffset].tool != nullptr) {
|
||||||
killAllEvents();
|
g_moduleIdx = reusableBuffer.radioTools.script[index - menuVerticalOffset].module;
|
||||||
if (reusableBuffer.radioTools.script[index].tool != nullptr) {
|
pushMenu(reusableBuffer.radioTools.script[index - menuVerticalOffset].tool);
|
||||||
g_moduleIdx = reusableBuffer.radioTools.script[index].module;
|
}
|
||||||
pushMenu(reusableBuffer.radioTools.script[index].tool);
|
else if (reusableBuffer.radioTools.script[index - menuVerticalOffset].path[0]) {
|
||||||
}
|
char toolPath[FF_MAX_LFN];
|
||||||
else if (reusableBuffer.radioTools.script[index].path[0]) {
|
strcpy(toolPath, reusableBuffer.radioTools.script[index - menuVerticalOffset].path);
|
||||||
char toolPath[FF_MAX_LFN];
|
*((char *)getBasename(toolPath)-1) = '\0';
|
||||||
strcpy(toolPath, reusableBuffer.radioTools.script[index].path);
|
f_chdir(toolPath);
|
||||||
*((char *)getBasename(toolPath)-1) = '\0';
|
luaExec(reusableBuffer.radioTools.script[index - menuVerticalOffset].path);
|
||||||
f_chdir(toolPath);
|
|
||||||
luaExec(reusableBuffer.radioTools.script[index].path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addRadioTool(uint8_t index, const char * label)
|
void addRadioTool(uint8_t index, const char * label)
|
||||||
{
|
{
|
||||||
if (index >= menuVerticalOffset) {
|
strAppend(reusableBuffer.radioTools.script[index - menuVerticalOffset].label, label, TOOL_NAME_MAX_LEN);
|
||||||
if ((index - menuVerticalOffset) < NUM_BODY_LINES) {
|
auto attr = dispTool(index);
|
||||||
strncpy(reusableBuffer.radioTools.script[index].label, label, sizeof(reusableBuffer.radioTools.script[0].label));
|
if (attr && s_editMode > 0) {
|
||||||
auto attr = dispTool(index, label);
|
s_editMode = 0;
|
||||||
if (attr && s_editMode > 0) {
|
killAllEvents();
|
||||||
s_editMode = 0;
|
|
||||||
killAllEvents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addRadioModuleToolHandler(uint8_t index, const char * label, void (* tool)(event_t), uint8_t module)
|
void addRadioModuleToolHandler(uint8_t index, const char * label, void (* tool)(event_t), uint8_t module)
|
||||||
{
|
{
|
||||||
if (index >= menuVerticalOffset) {
|
if (index >= menuVerticalOffset && index < menuVerticalOffset + NUM_BODY_LINES) {
|
||||||
uint8_t lineIndex = index - menuVerticalOffset;
|
memclear(&reusableBuffer.radioTools.script[index - menuVerticalOffset], sizeof(reusableBuffer.radioTools.script[0]));
|
||||||
if (lineIndex < NUM_BODY_LINES) {
|
reusableBuffer.radioTools.script[index - menuVerticalOffset].tool = tool;
|
||||||
memclear(&reusableBuffer.radioTools.script[index], sizeof(reusableBuffer.radioTools.script[0]));
|
reusableBuffer.radioTools.script[index - menuVerticalOffset].module = module;
|
||||||
reusableBuffer.radioTools.script[index].tool = tool;
|
addRadioTool(index, label);
|
||||||
reusableBuffer.radioTools.script[index].module = module;
|
|
||||||
addRadioTool(index, label);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,9 +92,12 @@ void addRadioScriptToolHandler(std::vector<LuaScript> luaScripts)
|
|||||||
{
|
{
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
for (auto luaScript : luaScripts) {
|
for (auto luaScript : luaScripts) {
|
||||||
memclear(&reusableBuffer.radioTools.script[index], sizeof(reusableBuffer.radioTools.script[0]));
|
if (index >= menuVerticalOffset && index < menuVerticalOffset + NUM_BODY_LINES) {
|
||||||
strncpy(reusableBuffer.radioTools.script[index].path, luaScript.path.c_str(), sizeof(reusableBuffer.radioTools.script[0].path));
|
memclear(&reusableBuffer.radioTools.script[index - menuVerticalOffset], sizeof(reusableBuffer.radioTools.script[0]));
|
||||||
addRadioTool(index++, luaScript.label.c_str());
|
strAppend(reusableBuffer.radioTools.script[index - menuVerticalOffset].path, luaScript.path.c_str(), TOOL_PATH_MAX_LEN);
|
||||||
|
addRadioTool(index, luaScript.label.c_str());
|
||||||
|
}
|
||||||
|
index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -130,7 +122,9 @@ void menuRadioTools(event_t event)
|
|||||||
|
|
||||||
if (reusableBuffer.radioTools.oldOffset == menuVerticalOffset) {
|
if (reusableBuffer.radioTools.oldOffset == menuVerticalOffset) {
|
||||||
for(uint8_t line = 0; line < reusableBuffer.radioTools.linesCount; line++) {
|
for(uint8_t line = 0; line < reusableBuffer.radioTools.linesCount; line++) {
|
||||||
displayRadioTool(line);
|
if (line >= menuVerticalOffset && line < menuVerticalOffset + NUM_BODY_LINES) {
|
||||||
|
displayRadioTool(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user