Merge pull request #289 from EdgeTX/2.4

Merge from 2.4 bug fixes
This commit is contained in:
richardclli
2021-06-21 15:45:44 +08:00
committed by GitHub
240 changed files with 3821 additions and 4760 deletions
@@ -21,16 +21,100 @@
#include "opentx.h"
#include "conversions.h"
#if defined(COLORLCD)
#include "storage/modelslist.h"
#include "storage/sdcard_common.h"
static void drawProgressScreen(const char* filename, int progress, int total)
{
OpenTxTheme* l_theme = static_cast<OpenTxTheme*>(theme);
lcd->reset();
l_theme->drawBackground(lcd);
lcd->drawText(LCD_W/2, LCD_H/2 - 30, STR_CONVERTING, FONT(XL) | CENTERED | ALARM_COLOR);
lcd->drawText(LCD_W/2, LCD_H/2, filename, FONT(STD) | CENTERED | DEFAULT_COLOR);
l_theme->drawProgressBar(lcd,
LCD_W / 4,
LCD_H / 2 + 40,
LCD_W / 2,
20,
progress, total);
WDG_RESET();
lcdRefresh();
}
void convertRadioData(int version)
{
TRACE("convertRadioData(%d)", version);
// the theme has not been loaded before
static_cast<OpenTxTheme*>(theme)->load();
// Init backlight mode before entering alert screens
requiredBacklightBright = BACKLIGHT_FORCED_ON;
g_eeGeneral.blOffBright = 20;
RAISE_ALERT(STR_STORAGE_WARNING, STR_SDCARD_CONVERSION_REQUIRE, NULL,
AU_NONE);
// Load models list before converting
modelslist.load();
unsigned converted = 0;
auto to_convert = modelslist.getModelsCount() + 1;
drawProgressScreen(RADIO_FILENAME, converted, to_convert);
TRACE("converting '%s' (%d/%d)", RADIO_FILENAME, converted, to_convert);
#if STORAGE_CONVERSIONS < 220
if (version == 219) {
convertRadioData_219_to_220(g_eeGeneral);
storageDirty(EE_GENERAL);
storageCheck(true);
}
#endif
converted++;
#if defined(SIMU)
RTOS_WAIT_MS(200);
#endif
const char* error = nullptr;
for (auto category_ptr : modelslist.getCategories()) {
for (auto model_ptr : *category_ptr) {
uint8_t model_version;
const char* filename = model_ptr->modelFilename;
TRACE("converting '%s' (%d/%d)", filename, converted, to_convert);
drawProgressScreen(filename, converted, to_convert);
error = readModel(filename, (uint8_t *)&g_model, sizeof(g_model), &model_version);
if (!error) {
convertModelData(model_version);
char path[256];
getModelPath(path, filename);
error = writeFile(path, (uint8_t *)&g_model, sizeof(g_model));
//TODO: what should be done with this error?
}
converted++;
#if defined(SIMU)
RTOS_WAIT_MS(200);
#endif
}
}
// reload models list
modelslist.clear();
modelslist.load();
}
#endif
void convertModelData(int version)
{
@@ -94,6 +94,11 @@ static void convertToStr(char* str, size_t len)
}
}
#if defined(COLORLCD)
extern const LayoutFactory * defaultLayout;
extern OpenTxTheme * defaultTheme;
#endif
void convertModelData_219_to_220(ModelData &model)
{
ModelData* oldModelAllocated = (ModelData*)malloc(sizeof(ModelData));
@@ -101,11 +106,10 @@ void convertModelData_219_to_220(ModelData &model)
memcpy(&oldModel, &model, sizeof(ModelData));
ModelData& newModel = (ModelData&)model;
convertToStr(model.header.name, LEN_MODEL_NAME_219);
for (uint8_t i=0; i<MAX_TIMERS_219; i++) {
//TODO: convert to new timers v220
// convert to new timers v220
TimerData& timer = newModel.timers[i];
convertToStr(timer.name, LEN_TIMER_NAME_219);
@@ -116,12 +120,16 @@ void convertModelData_219_to_220(ModelData &model)
if (timer_219.mode >= TMRMODE_START) {
timer_219.mode += 1;
}
if (timer_219.mode < TMRMODE_COUNT) {
if (timer_219.mode < TMRMODE_COUNT
&& timer_219.mode >=0) {
timer.mode = timer_219.mode;
}
else {
timer.mode = TMRMODE_START;
timer.swtch = timer_219.mode - (TMRMODE_COUNT - 1);
if (timer_219.mode > 0)
timer.swtch = timer_219.mode - (TMRMODE_COUNT - 1);
else
timer.swtch = timer_219.mode;
}
timer.start = timer_219.start;
@@ -145,7 +153,7 @@ void convertModelData_219_to_220(ModelData &model)
// CurveHeader.name
for (uint8_t i=0; i<MAX_CURVES_219; ++i) {
convertToStr(model.expoData[i].name, LEN_CURVE_NAME_219);
convertToStr(model.curves[i].name, LEN_CURVE_NAME_219);
}
// CustomFunctionData::play.name
@@ -191,21 +199,21 @@ void convertModelData_219_to_220(ModelData &model)
// TelemetryScriptData::file ?
// ModuleData::pxx2.receiverName
#if defined(PCBHORUS)
#if defined(COLORLCD)
// Clear CustomScreenData + TopBarPersistentData
// as they cannot be converted (missing option types)
memset(newModel.screenData, 0,
sizeof(newModel.screenData) +
sizeof(newModel.topbarData));
loadDefaultLayout();
if (defaultLayout) {
strcpy(newModel.screenData[0].LayoutId, defaultLayout->getId());
defaultLayout->initPersistentData(&newModel.screenData[0].layoutData);
}
#endif
free(oldModelAllocated);
}
#if defined(PCBHORUS)
extern OpenTxTheme * defaultTheme;
#endif
void convertRadioData_219_to_220(RadioData & settings)
{
TRACE("Radio conversion from v219 to v220");
@@ -217,7 +225,7 @@ void convertRadioData_219_to_220(RadioData & settings)
RadioData& oldSettings = *oldSettingsAllocated;
memcpy(&oldSettings, &settings, sizeof(RadioData));
#if defined(PCBHORUS)
#if defined(COLORLCD)
// Clear CustomScreenData + TopBarPersistentData
// as they cannot be converted (missing option types)
strcpy(g_eeGeneral.themeName, defaultTheme->getName());