EEPROM conversions on sky9x

This commit is contained in:
bsongis
2014-03-29 10:07:22 +01:00
parent 6b4c5bb754
commit bb57755f5e
6 changed files with 138 additions and 81 deletions
+90 -67
View File
@@ -44,7 +44,9 @@ PACK(typedef struct {
int8_t weight;
uint8_t curveMode;
char name[LEN_EXPOMIX_NAME];
#if defined(PCBTARANIS)
uint8_t spare[2];
#endif
int8_t curveParam;
}) ExpoData_v215;
@@ -445,60 +447,86 @@ void ConvertModel_215_to_216(ModelData &model)
#endif
for (uint8_t i=0; i<64; i++) {
MixData & mix = g_model.mixData[i];
MixData * mix = &g_model.mixData[i];
MixData_v215 * oldMix = &oldModel.mixData[i];
#if defined(PCBTARANIS)
mix.destCh = oldModel.mixData[i].destCh;
mix.phases = oldModel.mixData[i].phases;
mix.mltpx = oldModel.mixData[i].mltpx;
if (oldModel.mixData[i].carryTrim == TRIM_OFF) mix.carryTrim = TRIM_OFF;
mix.weight = ConvertGVAR_215_to_216(oldModel.mixData[i].weight);
mix.swtch = ConvertSwitch_215_to_216(oldModel.mixData[i].swtch);
if (oldModel.mixData[i].curveMode==0/*differential*/) {
mix.curve.type = CURVE_REF_DIFF;
mix.curve.value = oldModel.mixData[i].curveParam;
mix->destCh = oldMix->destCh;
mix->phases = oldMix->phases;
mix->mltpx = oldMix->mltpx;
if (oldMix->carryTrim == TRIM_OFF) mix->carryTrim = TRIM_OFF;
mix->weight = ConvertGVAR_215_to_216(oldMix->weight);
mix->swtch = ConvertSwitch_215_to_216(oldMix->swtch);
if (oldMix->curveMode==0/*differential*/) {
mix->curve.type = CURVE_REF_DIFF;
mix->curve.value = oldMix->curveParam;
}
else if (oldModel.mixData[i].curveParam <= 6) {
mix.curve.type = CURVE_REF_FUNC;
mix.curve.value = oldModel.mixData[i].curveParam;
else if (oldMix->curveParam <= 6) {
mix->curve.type = CURVE_REF_FUNC;
mix->curve.value = oldMix->curveParam;
}
else {
mix.curve.type = CURVE_REF_CUSTOM;
mix.curve.value = oldModel.mixData[i].curveParam - 6;
mix->curve.type = CURVE_REF_CUSTOM;
mix->curve.value = oldMix->curveParam - 6;
}
mix->mixWarn = oldMix->mixWarn;
mix->delayUp = oldMix->delayUp;
mix->delayDown = oldMix->delayDown;
mix->speedUp = oldMix->speedUp;
mix->speedDown = oldMix->speedDown;
mix->srcRaw = oldMix->srcRaw;
if (mix->srcRaw > 4 || oldMix->noExpo)
mix->srcRaw = ConvertSource_215_to_216(mix->srcRaw);
mix->offset = ConvertGVAR_215_to_216(oldMix->offset);
memcpy(mix->name, oldMix->name, LEN_EXPOMIX_NAME);
if (!GV_IS_GV_VALUE(mix->weight, 500, 500) && !GV_IS_GV_VALUE(mix->offset, 500, 500)) {
mix->offset = divRoundClosest(mix->offset * mix->weight, 100);
}
mix.mixWarn = oldModel.mixData[i].mixWarn;
mix.delayUp = oldModel.mixData[i].delayUp;
mix.delayDown = oldModel.mixData[i].delayDown;
mix.speedUp = oldModel.mixData[i].speedUp;
mix.speedDown = oldModel.mixData[i].speedDown;
mix.srcRaw = oldModel.mixData[i].srcRaw;
if (mix.srcRaw > 4 || oldModel.mixData[i].noExpo)
mix.srcRaw = ConvertSource_215_to_216(mix.srcRaw);
mix.offset = ConvertGVAR_215_to_216(oldModel.mixData[i].offset);
memcpy(mix.name, oldModel.mixData[i].name, LEN_EXPOMIX_NAME);
#else
memcpy(&mix, &oldModel.mixData[i], sizeof(mix));
mix->destCh = oldMix->destCh;
mix->mixWarn = oldMix->mixWarn;
mix->phases = oldMix->phases;
mix->curveMode = oldMix->curveMode;
mix->noExpo = oldMix->noExpo;
mix->carryTrim = oldMix->carryTrim;
mix->mltpx = oldMix->mltpx;
mix->weight = oldMix->weight;
mix->swtch = oldMix->swtch;
mix->curveParam = oldMix->curveParam;
mix->delayUp = oldMix->delayUp;
mix->delayDown = oldMix->delayDown;
mix->speedUp = oldMix->speedUp;
mix->speedDown = oldMix->speedDown;
mix->srcRaw = oldMix->srcRaw;
mix->offset = oldMix->offset;
memcpy(mix->name, oldMix->name, LEN_EXPOMIX_NAME);
#endif
if (!GV_IS_GV_VALUE(mix.weight, 500, 500) && !GV_IS_GV_VALUE(mix.offset, 500, 500)) {
mix.offset = divRoundClosest(mix.offset * mix.weight, 100);
}
}
for (uint8_t i=0; i<32; i++) {
#if defined(PCBTARANIS)
g_model.limitData[i].min = 10 * oldModel.limitData[i].min;
g_model.limitData[i].max = 10 * oldModel.limitData[i].max;
#else
g_model.limitData[i].min = oldModel.limitData[i].min;
g_model.limitData[i].max = oldModel.limitData[i].max;
#endif
g_model.limitData[i].ppmCenter = oldModel.limitData[i].ppmCenter;
g_model.limitData[i].offset = oldModel.limitData[i].offset;
g_model.limitData[i].symetrical = oldModel.limitData[i].symetrical;
g_model.limitData[i].revert = oldModel.limitData[i].revert;
#if defined(PCBTARANIS)
memcpy(&g_model.limitData[i].name, &oldModel.limitData[i].name, LEN_CHANNEL_NAME);
memcpy(g_model.limitData[i].name, oldModel.limitData[i].name, LEN_CHANNEL_NAME);
#endif
}
int indexes[NUM_STICKS] = { 0, 0, 0, 0 };
for (uint8_t i=0; i<32; i++) {
if (oldModel.expoData[i].mode) {
#if defined(PCBTARANIS)
uint8_t chn = oldModel.expoData[i].chn;
if (!oldModel.expoData[i].swtch && !oldModel.expoData[i].phases) {
int indexes[NUM_STICKS] = { 0, 0, 0, 0 };
#endif
for (uint8_t i=0; i<32; i++) {
ExpoData * expo = &g_model.expoData[i];
ExpoData_v215 * oldExpo = &oldModel.expoData[i];
if (oldExpo->mode) {
#if defined(PCBTARANIS)
uint8_t chn = oldExpo->chn;
if (!oldExpo->swtch && !oldExpo->phases) {
indexes[chn] = -1;
}
else if (indexes[chn] != -1) {
@@ -507,29 +535,36 @@ void ConvertModel_215_to_216(ModelData &model)
for (uint8_t j=chn+1; j<NUM_STICKS; j++) {
indexes[j] = i+1;
}
g_model.expoData[i].srcRaw = MIXSRC_Rud+chn;
g_model.expoData[i].chn = chn;
g_model.expoData[i].mode = oldModel.expoData[i].mode;
g_model.expoData[i].swtch = ConvertSwitch_215_to_216(oldModel.expoData[i].swtch);
g_model.expoData[i].phases = oldModel.expoData[i].phases;
g_model.expoData[i].weight = oldModel.expoData[i].weight;
memcpy(&g_model.expoData[i].name, &oldModel.expoData[i].name, LEN_EXPOMIX_NAME);
if (oldModel.expoData[i].curveMode==0/*expo*/) {
if (oldModel.expoData[i].curveParam) {
g_model.expoData[i].curve.type = CURVE_REF_EXPO;
g_model.expoData[i].curve.value = oldModel.expoData[i].curveParam;
expo->srcRaw = MIXSRC_Rud+chn;
expo->chn = chn;
expo->mode = oldExpo->mode;
expo->swtch = ConvertSwitch_215_to_216(oldExpo->swtch);
expo->phases = oldExpo->phases;
expo->weight = oldExpo->weight;
memcpy(expo->name, oldExpo->name, LEN_EXPOMIX_NAME);
if (oldExpo->curveMode==0/*expo*/) {
if (oldExpo->curveParam) {
expo->curve.type = CURVE_REF_EXPO;
expo->curve.value = oldExpo->curveParam;
}
}
else if (oldModel.expoData[i].curveParam <= 6) {
g_model.expoData[i].curve.type = CURVE_REF_FUNC;
g_model.expoData[i].curve.value = oldModel.expoData[i].curveParam;
else if (oldExpo->curveParam <= 6) {
expo->curve.type = CURVE_REF_FUNC;
expo->curve.value = oldExpo->curveParam;
}
else {
g_model.expoData[i].curve.type = CURVE_REF_CUSTOM;
g_model.expoData[i].curve.value = oldModel.expoData[i].curveParam - 7;
expo->curve.type = CURVE_REF_CUSTOM;
expo->curve.value = oldExpo->curveParam - 7;
}
#else
memcpy(&g_model.expoData[i], &oldModel.expoData[i], sizeof(g_model.expoData[i]));
expo->mode = oldExpo->mode;
expo->chn = oldExpo->chn;
expo->curveMode = oldExpo->curveMode;
expo->swtch = oldExpo->swtch;
expo->phases = oldExpo->phases;
expo->weight = oldExpo->weight;
memcpy(expo->name, oldExpo->name, LEN_EXPOMIX_NAME);
expo->curveParam = oldExpo->curveParam;
#endif
}
else {
@@ -540,7 +575,7 @@ void ConvertModel_215_to_216(ModelData &model)
for (int i=NUM_STICKS-1; i>=0; i--) {
int idx = indexes[i];
if (idx >= 0) {
ExpoData *expo = expoAddress(idx);
ExpoData * expo = expoAddress(idx);
memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
memclear(expo, sizeof(ExpoData));
expo->srcRaw = MIXSRC_Rud + i;
@@ -806,12 +841,7 @@ bool eeConvert()
MESSAGE(STR_EEPROMWARN, STR_EEPROM_CONVERTING, NULL, AU_EEPROM_FORMATTING); // TODO translations
// General Settings conversion
#if defined(PCBTARANIS)
theFile.openRlc(0);
theFile.readRlc((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral));
#else
#pragma message("TODO openRlc for sky9x")
#endif
loadGeneralSettings();
if (g_eeGeneral.version == 215) ConvertGeneralSettings_215_to_216(g_eeGeneral);
s_eeDirtyMsk = EE_GENERAL;
eeCheck(true);
@@ -822,16 +852,9 @@ bool eeConvert()
uint8_t currModel = g_eeGeneral.currModel;
for (uint8_t id=0; id<MAX_MODELS; id++) {
lcd_hline(61, 6*FH+5, 10+id*2, FORCE);
// lcd_putsnAtt(61, 7*FH)
lcdRefresh();
if (eeModelExists(id)) {
// TODO loadModel without anything else
#if defined(PCBTARANIS)
theFile.openRlc(FILE_MODEL(id));
theFile.readRlc((uint8_t*)&g_model, sizeof(g_model));
#else
#pragma message("TODO openRlc for sky9x")
#endif
loadModel(id);
int version = conversionVersionStart;
if (version == 215) {
version = 216;
+20 -12
View File
@@ -317,20 +317,28 @@ uint32_t get_current_block_number( uint32_t block_no, uint16_t *p_size, uint32_t
return block_no ;
}
// For conversions ...
void loadGeneralSettings()
{
memset(&g_eeGeneral, 0, sizeof(g_eeGeneral));
uint16_t size = min<int>(File_system[0].size, sizeof(g_eeGeneral));
if (size) {
read32_eeprom_data((File_system[0].block_no << 12) + sizeof(struct t_eeprom_header), (uint8_t *)&g_eeGeneral, size);
}
}
void loadModel(int index)
{
memset(&g_model, 0, sizeof(g_model));
int size = min<int>(File_system[index+1].size, sizeof(g_model));
if (size > 256) { // if loaded a fair amount
read32_eeprom_data((File_system[index+1].block_no << 12) + sizeof(struct t_eeprom_header), (uint8_t *)&g_model, size) ;
}
}
bool eeLoadGeneral()
{
uint16_t size = File_system[0].size;
memset(&g_eeGeneral, 0, sizeof(EEGeneral));
if (size > sizeof(EEGeneral)) {
size = sizeof(EEGeneral) ;
}
if (size) {
read32_eeprom_data( ( File_system[0].block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&g_eeGeneral, size) ;
}
loadGeneralSettings();
if (g_eeGeneral.version != EEPROM_VER) {
TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER);
if (!eeConvert())
+3
View File
@@ -101,5 +101,8 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc);
const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name);
#endif
void loadGeneralSettings();
void loadModel(int index);
#endif
+17
View File
@@ -868,6 +868,23 @@ void RlcFile::DisplayProgressBar(uint8_t x)
#define CHECK_EEPROM_VARIANT() (1)
#endif
// For conversions ...
#if defined(CPUARM)
void loadGeneralSettings()
{
memset(&g_eeGeneral, 0, sizeof(g_eeGeneral));
theFile.openRlc(FILE_GENERAL);
theFile.readRlc((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral));
}
void loadModel(int index)
{
memset(&g_model, 0, sizeof(g_model));
theFile.openRlc(FILE_MODEL(index));
theFile.readRlc((uint8_t*)&g_model, sizeof(g_model));
}
#endif
bool eeLoadGeneral()
{
theFile.openRlc(FILE_GENERAL);
+6
View File
@@ -241,4 +241,10 @@ const pm_char * eeBackupModel(uint8_t i_fileSrc);
const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name);
#endif
// For conversions
#if defined(CPUARM)
void loadGeneralSettings();
void loadModel(int index);
#endif
#endif
+2 -2
View File
@@ -439,7 +439,7 @@ PACK(typedef struct t_CurveRef {
#endif
#if defined(PCBTARANIS)
PACK(typedef struct t_ExpoData {
PACK(typedef struct {
uint8_t srcRaw;
uint16_t scale;
uint8_t chn;
@@ -550,7 +550,7 @@ PACK(typedef struct t_LimitData {
#define DELAY_MAX (25*DELAY_STEP) /* 25 seconds */
#define SLOW_MAX (25*SLOW_STEP) /* 25 seconds */
#if defined(PCBTARANIS)
PACK(typedef struct t_MixData {
PACK(typedef struct {
uint8_t destCh;
uint16_t phases;
uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means :=