From f932e9e12c44a8e9b56d092a95e92626ac27a2da Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 19 Oct 2021 09:07:41 +0200 Subject: [PATCH] Further confined v220 data structures --- radio/src/audio.h | 1 - radio/src/gui/colorlcd/theme_manager.cpp | 12 +++- radio/src/gui/colorlcd/theme_manager.h | 9 ++- radio/src/gui/common/stdlcd/view_text.cpp | 68 ++++++++++++++++++ radio/src/sdcard.cpp | 67 ------------------ radio/src/sdcard.h | 12 ++-- .../conversions/conversions_219_220.cpp | 70 +++++++++---------- .../conversions/conversions_220_221.cpp | 12 +++- .../src/storage/conversions/datastructs_220.h | 3 + radio/src/storage/modelslist.cpp | 7 ++ radio/src/storage/modelslist.h | 5 ++ radio/src/storage/sdcard_common.h | 4 +- radio/src/storage/yaml/yaml_modelslist.cpp | 2 + radio/src/telemetry/multi.h | 2 + radio/src/translations.h | 26 +++++-- 15 files changed, 175 insertions(+), 125 deletions(-) diff --git a/radio/src/audio.h b/radio/src/audio.h index 9782c855e..57bbcf86c 100644 --- a/radio/src/audio.h +++ b/radio/src/audio.h @@ -615,7 +615,6 @@ void pushUnit(uint8_t unit, uint8_t idx, uint8_t id); void playModelName(); #define I18N_PLAY_FUNCTION(lng, x, ...) void lng ## _ ## x(__VA_ARGS__, uint8_t id) -#define PLAY_FUNCTION(x, ...) void x(__VA_ARGS__, uint8_t id) #define PUSH_NUMBER_PROMPT(p) pushPrompt((p), id) #define PUSH_UNIT_PROMPT(p, i) pushUnit((p), (i), id) #define PLAY_NUMBER(n, u, a) playNumber((n), (u), (a), id) diff --git a/radio/src/gui/colorlcd/theme_manager.cpp b/radio/src/gui/colorlcd/theme_manager.cpp index a6365996a..35388a5ab 100644 --- a/radio/src/gui/colorlcd/theme_manager.cpp +++ b/radio/src/gui/colorlcd/theme_manager.cpp @@ -18,7 +18,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ + #include "theme_manager.h" +#include "theme.h" + +#include +#include ThemePersistance themePersistance; @@ -93,7 +98,7 @@ void ThemeFile::scanFile() char *plvalue; char *prvalue; - strncpy(lvalue, line, min((int)(ptr - line), 63)); + strncpy(lvalue, line, std::min((int)(ptr - line), 63)); lvalue[ptr - line] = '\0'; strncpy(rvalue, ptr + 1, 63); plvalue = trim(lvalue); @@ -226,6 +231,9 @@ void ThemeFile::applyTheme() OpenTxTheme::instance()->update(false); } +// not sure why this is needed... +constexpr unsigned MAX_SD_FILE_LENGTH = 64; + void ThemePersistance::scanForThemes() { TRACE("in scanForThemes"); @@ -251,7 +259,7 @@ void ThemePersistance::scanForThemes() if (res != FR_OK || fno.fname[0] == 0) break; // Break on error or end of dir - if (strlen((const char *)fno.fname) > SD_SCREEN_FILE_LENGTH) continue; + if (strlen((const char *)fno.fname) > MAX_SD_FILE_LENGTH) continue; if (fno.fattrib & AM_DIR) continue; TRACE("scanForThemes: found file %s", fno.fname); diff --git a/radio/src/gui/colorlcd/theme_manager.h b/radio/src/gui/colorlcd/theme_manager.h index b466a0553..eb61624e8 100644 --- a/radio/src/gui/colorlcd/theme_manager.h +++ b/radio/src/gui/colorlcd/theme_manager.h @@ -18,15 +18,22 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ + #pragma once -#include + #include #include +#include #include + +#include "debug.h" #include "sdcard.h" #include "colors.h" #include "str_functions.h" +// sdReadir: used to be in "sdcard.h" (another GPL violation...) +#include "libopenui_file.h" + class ThemePersistance; extern ThemePersistance themePersistance; diff --git a/radio/src/gui/common/stdlcd/view_text.cpp b/radio/src/gui/common/stdlcd/view_text.cpp index 0e767e698..a70c48879 100644 --- a/radio/src/gui/common/stdlcd/view_text.cpp +++ b/radio/src/gui/common/stdlcd/view_text.cpp @@ -29,6 +29,74 @@ #define EVT_KEY_PREVIOUS_LINE EVT_KEY_FIRST(KEY_UP) #endif +constexpr uint32_t TEXT_FILE_MAXSIZE = 2048; + +static void sdReadTextFile(const char * filename, char lines[TEXT_VIEWER_LINES][LCD_COLS + 1], int & lines_count) +{ + FIL file; + int result; + char c; + unsigned int sz; + int line_length = 0; + uint8_t escape = 0; + char escape_chars[4] = {0}; + int current_line = 0; + + memclear(lines, TEXT_VIEWER_LINES * (LCD_COLS + 1)); + + result = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ); + if (result == FR_OK) { + for (uint32_t i = 0; i < TEXT_FILE_MAXSIZE && f_read(&file, &c, 1, &sz) == FR_OK && sz == 1 && (lines_count == 0 || current_line - menuVerticalOffset < int(TEXT_VIEWER_LINES)); i++) { + if (c == '\n') { + ++current_line; + line_length = 0; + escape = 0; + } + else if (c != '\r' && current_line >= menuVerticalOffset && current_line - menuVerticalOffset < int(TEXT_VIEWER_LINES) && line_length < LCD_COLS) { + if (c == '\\' && escape == 0) { + escape = 1; + continue; + } + else if (c != '\\' && escape > 0 && escape < sizeof(escape_chars)) { + escape_chars[escape - 1] = c; + if (escape == 2 && !strncmp(escape_chars, "up", 2)) { + c = CHAR_UP; + } + else if (escape == 2 && !strncmp(escape_chars, "dn", 2)) { + c = CHAR_DOWN; + } + else if (escape == 3) { + int val = atoi(escape_chars); + if (val >= 200 && val < 225) { + c = '\200' + val - 200; + } + } + else { + escape++; + continue; + } + } + else if (c=='~') { + c = 'z'+1; + } + else if (c=='\t') { + c = 0x1D; //tab + } + escape = 0; + lines[current_line-menuVerticalOffset][line_length++] = c; + } + } + if (c != '\n') { + current_line += 1; + } + f_close(&file); + } + + if (lines_count == 0) { + lines_count = current_line; + } +} + void readModelNotes() { LED_ERROR_BEGIN(); diff --git a/radio/src/sdcard.cpp b/radio/src/sdcard.cpp index 62c193c15..e3ad2838e 100644 --- a/radio/src/sdcard.cpp +++ b/radio/src/sdcard.cpp @@ -363,73 +363,6 @@ bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen return popupMenuItemsCount; } -constexpr uint32_t TEXT_FILE_MAXSIZE = 2048; - -void sdReadTextFile(const char * filename, char lines[TEXT_VIEWER_LINES][LCD_COLS + 1], int & lines_count) -{ - FIL file; - int result; - char c; - unsigned int sz; - int line_length = 0; - uint8_t escape = 0; - char escape_chars[4] = {0}; - int current_line = 0; - - memclear(lines, TEXT_VIEWER_LINES * (LCD_COLS + 1)); - - result = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ); - if (result == FR_OK) { - for (uint32_t i = 0; i < TEXT_FILE_MAXSIZE && f_read(&file, &c, 1, &sz) == FR_OK && sz == 1 && (lines_count == 0 || current_line - menuVerticalOffset < int(TEXT_VIEWER_LINES)); i++) { - if (c == '\n') { - ++current_line; - line_length = 0; - escape = 0; - } - else if (c != '\r' && current_line >= menuVerticalOffset && current_line - menuVerticalOffset < int(TEXT_VIEWER_LINES) && line_length < LCD_COLS) { - if (c == '\\' && escape == 0) { - escape = 1; - continue; - } - else if (c != '\\' && escape > 0 && escape < sizeof(escape_chars)) { - escape_chars[escape - 1] = c; - if (escape == 2 && !strncmp(escape_chars, "up", 2)) { - c = CHAR_UP; - } - else if (escape == 2 && !strncmp(escape_chars, "dn", 2)) { - c = CHAR_DOWN; - } - else if (escape == 3) { - int val = atoi(escape_chars); - if (val >= 200 && val < 225) { - c = '\200' + val - 200; - } - } - else { - escape++; - continue; - } - } - else if (c=='~') { - c = 'z'+1; - } - else if (c=='\t') { - c = 0x1D; //tab - } - escape = 0; - lines[current_line-menuVerticalOffset][line_length++] = c; - } - } - if (c != '\n') { - current_line += 1; - } - f_close(&file); - } - - if (lines_count == 0) { - lines_count = current_line; - } -} #endif // !LIBOPENUI #if defined(SDCARD) diff --git a/radio/src/sdcard.h b/radio/src/sdcard.h index 18bedfe82..825f57976 100644 --- a/radio/src/sdcard.h +++ b/radio/src/sdcard.h @@ -22,11 +22,12 @@ #ifndef _SDCARD_H_ #define _SDCARD_H_ -#if !defined(SIMU) #include "ff.h" -#endif -#include "opentx.h" +extern FATFS g_FATFS_Obj; +extern FIL g_oLogFile; + +#include "translations.h" #define PATH_SEPARATOR "/" #define ROOT_PATH PATH_SEPARATOR @@ -104,9 +105,6 @@ const char RADIO_SETTINGS_YAML_PATH[] = RADIO_PATH PATH_SEPARATOR "radio.yml"; filename[sizeof(path)+sizeof(var)] = '\0'; \ strcat(&filename[sizeof(path)], ext) -extern FATFS g_FATFS_Obj; -extern FIL g_oLogFile; - extern uint8_t logDelay; void logsInit(); void logsClose(); @@ -179,6 +177,4 @@ const char * sdCopyFile(const char * srcFilename, const char * srcDir, const cha #define LIST_SD_FILE_EXT 2 bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen, const char * selection, uint8_t flags=0); -void sdReadTextFile(const char * filename, char lines[NUM_BODY_LINES][LCD_COLS + 1], int & lines_count); - #endif // _SDCARD_H_ diff --git a/radio/src/storage/conversions/conversions_219_220.cpp b/radio/src/storage/conversions/conversions_219_220.cpp index c65b1eed2..d65d528af 100644 --- a/radio/src/storage/conversions/conversions_219_220.cpp +++ b/radio/src/storage/conversions/conversions_219_220.cpp @@ -19,16 +19,20 @@ * GNU General Public License for more details. */ -#include "opentx.h" +#include +#include + +#include "definitions.h" #include "datastructs_219.h" #include "datastructs_220.h" -#if defined(COLORLCD) -#include "theme.h" -#endif +#include "debug.h" +#include "strhelpers.h" #if defined(EEPROM) || defined(EEPROM_RLC) -#include + #include +#else + #include #endif // @@ -85,7 +89,7 @@ // -> ModelData: +1284 (CustomScreenData x 5 = 1200; TopBar::PersistentData: +84) // -typedef TimerData TimerData_v220; +typedef bin_storage_220::TimerData TimerData_v220; static void convertToStr(char* str, size_t len) { @@ -99,11 +103,6 @@ static void convertToStr(char* str, size_t len) } } -#if defined(COLORLCD) -extern const LayoutFactory * defaultLayout; -extern OpenTxTheme * defaultTheme; -#endif - void convertModelData_219_to_220(void* data) { constexpr unsigned md_size = sizeof(bin_storage_220::ModelData); @@ -125,17 +124,17 @@ void convertModelData_219_to_220(void* data) // Convert mode - if (timer_219.mode >= TMRMODE_START) { + if (timer_219.mode >= bin_storage_220::TMRMODE_START) { timer_219.mode += 1; } - if (timer_219.mode < TMRMODE_COUNT + if (timer_219.mode < bin_storage_220::TMRMODE_COUNT && timer_219.mode >=0) { timer.mode = timer_219.mode; } else { - timer.mode = TMRMODE_ON; + timer.mode = bin_storage_220::TMRMODE_ON; if (timer_219.mode > 0) - timer.swtch = timer_219.mode - (TMRMODE_COUNT - 1); + timer.swtch = timer_219.mode - (bin_storage_220::TMRMODE_COUNT - 1); else timer.swtch = timer_219.mode; } @@ -219,33 +218,28 @@ void convertModelData_219_to_220(void* data) sizeof(newModel.screenData) + sizeof(newModel.topbarData)); - if (defaultLayout) { - strcpy(newModel.screenData[0].LayoutId, "Layout2P1"); + strcpy(newModel.screenData[0].LayoutId, "Layout2P1"); + auto persistentData = &newModel.screenData[0].layoutData; - // TODO: copy the raw structure for the default layout in version 220 - //defaultLayout->initPersistentData(&newModel.screenData[0].layoutData, true); - auto persistentData = &newModel.screenData[0].layoutData; + // top bar + persistentData->options[0].type = bin_storage_220::ZOV_Bool; + persistentData->options[0].value.boolValue = true; - // top bar - persistentData->options[0].type = bin_storage_220::ZOV_Bool; - persistentData->options[0].value.boolValue = true; + // flight mode + persistentData->options[1].type = bin_storage_220::ZOV_Bool; + persistentData->options[1].value.boolValue = true; - // flight mode - persistentData->options[1].type = bin_storage_220::ZOV_Bool; - persistentData->options[1].value.boolValue = true; + // sliders + persistentData->options[2].type = bin_storage_220::ZOV_Bool; + persistentData->options[2].value.boolValue = true; - // sliders - persistentData->options[2].type = bin_storage_220::ZOV_Bool; - persistentData->options[2].value.boolValue = true; + // trims + persistentData->options[3].type = bin_storage_220::ZOV_Bool; + persistentData->options[3].value.boolValue = true; - // trims - persistentData->options[3].type = bin_storage_220::ZOV_Bool; - persistentData->options[3].value.boolValue = true; - - // mirrored - persistentData->options[4].type = bin_storage_220::ZOV_Bool; - persistentData->options[4].value.boolValue = false; - } + // mirrored + persistentData->options[4].type = bin_storage_220::ZOV_Bool; + persistentData->options[4].value.boolValue = false; #endif free(oldModelAllocated); } @@ -300,7 +294,7 @@ void convertRadioData_219_to_220(void* data) #if defined(COLORLCD) // Clear CustomScreenData + TopBarPersistentData // as they cannot be converted (missing option types) - strcpy(settings.themeName, defaultTheme->getName()); + strcpy(settings.themeName, "EdgeTX"); memset(&settings.themeData, 0, sizeof(settings.themeData)); #endif diff --git a/radio/src/storage/conversions/conversions_220_221.cpp b/radio/src/storage/conversions/conversions_220_221.cpp index 342cb0774..a9fd697e4 100644 --- a/radio/src/storage/conversions/conversions_220_221.cpp +++ b/radio/src/storage/conversions/conversions_220_221.cpp @@ -19,9 +19,19 @@ * GNU General Public License for more details. */ -#include "opentx.h" +#include +#include + +#include "definitions.h" #include "datastructs_220.h" +#include "sdcard.h" + +#include + +using namespace bin_storage_220; +#include + // see "yaml/yaml_datastructs.h" namespace yaml_conv_220 { const YamlNode* get_radiodata_nodes(); diff --git a/radio/src/storage/conversions/datastructs_220.h b/radio/src/storage/conversions/datastructs_220.h index b4c80cb5a..fed2e49d9 100644 --- a/radio/src/storage/conversions/datastructs_220.h +++ b/radio/src/storage/conversions/datastructs_220.h @@ -28,3 +28,6 @@ namespace bin_storage_220 { #include "yaml/myeeprom_220.h" }; + +// prevent board.h from being included +#define _BOARD_H_ diff --git a/radio/src/storage/modelslist.cpp b/radio/src/storage/modelslist.cpp index c956741f0..cd1237030 100644 --- a/radio/src/storage/modelslist.cpp +++ b/radio/src/storage/modelslist.cpp @@ -27,6 +27,13 @@ using std::list; #include "yaml/yaml_modelslist.h" #endif +#include "myeeprom.h" +#include "datastructs.h" +#include "pulses/modules_helpers.h" +#include "strhelpers.h" + +#include + ModelsList modelslist; ModelCell::ModelCell(const char* name) : valid_rfData(false) diff --git a/radio/src/storage/modelslist.h b/radio/src/storage/modelslist.h index 0383081c4..c3d0c0664 100644 --- a/radio/src/storage/modelslist.h +++ b/radio/src/storage/modelslist.h @@ -30,12 +30,17 @@ #include "sdcard_raw.h" #endif +#include "dataconstants.h" + // #define MODELCELL_WIDTH 172 // #define MODELCELL_HEIGHT 59 // modelXXXXXXX.bin F,FF F,3F,FF\r\n #define LEN_MODELS_IDX_LINE (LEN_MODEL_FILENAME + sizeof(" F,FF F,3F,FF\r\n")-1) +struct ModelData; +struct ModuleData; + struct SimpleModuleData { uint8_t type; diff --git a/radio/src/storage/sdcard_common.h b/radio/src/storage/sdcard_common.h index 1ce2cfb19..9dfa4d1bc 100644 --- a/radio/src/storage/sdcard_common.h +++ b/radio/src/storage/sdcard_common.h @@ -35,9 +35,9 @@ #define DEFAULT_MODEL_FILENAME MODEL_FILENAME_PREFIX "1" MODEL_FILENAME_SUFFIX #define MODEL_FILENAME_PATTERN MODEL_FILENAME_PREFIX MODEL_FILENAME_SUFFIX -//#if !defined(EEPROM) +#if !defined(STORAGE_MODELSLIST) extern ModelHeader modelHeaders[MAX_MODELS]; -//#endif +#endif // opens radio.bin or model file const char* openFileBin(const char* fullpath, FIL* file, uint16_t* size, diff --git a/radio/src/storage/yaml/yaml_modelslist.cpp b/radio/src/storage/yaml/yaml_modelslist.cpp index dd3384751..04a291e61 100644 --- a/radio/src/storage/yaml/yaml_modelslist.cpp +++ b/radio/src/storage/yaml/yaml_modelslist.cpp @@ -24,6 +24,8 @@ #include "storage/modelslist.h" +#include + using std::list; struct modelslist_iter diff --git a/radio/src/telemetry/multi.h b/radio/src/telemetry/multi.h index 64f51edb3..1f7fbf07d 100644 --- a/radio/src/telemetry/multi.h +++ b/radio/src/telemetry/multi.h @@ -22,6 +22,8 @@ #ifndef OPENTX_MULTI_H #define OPENTX_MULTI_H +#include "../timers.h" + #define MULTI_BUFFER_SIZE 177 extern uint8_t * Multi_Buffer; diff --git a/radio/src/translations.h b/radio/src/translations.h index f8cea01fd..57e43b455 100644 --- a/radio/src/translations.h +++ b/radio/src/translations.h @@ -22,6 +22,7 @@ #ifndef _TRANSLATIONS_H_ #define _TRANSLATIONS_H_ +#include "opentx_types.h" #include "translations/untranslated.h" #if defined(TRANSLATIONS_FR) @@ -778,14 +779,29 @@ const LanguagePack * const languagePacks[] = { #endif #if defined(SIMU) - #define LANGUAGE_PACK_DECLARE(lng, name) const LanguagePack lng ## LanguagePack = { #lng, name, lng ## _ ## playNumber, lng ## _ ## playDuration } +#define LANGUAGE_PACK_DECLARE(lng, name) \ + const LanguagePack lng##LanguagePack = {#lng, name, lng##_##playNumber, \ + lng##_##playDuration} #else - #define LANGUAGE_PACK_DECLARE(lng, name) extern const LanguagePack lng ## LanguagePack = { #lng, name, lng ## _ ## playNumber, lng ## _ ## playDuration } +#define LANGUAGE_PACK_DECLARE(lng, name) \ + extern const LanguagePack lng##LanguagePack = { \ + #lng, name, lng##_##playNumber, lng##_##playDuration} #endif -#define LANGUAGE_PACK_DECLARE_DEFAULT(lng, name) LANGUAGE_PACK_DECLARE(lng, name); const LanguagePack * currentLanguagePack = & lng ## LanguagePack; uint8_t currentLanguagePackIdx -inline PLAY_FUNCTION(playNumber, getvalue_t number, uint8_t unit, uint8_t flags) { currentLanguagePack->playNumber(number, unit, flags, id); } -inline PLAY_FUNCTION(playDuration, int seconds, uint8_t flags) { currentLanguagePack->playDuration(seconds, flags, id); } +#define LANGUAGE_PACK_DECLARE_DEFAULT(lng, name) \ + LANGUAGE_PACK_DECLARE(lng, name); \ + const LanguagePack* currentLanguagePack = &lng##LanguagePack; \ + uint8_t currentLanguagePackIdx + +#define PLAY_FUNCTION(x, ...) void x(__VA_ARGS__, uint8_t id) + +inline PLAY_FUNCTION(playNumber, getvalue_t number, uint8_t unit, uint8_t flags) { + currentLanguagePack->playNumber(number, unit, flags, id); +} + +inline PLAY_FUNCTION(playDuration, int seconds, uint8_t flags) { + currentLanguagePack->playDuration(seconds, flags, id); +} extern const char STR_MODELNAME[]; extern const char STR_PHASENAME[];