Added EEPROM conversions to YAML

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:00 +01:00
parent 630e6918ea
commit 5e0d0131b4
13 changed files with 105 additions and 25 deletions
+7 -1
View File
@@ -160,9 +160,15 @@ if(${STORAGE} STREQUAL SDCARD)
set(SRC ${SRC} storage/sdcard_raw.cpp)
add_definitions(-DSDCARD_RAW)
elseif(${STORAGE_FORMAT} STREQUAL YAML)
set(SRC ${SRC} storage/sdcard_yaml.cpp storage/sdcard_raw.cpp)
set(SRC ${SRC} storage/sdcard_yaml.cpp)
add_definitions(-DSDCARD_YAML)
include(storage/yaml/CMakeLists.txt)
if (${STORAGE_CONVERT} STREQUAL EEPROM_RLC)
set(SRC ${SRC} storage/eeprom_rlc.cpp)
add_definitions(-DEEPROM_RLC)
else()
set(SRC ${SRC} storage/sdcard_raw.cpp)
endif()
endif()
elseif(${STORAGE} STREQUAL EEPROM)
set(SRC ${SRC} storage/eeprom_common.cpp)
+3 -2
View File
@@ -55,8 +55,9 @@ bool eeModelExists(uint8_t id)
{
int index = 0;
for (ModelsCategory::iterator it = modelSelect.currentCategory->begin(); it != modelSelect.currentCategory->end(); ++it, ++index) {
if (id == index){
for (ModelsCategory::iterator it = modelSelect.currentCategory->begin();
it != modelSelect.currentCategory->end(); ++it, ++index) {
if (id == index) {
return true;
}
}
+2 -2
View File
@@ -702,7 +702,7 @@ static void checkFailsafe()
#if defined(GUI)
void checkAll()
{
#if defined(EEPROM_RLC)
#if defined(EEPROM_RLC) && !defined(SDCARD_RAW) && !defined(SDCARD_YAML)
checkLowEEPROM();
#endif
@@ -753,7 +753,7 @@ void checkAll()
#endif // GUI
#if defined(EEPROM_RLC)
#if defined(EEPROM_RLC) && !defined(SDCARD_RAW) && !defined(SDCARD_YAML)
void checkLowEEPROM()
{
if (g_eeGeneral.disableMemoryWarning) return;
+1 -1
View File
@@ -630,7 +630,7 @@ int main(int argc, char ** argv)
simuInit();
#if defined(EEPROM)
#if defined(EEPROM) || defined(EEPROM_RLC)
startEepromThread(argc >= 2 ? argv[1] : "eeprom.bin");
#endif
startAudioThread();
+47 -6
View File
@@ -27,7 +27,9 @@
#include "storage/sdcard_common.h"
#include "storage/sdcard_raw.h"
#include "storage/sdcard_yaml.h"
#endif
#if !defined(EEPROM_RLC)
static void drawProgressScreen(const char* filename, int progress, int total)
{
#if defined(COLORLCD)
@@ -158,15 +160,36 @@ void convertModelData(int version)
#endif
}
#if defined(EEPROM)
#if defined(EEPROM) || defined(EEPROM_RLC)
#include "storage/eeprom_common.h"
void eeConvertModel(int id, int version)
{
eeLoadModelData(id);
convertModelData(version);
uint8_t currModel = g_eeGeneral.currModel;
g_eeGeneral.currModel = id;
#if !defined(EEPROM)
char filename[LEN_MODEL_FILENAME+1];
memset(filename, 0, sizeof(filename));
char* s = strAppend(filename, MODEL_FILENAME_PREFIX);
s = strAppendUnsigned(s, id + 1, 2);
s = strAppend(s, MODEL_FILENAME_SUFFIX);
memcpy(g_eeGeneral.currModelFilename, filename, sizeof(g_eeGeneral.currModelFilename));
if (!modelslist.getCurrentCategory()) {
ModelsCategory* cat = modelslist.createCategory("Models", false);
modelslist.setCurrentCategory(cat);
}
ModelCell* model = modelslist.addModel(modelslist.getCurrentCategory(),
filename, false);
model->setModelName(g_model.header.name);
#endif
storageDirty(EE_MODEL);
storageCheck(true);
g_eeGeneral.currModel = currModel;
}
@@ -178,6 +201,9 @@ bool eeConvert()
case 219:
msg = "EEprom Data v219";
break;
case 220:
msg = "EEprom Data v220";
break;
default:
return false;
}
@@ -203,12 +229,15 @@ bool eeConvert()
convertRadioData_219_to_220(g_eeGeneral);
}
#endif
g_eeGeneral.version = EEPROM_VER;
storageDirty(EE_GENERAL);
storageCheck(true);
#if defined(COLORLCD)
#elif LCD_W >= 212
#if !defined(EEPROM)
modelslist.clear();
#endif
#if LCD_W >= 212
lcdDrawRect(60, 6*FH+4, 132, 3);
#else
lcdDrawRect(10, 6*FH+4, 102, 3);
@@ -216,18 +245,30 @@ bool eeConvert()
// Models conversion
for (uint8_t id=0; id<MAX_MODELS; id++) {
#if defined(COLORLCD)
#elif LCD_W >= 212
#if LCD_W >= 212
lcdDrawSolidHorizontalLine(61, 6*FH+5, 10+id*2, FORCE);
#else
lcdDrawSolidHorizontalLine(11, 6*FH+5, 10+(id*3)/2, FORCE);
#endif
lcdRefresh();
#if defined(SIMU)
RTOS_WAIT_MS(100);
#endif
#if defined(SDCARD_RAW) || defined(SDCARD_YAML)
if (eeModelExistsRlc(id)) {
#else
if (eeModelExists(id)) {
#endif
eeConvertModel(id, conversionVersionStart);
}
}
#if !defined(EEPROM)
modelslist.save();
#endif
return true;
}
#endif
+12 -1
View File
@@ -23,6 +23,9 @@
#include <string.h>
#include "opentx.h"
#include "../timers.h"
#include "storage/eeprom_common.h"
#include "storage/eeprom_rlc.h"
#include "conversions/conversions.h"
uint8_t s_write_err = 0; // error reasons
@@ -154,6 +157,7 @@ void eepromCheck()
ENABLE_SYNC_WRITE(false);
}
#if !defined(SDCARD_RAW) && !defined(SDCARD_YAML)
void storageFormat()
{
ENABLE_SYNC_WRITE(true);
@@ -179,6 +183,7 @@ void storageFormat()
ENABLE_SYNC_WRITE(false);
}
#endif
bool eepromOpen()
{
@@ -444,7 +449,7 @@ bool RlcFile::copy(uint8_t i_fileDst, uint8_t i_fileSrc)
return true;
}
#if defined(SDCARD)
#if defined(SDCARD) && !defined(SDCARD_RAW) && !defined(SDCARD_YAML)
const char * eeBackupModel(uint8_t i_fileSrc)
{
char * buf = reusableBuffer.modelsel.mainname;
@@ -827,11 +832,16 @@ void eeLoadModelName(uint8_t id, char *name)
}
}
#if defined(SDCARD_RAW) || defined(SDCARD_YAML)
bool eeModelExistsRlc(uint8_t id)
#else
bool eeModelExists(uint8_t id)
#endif
{
return EFile::exists(FILE_MODEL(id));
}
#if !defined(SDCARD_RAW) && !defined(SDCARD_YAML)
void storageCheck(bool immediately)
{
if (immediately) {
@@ -851,6 +861,7 @@ void storageCheck(bool immediately)
theFile.writeRlc(FILE_MODEL(g_eeGeneral.currModel), FILE_TYP_MODEL, (uint8_t*)&g_model, sizeof(g_model), immediately);
}
}
#endif
void eeLoadModelHeader(uint8_t id, ModelHeader *header)
{
+6
View File
@@ -175,8 +175,10 @@ const char * eeBackupModel(uint8_t i_fileSrc);
const char * eeRestoreModel(uint8_t i_fileDst, char *model_name);
#endif
#if !defined(SDCARD_RAW) && !defined(SDCARD_YAML)
// For conversions
void loadRadioSettings();
#endif
bool eepromOpen();
void eeLoadModelName(uint8_t id, char * name);
@@ -206,4 +208,8 @@ inline bool isEepromStart(const void * buffer)
void eepromBackup();
#if defined(SDCARD_RAW) || defined(SDCARD_YAML)
bool eeModelExistsRlc(uint8_t id);
#endif
#endif // _EEPROM_RLC_H_
+2 -2
View File
@@ -478,11 +478,11 @@ ModelsCategory * ModelsList::createCategory(const char* name, bool save)
return result;
}
ModelCell * ModelsList::addModel(ModelsCategory * category, const char * name)
ModelCell * ModelsList::addModel(ModelsCategory * category, const char * name, bool save)
{
ModelCell * result = category->addModel(name);
modelsCount++;
save();
if (save) this->save();
return result;
}
+1 -1
View File
@@ -145,7 +145,7 @@ public:
ModelsCategory * createCategory(const char * name, bool save=true);
void removeCategory(ModelsCategory * category);
ModelCell * addModel(ModelsCategory * category, const char * name);
ModelCell * addModel(ModelsCategory * category, const char * name, bool save=true);
void removeModel(ModelsCategory * category, ModelCell * model);
void moveModel(ModelsCategory * category, ModelCell * model, int8_t step);
void moveModel(ModelCell * model, ModelsCategory * previous_category, ModelsCategory * new_category);
+5 -4
View File
@@ -26,13 +26,14 @@
#define DEFAULT_CATEGORY "Models"
#define MODEL_FILENAME_PREFIX "model"
#if defined(SDCARD_RAW)
#define DEFAULT_MODEL_FILENAME "model1.bin"
#define MODEL_FILENAME_PATTERN "model.bin"
#define MODEL_FILENAME_SUFFIX ".bin"
#elif defined(SDCARD_YAML)
#define DEFAULT_MODEL_FILENAME "model1.yml"
#define MODEL_FILENAME_PATTERN "model.yml"
#define MODEL_FILENAME_SUFFIX ".yml"
#endif
#define DEFAULT_MODEL_FILENAME MODEL_FILENAME_PREFIX "1" MODEL_FILENAME_SUFFIX
#define MODEL_FILENAME_PATTERN MODEL_FILENAME_PREFIX MODEL_FILENAME_SUFFIX
//#if !defined(EEPROM)
extern ModelHeader modelHeaders[MAX_MODELS];
+15 -2
View File
@@ -30,6 +30,10 @@
#include "yaml/yaml_parser.h"
#include "yaml/yaml_datastructs.h"
#if defined(EEPROM_RLC)
#include "storage/eeprom_rlc.h"
#endif
const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, void* parser_ctx)
{
FIL file;
@@ -90,7 +94,15 @@ const char * loadRadioSettings()
{
FILINFO fno;
if (f_stat(RADIO_SETTINGS_YAML_PATH, &fno) != FR_OK) {
return loadRadioSettingsBin();
#if !defined(EEPROM_RLC)
return loadRadioSettingsBin();
#else
// Load from EEPROM
if (!eepromOpen() || !eeLoadGeneral(true)) {
return "ERROR";
}
return nullptr;
#endif
}
return loadRadioSettingsYaml();
@@ -192,8 +204,9 @@ const char* readModel(const char* filename, uint8_t* buffer, uint32_t size,
if (!strncmp(ext, YAML_EXT, 4)) {
return readModelYaml(filename, buffer, size, version);
}
#if !defined(EEPROM_RLC)
return readModelBin(filename, buffer, size, version);
#endif
}
return nullptr;
}
+2 -1
View File
@@ -420,7 +420,8 @@ set(HSE_VALUE 12000000)
set(SDCARD YES)
if(YAML_STORAGE)
set(STORAGE SDCARD)
set(STORAGE_FORMAT YAML)
set(STORAGE_FORMAT YAML)
set(STORAGE_CONVERT EEPROM_RLC)
else()
set(STORAGE EEPROM)
set(STORAGE_FORMAT RLC)
+2 -2
View File
@@ -822,9 +822,7 @@ const char STR_REPEAT_AT_ZERO[] = TR_REPEAT_AT_ZERO;
const char STR_BAD_RADIO_DATA[] = TR_BADEEPROMDATA;
const char STR_STORAGE_FORMAT[] = TR_EEPROMFORMATTING;
const char STR_STORAGE_WARNING[] = TR_EEPROMWARN;
const char STR_EEPROM_CONVERTING[] = TR_EEPROM_CONVERTING;
const char STR_EEPROMLOWMEM[] = TR_EEPROMLOWMEM;
const char STR_EEPROMOVERFLOW[] = TR_EEPROMOVERFLOW;
#else
const char STR_BAD_RADIO_DATA[] = TR_BAD_RADIO_DATA;
const char STR_STORAGE_WARNING[] = TR_STORAGE_WARNING;
@@ -832,6 +830,8 @@ const char STR_STORAGE_FORMAT[] = TR_STORAGE_FORMAT;
const char STR_SDCARD_CONVERSION_REQUIRE[] = TR_SDCARD_CONVERSION_REQUIRE;
const char STR_CONVERTING[] = TR_CONVERTING;
#endif
const char STR_EEPROMOVERFLOW[] = TR_EEPROMOVERFLOW;
const char STR_EEPROM_CONVERTING[] = TR_EEPROM_CONVERTING;
#if defined(LUA)
const char STR_MENUCUSTOMSCRIPTS[] = TR_MENUCUSTOMSCRIPTS;