Further confined v220 data structures

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:01 +01:00
parent 7b6749ebee
commit f932e9e12c
15 changed files with 175 additions and 125 deletions
-1
View File
@@ -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)
+10 -2
View File
@@ -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 <cstdlib>
#include <cstring>
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);
+8 -1
View File
@@ -18,15 +18,22 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <stdlib.h>
#include <list>
#include <string>
#include <vector>
#include <locale>
#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;
+68
View File
@@ -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();
-67
View File
@@ -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)
+4 -8
View File
@@ -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_
@@ -19,16 +19,20 @@
* GNU General Public License for more details.
*/
#include "opentx.h"
#include <cstdlib>
#include <cstring>
#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 <storage/eeprom_common.h>
#include <storage/eeprom_common.h>
#else
#include <storage/sdcard_common.h>
#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
@@ -19,9 +19,19 @@
* GNU General Public License for more details.
*/
#include "opentx.h"
#include <cstdlib>
#include <cstring>
#include "definitions.h"
#include "datastructs_220.h"
#include "sdcard.h"
#include <storage/yaml/yaml_node.h>
using namespace bin_storage_220;
#include <storage/sdcard_common.h>
// see "yaml/yaml_datastructs.h"
namespace yaml_conv_220 {
const YamlNode* get_radiodata_nodes();
@@ -28,3 +28,6 @@ namespace bin_storage_220 {
#include "yaml/myeeprom_220.h"
};
// prevent board.h from being included
#define _BOARD_H_
+7
View File
@@ -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 <cstring>
ModelsList modelslist;
ModelCell::ModelCell(const char* name) : valid_rfData(false)
+5
View File
@@ -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;
+2 -2
View File
@@ -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,
@@ -24,6 +24,8 @@
#include "storage/modelslist.h"
#include <cstring>
using std::list;
struct modelslist_iter
+2
View File
@@ -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;
+21 -5
View File
@@ -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[];