Some b&w conversion fixes (more needed for color lcd)
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
#include "storage/sdcard_yaml.h"
|
#include "storage/sdcard_yaml.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(EEPROM_RLC)
|
#if defined(STORAGE_MODELSLIST)
|
||||||
static void drawProgressScreen(const char* filename, int progress, int total)
|
static void drawProgressScreen(const char* filename, int progress, int total)
|
||||||
{
|
{
|
||||||
#if defined(COLORLCD)
|
#if defined(COLORLCD)
|
||||||
@@ -71,8 +71,7 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
AU_NONE);
|
AU_NONE);
|
||||||
|
|
||||||
// Load models list before converting
|
// Load models list before converting
|
||||||
// TODO: force old .txt format
|
modelslist.load(ModelsList::Format::txt);
|
||||||
modelslist.load();
|
|
||||||
|
|
||||||
unsigned converted = 0;
|
unsigned converted = 0;
|
||||||
auto to_convert = modelslist.getModelsCount() + 1;
|
auto to_convert = modelslist.getModelsCount() + 1;
|
||||||
@@ -82,16 +81,12 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
|
|
||||||
#if STORAGE_CONVERSIONS < 220
|
#if STORAGE_CONVERSIONS < 220
|
||||||
if (version == 219) {
|
if (version == 219) {
|
||||||
// TODO: alloc specific structure for destination
|
|
||||||
convertRadioData_219_to_220(path);
|
convertRadioData_219_to_220(path);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if STORAGE_CONVERSIONS < 220
|
#if STORAGE_CONVERSIONS < 220
|
||||||
if (version == 220) {
|
if (version == 220) {
|
||||||
convertRadioData_220_to_221(path);
|
convertRadioData_220_to_221(path);
|
||||||
// g_eeGeneral.version = EEPROM_VER;
|
|
||||||
// storageDirty(EE_GENERAL);
|
|
||||||
// storageCheck(true);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
converted++;
|
converted++;
|
||||||
@@ -110,31 +105,16 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
TRACE("converting '%s' (%d/%d)", filename, converted, to_convert);
|
TRACE("converting '%s' (%d/%d)", filename, converted, to_convert);
|
||||||
drawProgressScreen(filename, converted, to_convert);
|
drawProgressScreen(filename, converted, to_convert);
|
||||||
|
|
||||||
error = readModelBin(filename, (uint8_t *)&g_model, sizeof(g_model), &model_version);
|
// read only the version number (size=0)
|
||||||
|
error = readModelBin(filename, nullptr, 0, &model_version);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
convertBinModelData(filename, model_version);
|
error = convertBinModelData(filename, model_version);
|
||||||
|
if (error) {
|
||||||
#if defined(SDCARD_YAML)
|
// add error counter?
|
||||||
// patch model filename
|
continue;
|
||||||
const char* ext = strrchr(filename, '.');
|
|
||||||
if ((ext != nullptr) && !strncmp(ext, MODELS_EXT, 4)) {
|
|
||||||
memcpy((void*)ext, (void*)YAML_EXT, sizeof(YAML_EXT) - 1);
|
|
||||||
}
|
}
|
||||||
// in case it's the current model, patch it as well
|
|
||||||
if (!strncmp(filename, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME)) {
|
|
||||||
strncpy(g_eeGeneral.currModelFilename, filename, LEN_MODEL_FILENAME+1);
|
|
||||||
}
|
|
||||||
// and write to YAML file
|
|
||||||
error = writeModelYaml(filename);
|
|
||||||
#else
|
|
||||||
char path[256];
|
|
||||||
getModelPath(path, filename);
|
|
||||||
|
|
||||||
error = writeFileBin(path, (uint8_t *)&g_model, sizeof(g_model));
|
|
||||||
#endif
|
|
||||||
//TODO: what should be done with this error?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
converted++;
|
converted++;
|
||||||
@@ -145,10 +125,8 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SDCARD_YAML)
|
#if defined(SDCARD_YAML) || defined(STORAGE_MODELSLIST)
|
||||||
modelslist.save();
|
modelslist.save(ModelsList::Format::yaml);
|
||||||
storageDirty(EE_GENERAL);
|
|
||||||
storageCheck(true);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// reload models list
|
// reload models list
|
||||||
@@ -156,23 +134,25 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
modelslist.load();
|
modelslist.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convertBinModelData(const char* filename, int version)
|
const char* convertBinModelData(const char* filename, int version)
|
||||||
{
|
{
|
||||||
TRACE("convertModelData(%s,%d)", filename);
|
TRACE("convertModelData(%s,%d)", filename);
|
||||||
|
|
||||||
#if STORAGE_CONVERSIONS < 220
|
#if STORAGE_CONVERSIONS < 220
|
||||||
if (version == 219) {
|
if (version == 219) {
|
||||||
convertModelData_219_to_220(filename);
|
const char* error = convertModelData_219_to_220(filename);
|
||||||
|
if (error) return error;
|
||||||
version = 220;
|
version = 220;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if STORAGE_CONVERSIONS < 221
|
#if STORAGE_CONVERSIONS < 221
|
||||||
if (version == 220) {
|
if (version == 220) {
|
||||||
convertModelData_220_to_221(filename);
|
const char* error = convertModelData_220_to_221(filename);
|
||||||
|
if (error) return error;
|
||||||
version = 221;
|
version = 221;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// TODO: error handling
|
return nullptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -225,7 +205,6 @@ bool eeConvert()
|
|||||||
RAISE_ALERT(STR_STORAGE_WARNING, STR_EEPROM_CONVERTING, NULL, AU_NONE);
|
RAISE_ALERT(STR_STORAGE_WARNING, STR_EEPROM_CONVERTING, NULL, AU_NONE);
|
||||||
|
|
||||||
// General Settings conversion
|
// General Settings conversion
|
||||||
eeLoadGeneralSettingsData();
|
|
||||||
int version = conversionVersionStart;
|
int version = conversionVersionStart;
|
||||||
|
|
||||||
#if STORAGE_CONVERSIONS < 220
|
#if STORAGE_CONVERSIONS < 220
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
// Entry points for converting radio & model data
|
// Entry points for converting radio & model data
|
||||||
void convertBinRadioData(const char * path, int version);
|
void convertBinRadioData(const char * path, int version);
|
||||||
void convertBinModelData(const char * path, int version);
|
const char* convertBinModelData(const char * path, int version);
|
||||||
|
|
||||||
bool eeConvert();
|
bool eeConvert();
|
||||||
void eeConvertModel(int id, int version);
|
void eeConvertModel(int id, int version);
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ const char* convertRadioData_219_to_220()
|
|||||||
auto rd_220 = reinterpret_cast<uint8_t*>(malloc(rd_size));
|
auto rd_220 = reinterpret_cast<uint8_t*>(malloc(rd_size));
|
||||||
|
|
||||||
uint16_t read = eeLoadGeneralSettingsData(rd_220, rd_size);
|
uint16_t read = eeLoadGeneralSettingsData(rd_220, rd_size);
|
||||||
if (read == rd_size) {
|
if (read >= rd_size - 1) { // 220 started with 1 byte less than 219
|
||||||
convertRadioData_219_to_220((void*)rd_220);
|
convertRadioData_219_to_220((void*)rd_220);
|
||||||
eeWriteGeneralSettingData((uint8_t *)rd_220, rd_size, true);
|
eeWriteGeneralSettingData((uint8_t *)rd_220, rd_size, true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -29,10 +29,24 @@ namespace yaml_conv_220 {
|
|||||||
const YamlNode* get_partialmodel_nodes();
|
const YamlNode* get_partialmodel_nodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined(EEPROM_RLC)
|
#if defined(STORAGE_MODELSLIST)
|
||||||
|
|
||||||
static const char* convertData_220_to_221(const char* path, unsigned size,
|
void patchFilenameToYaml(char* str)
|
||||||
const YamlNode* root_node)
|
{
|
||||||
|
constexpr unsigned bin_len = sizeof(MODELS_EXT) - 1;
|
||||||
|
constexpr unsigned yml_len = sizeof(YAML_EXT) - 1;
|
||||||
|
|
||||||
|
// patch file extension
|
||||||
|
const char* ext = strrchr(path, '.');
|
||||||
|
if (ext && (strlen(ext) == bin_len) &&
|
||||||
|
!strncmp(ext, STR_MODELS_EXT, bin_len)) {
|
||||||
|
memcpy((void*)ext, (void*)STR_YAML_EXT, yml_len + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* convertData_220_to_221(
|
||||||
|
const char* path, unsigned size, const YamlNode* root_node,
|
||||||
|
void (*patchBinary)(uint8_t*) = nullptr)
|
||||||
{
|
{
|
||||||
auto data = reinterpret_cast<uint8_t*>(malloc(size));
|
auto data = reinterpret_cast<uint8_t*>(malloc(size));
|
||||||
memset(data, 0, size);
|
memset(data, 0, size);
|
||||||
@@ -40,7 +54,9 @@ static const char* convertData_220_to_221(const char* path, unsigned size,
|
|||||||
uint8_t version;
|
uint8_t version;
|
||||||
const char* error = loadFileBin(path, data, size, &version);
|
const char* error = loadFileBin(path, data, size, &version);
|
||||||
if (!error) {
|
if (!error) {
|
||||||
// TODO: patch file name into .yml
|
if (patchBinary) patchBinary(data);
|
||||||
|
|
||||||
|
patchFilenameToYaml(path);
|
||||||
error = writeFileYaml(path, root_node, data);
|
error = writeFileYaml(path, root_node, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,13 +67,22 @@ static const char* convertData_220_to_221(const char* path, unsigned size,
|
|||||||
const char* convertModelData_220_to_221(const char* path)
|
const char* convertModelData_220_to_221(const char* path)
|
||||||
{
|
{
|
||||||
constexpr unsigned md_size = sizeof(bin_storage_220::ModelData);
|
constexpr unsigned md_size = sizeof(bin_storage_220::ModelData);
|
||||||
return convertData_220_to_221(path, md_size, yaml_conv_220::get_modeldata_nodes());
|
return convertData_220_to_221(path, md_size,
|
||||||
|
yaml_conv_220::get_modeldata_nodes());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void patchCurrentModelFilename(uint8_t* data)
|
||||||
|
{
|
||||||
|
auto rd = reinterpret_cast<bin_storage_220::RadioData*>(data);
|
||||||
|
patchFilenameToYaml(rd->currModelFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* convertRadioData_220_to_221(const char* path)
|
const char* convertRadioData_220_to_221(const char* path)
|
||||||
{
|
{
|
||||||
constexpr unsigned rd_size = sizeof(bin_storage_220::RadioData);
|
constexpr unsigned rd_size = sizeof(bin_storage_220::RadioData);
|
||||||
return convertData_220_to_221(path, rd_size, yaml_conv_220::get_radiodata_nodes());
|
return convertData_220_to_221(path, rd_size,
|
||||||
|
yaml_conv_220::get_radiodata_nodes(),
|
||||||
|
patchCurrentModelFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -74,7 +74,7 @@
|
|||||||
#define STORAGE_NUM_SLIDERS 2
|
#define STORAGE_NUM_SLIDERS 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// #define NUM_XPOTS STORAGE_NUM_POTS
|
#define NUM_XPOTS STORAGE_NUM_POTS
|
||||||
// #define NUM_TRIMS 4
|
// #define NUM_TRIMS 4
|
||||||
// #define NUM_MOUSE_ANALOGS 0
|
// #define NUM_MOUSE_ANALOGS 0
|
||||||
#define STORAGE_NUM_MOUSE_ANALOGS 0
|
#define STORAGE_NUM_MOUSE_ANALOGS 0
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <debug.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
namespace yaml_conv_220 {
|
namespace yaml_conv_220 {
|
||||||
|
|
||||||
#include "yaml_datastructs_funcs.cpp"
|
#include "yaml_datastructs_funcs.cpp"
|
||||||
|
|||||||
@@ -19,9 +19,6 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <debug.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "dataconstants_220.h"
|
#include "dataconstants_220.h"
|
||||||
#include "datastructs_220.h"
|
#include "datastructs_220.h"
|
||||||
#include "myeeprom_220.h"
|
#include "myeeprom_220.h"
|
||||||
|
|||||||
@@ -98,11 +98,24 @@ class ModelsList
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
enum class Format {
|
||||||
|
txt,
|
||||||
|
#if defined(SDCARD_YAML)
|
||||||
|
yaml,
|
||||||
|
yaml_txt,
|
||||||
|
load_default = yaml_txt,
|
||||||
|
save_default = yaml,
|
||||||
|
#else
|
||||||
|
load_default = txt,
|
||||||
|
save_default = txt,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
ModelsList();
|
ModelsList();
|
||||||
~ModelsList();
|
~ModelsList();
|
||||||
|
|
||||||
bool load();
|
bool load(Format fmt = Format::load_default);
|
||||||
void save();
|
void save(Format fmt = Format::save_default);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
const std::list<ModelsCategory *> & getCategories() const
|
const std::list<ModelsCategory *> & getCategories() const
|
||||||
|
|||||||
@@ -32,9 +32,12 @@
|
|||||||
#include "yaml/yaml_datastructs.h"
|
#include "yaml/yaml_datastructs.h"
|
||||||
|
|
||||||
#if defined(EEPROM_RLC)
|
#if defined(EEPROM_RLC)
|
||||||
|
#include "storage/eeprom_common.h"
|
||||||
#include "storage/eeprom_rlc.h"
|
#include "storage/eeprom_rlc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "storage/conversions/conversions.h"
|
||||||
|
|
||||||
const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, void* parser_ctx)
|
const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, void* parser_ctx)
|
||||||
{
|
{
|
||||||
FIL file;
|
FIL file;
|
||||||
@@ -68,7 +71,7 @@ const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, vo
|
|||||||
// Generic storage interface
|
// Generic storage interface
|
||||||
//
|
//
|
||||||
|
|
||||||
#if !defined(EEPROM_RLC)
|
#if defined(STORAGE_MODELSLIST)
|
||||||
void storageCreateModelsList()
|
void storageCreateModelsList()
|
||||||
{
|
{
|
||||||
modelslist.clear();
|
modelslist.clear();
|
||||||
@@ -97,14 +100,27 @@ const char * loadRadioSettings()
|
|||||||
{
|
{
|
||||||
FILINFO fno;
|
FILINFO fno;
|
||||||
if (f_stat(RADIO_SETTINGS_YAML_PATH, &fno) != FR_OK) {
|
if (f_stat(RADIO_SETTINGS_YAML_PATH, &fno) != FR_OK) {
|
||||||
#if !defined(EEPROM_RLC)
|
#if defined(STORAGE_MODELSLIST)
|
||||||
return loadRadioSettingsBin();
|
uint8_t version;
|
||||||
#else
|
const char* error = loadFileBin(RADIO_SETTINGS_PATH, nullptr, 0, &version);
|
||||||
|
if (error) {
|
||||||
|
TRACE("loadRadioSettings error=%s", error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
convertBinRadioData(RADIO_SETTINGS_PATH, version);
|
||||||
|
#elif defined(EEPROM_RLC)
|
||||||
// Load from EEPROM
|
// Load from EEPROM
|
||||||
if (!eepromOpen() || !eeLoadGeneral(true)) {
|
uint8_t versions[3];
|
||||||
|
uint16_t* variant = (uint16_t*)&versions[1];
|
||||||
|
if (!eepromOpen() || (eeLoadGeneralSettingsData(versions, 3) != 3)
|
||||||
|
|| (*variant != EEPROM_VARIANT)) {
|
||||||
return "ERROR";
|
return "ERROR";
|
||||||
}
|
}
|
||||||
return nullptr;
|
g_eeGeneral.version = versions[0];
|
||||||
|
g_eeGeneral.variant = *variant;
|
||||||
|
eeConvert();
|
||||||
|
#else
|
||||||
|
#error "Unsupported conversion format"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user