Some b&w conversion fixes (more needed for color lcd)
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
#include "storage/sdcard_yaml.h"
|
||||
#endif
|
||||
|
||||
#if !defined(EEPROM_RLC)
|
||||
#if defined(STORAGE_MODELSLIST)
|
||||
static void drawProgressScreen(const char* filename, int progress, int total)
|
||||
{
|
||||
#if defined(COLORLCD)
|
||||
@@ -71,8 +71,7 @@ void convertBinRadioData(const char * path, int version)
|
||||
AU_NONE);
|
||||
|
||||
// Load models list before converting
|
||||
// TODO: force old .txt format
|
||||
modelslist.load();
|
||||
modelslist.load(ModelsList::Format::txt);
|
||||
|
||||
unsigned converted = 0;
|
||||
auto to_convert = modelslist.getModelsCount() + 1;
|
||||
@@ -82,16 +81,12 @@ void convertBinRadioData(const char * path, int version)
|
||||
|
||||
#if STORAGE_CONVERSIONS < 220
|
||||
if (version == 219) {
|
||||
// TODO: alloc specific structure for destination
|
||||
convertRadioData_219_to_220(path);
|
||||
}
|
||||
#endif
|
||||
#if STORAGE_CONVERSIONS < 220
|
||||
if (version == 220) {
|
||||
convertRadioData_220_to_221(path);
|
||||
// g_eeGeneral.version = EEPROM_VER;
|
||||
// storageDirty(EE_GENERAL);
|
||||
// storageCheck(true);
|
||||
}
|
||||
#endif
|
||||
converted++;
|
||||
@@ -110,31 +105,16 @@ void convertBinRadioData(const char * path, int version)
|
||||
TRACE("converting '%s' (%d/%d)", 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) {
|
||||
|
||||
// TODO: error handling
|
||||
convertBinModelData(filename, model_version);
|
||||
|
||||
#if defined(SDCARD_YAML)
|
||||
// patch model filename
|
||||
const char* ext = strrchr(filename, '.');
|
||||
if ((ext != nullptr) && !strncmp(ext, MODELS_EXT, 4)) {
|
||||
memcpy((void*)ext, (void*)YAML_EXT, sizeof(YAML_EXT) - 1);
|
||||
error = convertBinModelData(filename, model_version);
|
||||
if (error) {
|
||||
// add error counter?
|
||||
continue;
|
||||
}
|
||||
// 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++;
|
||||
@@ -145,10 +125,8 @@ void convertBinRadioData(const char * path, int version)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SDCARD_YAML)
|
||||
modelslist.save();
|
||||
storageDirty(EE_GENERAL);
|
||||
storageCheck(true);
|
||||
#if defined(SDCARD_YAML) || defined(STORAGE_MODELSLIST)
|
||||
modelslist.save(ModelsList::Format::yaml);
|
||||
#endif
|
||||
|
||||
// reload models list
|
||||
@@ -156,23 +134,25 @@ void convertBinRadioData(const char * path, int version)
|
||||
modelslist.load();
|
||||
}
|
||||
|
||||
void convertBinModelData(const char* filename, int version)
|
||||
const char* convertBinModelData(const char* filename, int version)
|
||||
{
|
||||
TRACE("convertModelData(%s,%d)", filename);
|
||||
|
||||
#if STORAGE_CONVERSIONS < 220
|
||||
if (version == 219) {
|
||||
convertModelData_219_to_220(filename);
|
||||
const char* error = convertModelData_219_to_220(filename);
|
||||
if (error) return error;
|
||||
version = 220;
|
||||
}
|
||||
#endif
|
||||
#if STORAGE_CONVERSIONS < 221
|
||||
if (version == 220) {
|
||||
convertModelData_220_to_221(filename);
|
||||
const char* error = convertModelData_220_to_221(filename);
|
||||
if (error) return error;
|
||||
version = 221;
|
||||
}
|
||||
#endif
|
||||
// TODO: error handling
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -225,7 +205,6 @@ bool eeConvert()
|
||||
RAISE_ALERT(STR_STORAGE_WARNING, STR_EEPROM_CONVERTING, NULL, AU_NONE);
|
||||
|
||||
// General Settings conversion
|
||||
eeLoadGeneralSettingsData();
|
||||
int version = conversionVersionStart;
|
||||
|
||||
#if STORAGE_CONVERSIONS < 220
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
// Entry points for converting radio & model data
|
||||
void convertBinRadioData(const char * path, int version);
|
||||
void convertBinModelData(const char * path, int version);
|
||||
const char* convertBinModelData(const char * path, int version);
|
||||
|
||||
bool eeConvert();
|
||||
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));
|
||||
|
||||
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);
|
||||
eeWriteGeneralSettingData((uint8_t *)rd_220, rd_size, true);
|
||||
} else {
|
||||
|
||||
@@ -29,10 +29,24 @@ namespace yaml_conv_220 {
|
||||
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,
|
||||
const YamlNode* root_node)
|
||||
void patchFilenameToYaml(char* str)
|
||||
{
|
||||
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));
|
||||
memset(data, 0, size);
|
||||
@@ -40,7 +54,9 @@ static const char* convertData_220_to_221(const char* path, unsigned size,
|
||||
uint8_t version;
|
||||
const char* error = loadFileBin(path, data, size, &version);
|
||||
if (!error) {
|
||||
// TODO: patch file name into .yml
|
||||
if (patchBinary) patchBinary(data);
|
||||
|
||||
patchFilenameToYaml(path);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
#define STORAGE_NUM_SLIDERS 2
|
||||
#endif
|
||||
|
||||
// #define NUM_XPOTS STORAGE_NUM_POTS
|
||||
#define NUM_XPOTS STORAGE_NUM_POTS
|
||||
// #define NUM_TRIMS 4
|
||||
// #define NUM_MOUSE_ANALOGS 0
|
||||
#define STORAGE_NUM_MOUSE_ANALOGS 0
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <debug.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace yaml_conv_220 {
|
||||
|
||||
#include "yaml_datastructs_funcs.cpp"
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <debug.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dataconstants_220.h"
|
||||
#include "datastructs_220.h"
|
||||
#include "myeeprom_220.h"
|
||||
|
||||
@@ -98,11 +98,24 @@ class ModelsList
|
||||
|
||||
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();
|
||||
|
||||
bool load();
|
||||
void save();
|
||||
bool load(Format fmt = Format::load_default);
|
||||
void save(Format fmt = Format::save_default);
|
||||
void clear();
|
||||
|
||||
const std::list<ModelsCategory *> & getCategories() const
|
||||
|
||||
@@ -32,9 +32,12 @@
|
||||
#include "yaml/yaml_datastructs.h"
|
||||
|
||||
#if defined(EEPROM_RLC)
|
||||
#include "storage/eeprom_common.h"
|
||||
#include "storage/eeprom_rlc.h"
|
||||
#endif
|
||||
|
||||
#include "storage/conversions/conversions.h"
|
||||
|
||||
const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, void* parser_ctx)
|
||||
{
|
||||
FIL file;
|
||||
@@ -68,7 +71,7 @@ const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, vo
|
||||
// Generic storage interface
|
||||
//
|
||||
|
||||
#if !defined(EEPROM_RLC)
|
||||
#if defined(STORAGE_MODELSLIST)
|
||||
void storageCreateModelsList()
|
||||
{
|
||||
modelslist.clear();
|
||||
@@ -97,14 +100,27 @@ const char * loadRadioSettings()
|
||||
{
|
||||
FILINFO fno;
|
||||
if (f_stat(RADIO_SETTINGS_YAML_PATH, &fno) != FR_OK) {
|
||||
#if !defined(EEPROM_RLC)
|
||||
return loadRadioSettingsBin();
|
||||
#else
|
||||
#if defined(STORAGE_MODELSLIST)
|
||||
uint8_t version;
|
||||
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
|
||||
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 nullptr;
|
||||
g_eeGeneral.version = versions[0];
|
||||
g_eeGeneral.variant = *variant;
|
||||
eeConvert();
|
||||
#else
|
||||
#error "Unsupported conversion format"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user