1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 16:55:20 +03:00

Conversions errors (negative switches)

This commit is contained in:
Bertrand Songis 2014-02-11 11:29:10 +01:00
parent f5797b2b3a
commit 2c60b84258
5 changed files with 31 additions and 19 deletions

View file

@ -10,3 +10,6 @@
/*.o
/*.bin
/*.lst
/SCRIPTS
/SOUNDS
/LOGS

View file

@ -111,8 +111,6 @@ PACK(typedef struct {
}) MixData_v215;
#endif
PACK(typedef struct {
int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw
uint16_t start:12;
@ -235,7 +233,9 @@ int ConvertSource_215_to_216(int source, bool insertZero=false)
int ConvertSwitch_215_to_216(int swtch)
{
if (swtch <= SWSRC_LAST_SWITCH)
if (swtch < 0)
return -ConvertSwitch_215_to_216(-swtch);
else if (swtch <= SWSRC_LAST_SWITCH)
return swtch;
else
return swtch + (2*4) + (2*6); // 4 trims and 2 * 6-pos added as switches
@ -271,22 +271,28 @@ void ConvertModel_215_to_216(ModelData &model)
// Mixes: GVARS in weight moved from 512 to 4096 and -512 to -4096, because GVARS may be used in limits [-1250:1250]
// Switches: two 6-pos pots added, REa added to Sky9x
TRACE("Model conversion from v215 to v216");
assert(sizeof(ModelData_v215) <= sizeof(ModelData));
ModelData_v215 oldModel;
memcpy(&oldModel, &model, sizeof(oldModel));
memset(&model, 0, sizeof(ModelData));
char name[LEN_MODEL_NAME+1];
zchar2str(name, oldModel.header.name, LEN_MODEL_NAME);
TRACE("Model %s conversion from v215 to v216", name);
memcpy(&g_model.header, &oldModel.header, sizeof(g_model.header));
for (uint8_t i=0; i<2; i++) {
g_model.timers[i].mode = oldModel.timers[i].mode > 4 ? ConvertSwitch_215_to_216(oldModel.timers[i].mode): oldModel.timers[i].mode;
g_model.timers[i].start = oldModel.timers[i].start;
g_model.timers[i].minuteBeep = oldModel.timers[i].minuteBeep;
g_model.timers[i].persistent = oldModel.timers[i].persistent;
g_model.timers[i].countdownBeep = oldModel.timers[i].countdownBeep;
g_model.timers[i].value = oldModel.timers[i].value;
TimerData & timer = g_model.timers[i];
if (oldModel.timers[i].mode >= TMRMODE_FIRST_SWITCH)
timer.mode = TMRMODE_FIRST_SWITCH + ConvertSwitch_215_to_216(oldModel.timers[i].mode - TMRMODE_FIRST_SWITCH + 1) - 1;
else
timer.mode = oldModel.timers[i].mode;
timer.start = oldModel.timers[i].start;
timer.minuteBeep = oldModel.timers[i].minuteBeep;
timer.persistent = oldModel.timers[i].persistent;
timer.countdownBeep = oldModel.timers[i].countdownBeep;
timer.value = oldModel.timers[i].value;
}
g_model.protocol = oldModel.protocol;
g_model.thrTrim = oldModel.thrTrim;

View file

@ -1404,11 +1404,14 @@ enum MixSources {
#define MIN_POINTS 3
#define MAX_POINTS 17
#define TMRMODE_NONE 0
#define TMRMODE_ABS 1
#define TMRMODE_THR 2
#define TMRMODE_THR_REL 3
#define TMRMODE_THR_TRG 4
enum TimerModes {
TMRMODE_NONE,
TMRMODE_ABS,
TMRMODE_THR,
TMRMODE_THR_REL,
TMRMODE_THR_TRG,
TMRMODE_FIRST_SWITCH
};
#define COUNTDOWN_SILENT 0
#define COUNTDOWN_BEEPS 1
@ -1504,7 +1507,7 @@ enum FailsafeModes {
#define BeepANACenter uint8_t
#endif
PACK(typedef struct t_ModelHeader {
PACK(typedef struct {
char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName
uint8_t modelId;
MODELDATA_BITMAP

View file

@ -198,7 +198,7 @@ char idx2char(int8_t idx)
return ' ';
}
#if defined(PCBTARANIS)
#if defined(CPUARM)
int8_t char2idx(char c)
{
if (c == '_') return 37;

View file

@ -749,7 +749,7 @@ extern uint8_t pxxFlag[NUM_MODULES];
#define ZCHAR_MAX (LEN_STD_CHARS + LEN_SPECIAL_CHARS)
char idx2char(int8_t idx);
#if defined(PCBTARANIS)
#if defined(CPUARM)
int8_t char2idx(char c);
void str2zchar(char *dest, const char *src, int size);
void zchar2str(char *dest, const char *src, int size);