[color] Batch conversions
This commit is contained in:
@@ -21,16 +21,107 @@
|
||||
#include "opentx.h"
|
||||
#include "conversions.h"
|
||||
|
||||
#if defined(SDCARD)
|
||||
#include "storage/modelslist.h"
|
||||
#include "storage/sdcard_common.h"
|
||||
|
||||
#if defined(COLORLCD)
|
||||
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();
|
||||
}
|
||||
#endif
|
||||
|
||||
void convertRadioData(int version)
|
||||
{
|
||||
TRACE("convertRadioData(%d)", version);
|
||||
|
||||
#if defined(COLORLCD)
|
||||
// the theme has not been loaded before
|
||||
static_cast<OpenTxTheme*>(theme)->load();
|
||||
#endif
|
||||
|
||||
// Init backlight mode before entering alert screens
|
||||
requiredBacklightBright = BACKLIGHT_FORCED_ON;
|
||||
|
||||
#if defined(PCBHORUS)
|
||||
g_eeGeneral.blOffBright = 20;
|
||||
#endif
|
||||
|
||||
RAISE_ALERT(STR_STORAGE_WARNING, STR_SDCARD_CONVERSION_REQUIRE, NULL,
|
||||
AU_NONE);
|
||||
|
||||
unsigned converted = 0;
|
||||
auto to_convert = modelslist.getModelsCount() + 1;
|
||||
|
||||
#if defined(COLORLCD)
|
||||
drawProgressScreen(RADIO_FILENAME, converted, to_convert);
|
||||
#endif
|
||||
|
||||
TRACE("converting '%s' (%d/%d)", RADIO_FILENAME, converted, to_convert);
|
||||
|
||||
#if STORAGE_CONVERSIONS < 220
|
||||
if (version == 219) {
|
||||
convertRadioData_219_to_220(g_eeGeneral);
|
||||
}
|
||||
#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);
|
||||
#if defined(COLORLCD)
|
||||
drawProgressScreen(filename, converted, to_convert);
|
||||
#endif
|
||||
|
||||
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,7 +106,6 @@ 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++) {
|
||||
@@ -191,21 +195,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 +221,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());
|
||||
|
||||
Reference in New Issue
Block a user