1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 00:05:17 +03:00

[X10 Express] Spectrum analyser, first version

This commit is contained in:
Bertrand Songis 2019-08-19 16:21:44 +02:00
parent 01c88fbba8
commit ffb731dc30
No known key found for this signature in database
GPG key ID: F189F79290FEC50F
11 changed files with 281 additions and 140 deletions

View file

@ -49,48 +49,11 @@ void addRadioModuleTool(uint8_t index, const char * label, void (* tool)(event_t
#define TOOL_NAME_MAXLEN 16
#if defined(LUA)
bool readToolName(const char * filename, char * name)
{
FIL file;
char buffer[1024];
UINT count;
if (f_open(&file, filename, FA_READ) != FR_OK) {
return "Error opening file";
}
if (f_read(&file, &buffer, sizeof(buffer), &count) != FR_OK) {
f_close(&file);
return false;
}
const char * tns = "TNS|";
auto * start = std::search(buffer, buffer + sizeof(buffer), tns, tns + 4);
if (start >= buffer + sizeof(buffer))
return false;
start += 4;
const char * tne = "|TNE";
auto * end = std::search(buffer, buffer + sizeof(buffer), tne, tne + 4);
if (end >= buffer + sizeof(buffer) || end <= start)
return false;
uint8_t len = end - start;
if (len > TOOL_NAME_MAXLEN)
return false;
strncpy(name, start, len);
memclear(name + len, TOOL_NAME_MAXLEN + 1 - len);
return true;
}
void addRadioScriptTool(uint8_t index, const char * path)
{
char toolName[TOOL_NAME_MAXLEN + 1];
if (!readToolName(path, toolName)) {
if (!readToolName(toolName, path)) {
strAppendFilename(toolName, getBasename(path), TOOL_NAME_MAXLEN);
}
@ -102,12 +65,6 @@ void addRadioScriptTool(uint8_t index, const char * path)
luaExec(path);
}
}
bool isRadioScriptTool(const char * filename)
{
const char * ext = getFileExtension(filename);
return ext && !strcasecmp(ext, SCRIPT_EXT);
}
#endif
void menuRadioTools(event_t event)