feat: dramatically reduce SD card access while in Tools screen (#5721)
This commit is contained in:
@@ -701,7 +701,21 @@ union ReusableBuffer
|
|||||||
PXX2HardwareAndSettings hardwareAndSettings; // radio_version
|
PXX2HardwareAndSettings hardwareAndSettings; // radio_version
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(NUM_BODY_LINES)
|
||||||
|
struct scriptInfo{
|
||||||
|
uint8_t index;
|
||||||
|
char label[(LCD_W / FW) + 1];
|
||||||
|
uint8_t module;
|
||||||
|
void (* tool)(event_t);
|
||||||
|
char path[LEN_FILE_PATH_MAX+10+1];
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
#if defined(NUM_BODY_LINES)
|
||||||
|
scriptInfo script[NUM_BODY_LINES];
|
||||||
|
uint8_t oldOffset;
|
||||||
|
#endif
|
||||||
#if defined(PXX2)
|
#if defined(PXX2)
|
||||||
ModuleInformation modules[NUM_MODULES];
|
ModuleInformation modules[NUM_MODULES];
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -37,6 +37,39 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void displayRadioTool(uint8_t index)
|
||||||
|
{
|
||||||
|
if (index >= menuVerticalOffset) {
|
||||||
|
uint8_t lineIndex = index - menuVerticalOffset;
|
||||||
|
if (lineIndex < NUM_BODY_LINES) {
|
||||||
|
int8_t sub = menuVerticalPosition - HEADER_LINE;
|
||||||
|
LcdFlags attr = (sub == index ? INVERS : 0);
|
||||||
|
coord_t y = MENU_HEADER_HEIGHT + lineIndex * FH;
|
||||||
|
lcdDrawNumber(3, y, index + 1, LEADING0 | LEFT, 2);
|
||||||
|
lcdDrawText(3 * FW, y, reusableBuffer.radioTools.script[index].label, (sub == index ? INVERS : 0));
|
||||||
|
if (attr && s_editMode > 0) {
|
||||||
|
s_editMode = 0;
|
||||||
|
killAllEvents();
|
||||||
|
if (reusableBuffer.radioTools.script[index].tool != nullptr) {
|
||||||
|
g_moduleIdx = reusableBuffer.radioTools.script[index].module;
|
||||||
|
pushMenu(reusableBuffer.radioTools.script[index].tool);
|
||||||
|
}
|
||||||
|
else if (reusableBuffer.radioTools.script[index].path != nullptr) {
|
||||||
|
char toolName[RADIO_TOOL_NAME_MAXLEN + 1];
|
||||||
|
if (!readToolName(toolName, reusableBuffer.radioTools.script[index].path)) {
|
||||||
|
strAppendFilename(toolName, getBasename(reusableBuffer.radioTools.script[index].path), RADIO_TOOL_NAME_MAXLEN);
|
||||||
|
}
|
||||||
|
char toolPath[FF_MAX_LFN];
|
||||||
|
strcpy(toolPath, reusableBuffer.radioTools.script[index].path);
|
||||||
|
*((char *)getBasename(toolPath)-1) = '\0';
|
||||||
|
f_chdir(toolPath);
|
||||||
|
luaExec(reusableBuffer.radioTools.script[index].path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool addRadioTool(uint8_t index, const char * label)
|
bool addRadioTool(uint8_t index, const char * label)
|
||||||
{
|
{
|
||||||
if (index >= menuVerticalOffset) {
|
if (index >= menuVerticalOffset) {
|
||||||
@@ -57,6 +90,20 @@ bool addRadioTool(uint8_t index, const char * label)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addRadioModuleToolHandler(uint8_t index, const char * label, void (* tool)(event_t), uint8_t module)
|
||||||
|
{
|
||||||
|
if (index >= menuVerticalOffset) {
|
||||||
|
uint8_t lineIndex = index - menuVerticalOffset;
|
||||||
|
if (lineIndex < NUM_BODY_LINES) {
|
||||||
|
memclear(&reusableBuffer.radioTools.script[index], sizeof(reusableBuffer.radioTools.script[0]));
|
||||||
|
strncpy(reusableBuffer.radioTools.script[index].label, label, sizeof(reusableBuffer.radioTools.script[0]));
|
||||||
|
reusableBuffer.radioTools.script[index].tool = tool;
|
||||||
|
reusableBuffer.radioTools.script[index].module = module;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addRadioTool(index, label);
|
||||||
|
}
|
||||||
|
|
||||||
void addRadioModuleTool(uint8_t index, const char * label, void (* tool)(event_t), uint8_t module)
|
void addRadioModuleTool(uint8_t index, const char * label, void (* tool)(event_t), uint8_t module)
|
||||||
{
|
{
|
||||||
if (addRadioTool(index, label)) {
|
if (addRadioTool(index, label)) {
|
||||||
@@ -97,12 +144,36 @@ void addRadioScriptTool(uint8_t index, const char * path)
|
|||||||
luaExec(path);
|
luaExec(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addRadioScriptToolHandler(std::vector<LuaScript> luaScripts)
|
||||||
|
{
|
||||||
|
uint8_t index = 0;
|
||||||
|
for (auto luaScript : luaScripts) {
|
||||||
|
memclear(&reusableBuffer.radioTools.script[index], sizeof(reusableBuffer.radioTools.script[0]));
|
||||||
|
strncpy(reusableBuffer.radioTools.script[index].path, luaScript.path.c_str(), sizeof(reusableBuffer.radioTools.script[0].path));
|
||||||
|
strncpy(reusableBuffer.radioTools.script[index].label, luaScript.label.c_str(), sizeof(reusableBuffer.radioTools.script[0].label));
|
||||||
|
addRadioTool(index++, luaScript.label.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addRadioScriptToolHandler(uint8_t index, const char * path)
|
||||||
|
{
|
||||||
|
if (index >= menuVerticalOffset) {
|
||||||
|
uint8_t lineIndex = index - menuVerticalOffset;
|
||||||
|
if (lineIndex < NUM_BODY_LINES) {
|
||||||
|
memclear(&reusableBuffer.radioTools.script[index], sizeof(reusableBuffer.radioTools.script[0]));
|
||||||
|
strncpy(reusableBuffer.radioTools.script[index].path, path, sizeof(reusableBuffer.radioTools.script[0].path));
|
||||||
|
}
|
||||||
|
addRadioScriptTool(index, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void menuRadioTools(event_t event)
|
void menuRadioTools(event_t event)
|
||||||
{
|
{
|
||||||
if (event == EVT_ENTRY || event == EVT_ENTRY_UP) {
|
if (event == EVT_ENTRY || event == EVT_ENTRY_UP) {
|
||||||
memclear(&reusableBuffer.radioTools, sizeof(reusableBuffer.radioTools));
|
memclear(&reusableBuffer.radioTools, sizeof(reusableBuffer.radioTools));
|
||||||
|
reusableBuffer.radioTools.oldOffset = 0xFF;
|
||||||
#if defined(PXX2)
|
#if defined(PXX2)
|
||||||
for (uint8_t module = 0; module < NUM_MODULES; module++) {
|
for (uint8_t module = 0; module < NUM_MODULES; module++) {
|
||||||
if (isModulePXX2(module) && (module == INTERNAL_MODULE ? modulePortPowered(INTERNAL_MODULE) : modulePortPowered(EXTERNAL_MODULE))) {
|
if (isModulePXX2(module) && (module == INTERNAL_MODULE ? modulePortPowered(INTERNAL_MODULE) : modulePortPowered(EXTERNAL_MODULE))) {
|
||||||
@@ -116,6 +187,13 @@ void menuRadioTools(event_t event)
|
|||||||
|
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
|
|
||||||
|
if (reusableBuffer.radioTools.oldOffset == menuVerticalOffset) {
|
||||||
|
for(uint8_t line =0; line < reusableBuffer.radioTools.linesCount; line++) {
|
||||||
|
displayRadioTool(line);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(LUA)
|
#if defined(LUA)
|
||||||
FILINFO fno;
|
FILINFO fno;
|
||||||
DIR dir;
|
DIR dir;
|
||||||
@@ -150,22 +228,22 @@ void menuRadioTools(event_t event)
|
|||||||
f_closedir(&dir);
|
f_closedir(&dir);
|
||||||
|
|
||||||
std::sort(luaScripts.begin(), luaScripts.end(), LuaScript_compare_nocase);
|
std::sort(luaScripts.begin(), luaScripts.end(), LuaScript_compare_nocase);
|
||||||
addRadioScriptTool(luaScripts);
|
addRadioScriptToolHandler(luaScripts);
|
||||||
index += luaScripts.size();
|
index += luaScripts.size();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(INTERNAL_MODULE_PXX2)
|
#if defined(INTERNAL_MODULE_PXX2)
|
||||||
if (isPXX2ModuleOptionAvailable(reusableBuffer.radioTools.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER))
|
if (isPXX2ModuleOptionAvailable(reusableBuffer.radioTools.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER))
|
||||||
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
|
addRadioModuleToolHandler(index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
|
||||||
|
|
||||||
if (isPXX2ModuleOptionAvailable(reusableBuffer.radioTools.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER))
|
if (isPXX2ModuleOptionAvailable(reusableBuffer.radioTools.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER))
|
||||||
addRadioModuleTool(index++, STR_POWER_METER_INT, menuRadioPowerMeter, INTERNAL_MODULE);
|
addRadioModuleToolHandler(index++, STR_POWER_METER_INT, menuRadioPowerMeter, INTERNAL_MODULE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HARDWARE_INTERNAL_MODULE) && defined(MULTIMODULE)
|
#if defined(HARDWARE_INTERNAL_MODULE) && defined(MULTIMODULE)
|
||||||
if (g_eeGeneral.internalModule == MODULE_TYPE_MULTIMODULE)
|
if (g_eeGeneral.internalModule == MODULE_TYPE_MULTIMODULE)
|
||||||
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
|
addRadioModuleToolHandler(index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||||
@@ -181,16 +259,16 @@ void menuRadioTools(event_t event)
|
|||||||
has_spectrum_analyser = true;
|
has_spectrum_analyser = true;
|
||||||
#endif
|
#endif
|
||||||
if (has_spectrum_analyser)
|
if (has_spectrum_analyser)
|
||||||
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_EXT, menuRadioSpectrumAnalyser, EXTERNAL_MODULE);
|
addRadioModuleToolHandler(index++, STR_SPECTRUM_ANALYSER_EXT, menuRadioSpectrumAnalyser, EXTERNAL_MODULE);
|
||||||
#endif
|
#endif
|
||||||
#if defined(PXX2)
|
#if defined(PXX2)
|
||||||
if (isPXX2ModuleOptionAvailable(reusableBuffer.radioTools.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER))
|
if (isPXX2ModuleOptionAvailable(reusableBuffer.radioTools.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER))
|
||||||
addRadioModuleTool(index++, STR_POWER_METER_EXT, menuRadioPowerMeter, EXTERNAL_MODULE);
|
addRadioModuleToolHandler(index++, STR_POWER_METER_EXT, menuRadioPowerMeter, EXTERNAL_MODULE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(GHOST)
|
#if defined(GHOST)
|
||||||
if (isModuleGhost(EXTERNAL_MODULE))
|
if (isModuleGhost(EXTERNAL_MODULE))
|
||||||
addRadioModuleTool(index++, "Ghost Menu", menuGhostModuleConfig, EXTERNAL_MODULE);
|
addRadioModuleToolHandler(index++, "Ghost Menu", menuGhostModuleConfig, EXTERNAL_MODULE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -200,4 +278,5 @@ void menuRadioTools(event_t event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
reusableBuffer.radioTools.linesCount = index;
|
reusableBuffer.radioTools.linesCount = index;
|
||||||
|
reusableBuffer.radioTools.oldOffset = menuVerticalOffset;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user