TrmR / TrmE / TrmT / TrmA sources added to mixers and custom switches

The choice for Trim in mixers will be: OFF / ON / Rud / Ele / Thr / Ail
EEPROM formatted on ARM when invalid EEPROM
No EEPROM format when ARM board USB powered
This commit is contained in:
bsongis
2012-05-15 21:00:57 +00:00
parent 0e5360f07f
commit 45bdef6b3a
14 changed files with 116 additions and 124 deletions
+4
View File
@@ -72,6 +72,10 @@ inline void init_soft_power()
uint32_t check_soft_power() uint32_t check_soft_power()
{ {
#ifdef SIMU
return e_power_on;
#endif
if ( PIOC->PIO_PDSR & 0x02000000 ) if ( PIOC->PIO_PDSR & 0x02000000 )
{ {
return e_power_usb ; // Detected USB return e_power_usb ; // Detected USB
+8 -2
View File
@@ -529,8 +529,14 @@ void eeReadAll()
modelDefault(0); modelDefault(0);
STORE_GENERALVARS; if (check_soft_power() < e_power_usb) { // Usb on or power off
STORE_MODELVARS; /* we remove all models */
for (uint32_t i=0; i<MAX_MODELS; i++)
eeDeleteModel(i);
STORE_GENERALVARS;
STORE_MODELVARS;
}
} }
else else
{ {
+10 -10
View File
@@ -462,28 +462,28 @@ void putsChnRaw(uint8_t x, uint8_t y, uint8_t idx, uint8_t att)
{ {
if (idx==0) if (idx==0)
lcd_putsiAtt(x, y, STR_MMMINV, 0, att); lcd_putsiAtt(x, y, STR_MMMINV, 0, att);
else if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2+3) else if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+NUM_CYC)
lcd_putsiAtt(x, y, STR_VSRCRAW, idx-1, att); lcd_putsiAtt(x, y, STR_VSRCRAW, idx-1, att);
else if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2+3+NUM_PPM) else if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+NUM_CYC+NUM_PPM)
putsStrIdx(x, y, STR_PPM, idx - (NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2+3), att); putsStrIdx(x, y, STR_PPM, idx - (NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+NUM_CYC), att);
else if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2+3+NUM_PPM+NUM_CHNOUT) else if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+NUM_CYC+NUM_PPM+NUM_CHNOUT)
putsStrIdx(x, y, STR_CH, idx - (NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2+3+NUM_PPM), att); putsStrIdx(x, y, STR_CH, idx - (NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+NUM_CYC+NUM_PPM), att);
else else
lcd_putsiAtt(x, y, STR_VTELEMCHNS, idx-(NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2+3+NUM_PPM+NUM_CHNOUT), att); lcd_putsiAtt(x, y, STR_VTELEMCHNS, idx-(NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+NUM_CYC+NUM_PPM+NUM_CHNOUT), att);
} }
void putsChn(uint8_t x, uint8_t y, uint8_t idx, uint8_t att) void putsChn(uint8_t x, uint8_t y, uint8_t idx, uint8_t att)
{ {
if (idx > 0 && idx <= NUM_CHNOUT) if (idx > 0 && idx <= NUM_CHNOUT)
putsChnRaw(x, y, idx+(NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2+3+NUM_PPM), att); putsChnRaw(x, y, idx+(NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+NUM_CYC+NUM_PPM), att);
} }
void putsMixerSource(uint8_t x, uint8_t y, uint8_t idx, uint8_t att) void putsMixerSource(uint8_t x, uint8_t y, uint8_t idx, uint8_t att)
{ {
if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2) if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2)
putsChnRaw(x, y, idx, att); putsChnRaw(x, y, idx, att);
else if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+2+MAX_SWITCH) else if (idx<=NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+MAX_SWITCH)
putsSwitches(x, y, idx-NUM_STICKS-NUM_POTS-NUM_ROTARY_ENCODERS-2, att); putsSwitches(x, y, idx-NUM_STICKS-NUM_POTS-NUM_ROTARY_ENCODERS-NUM_STICKS-2, att);
else else
putsChnRaw(x, y, idx-MAX_SWITCH, att); putsChnRaw(x, y, idx-MAX_SWITCH, att);
} }
+1 -1
View File
@@ -189,7 +189,7 @@ void menuMainView(uint8_t event)
} }
{ {
uint8_t phase = getFlightPhase(); uint8_t phase = s_perout_flight_phase;
lcd_putsnAtt(6*FW, 2*FH, g_model.phaseData[phase].name, sizeof(g_model.phaseData[phase].name), ZCHAR); lcd_putsnAtt(6*FW, 2*FH, g_model.phaseData[phase].name, sizeof(g_model.phaseData[phase].name), ZCHAR);
uint8_t att = (g_vbat100mV < g_eeGeneral.vBatWarn ? BLINK|INVERS : 0) | DBLSIZE; uint8_t att = (g_vbat100mV < g_eeGeneral.vBatWarn ? BLINK|INVERS : 0) | DBLSIZE;
+10 -13
View File
@@ -706,7 +706,7 @@ void menuProcModel(uint8_t event)
if (m_posHorz > 1) m_posHorz = 1; if (m_posHorz > 1) m_posHorz = 1;
int8_t x = limit((int8_t)0, (int8_t)g_model.ppmNCH, (int8_t)2); int8_t x = limit((int8_t)0, (int8_t)g_model.ppmNCH, (int8_t)2);
g_model.ppmNCH = x; g_model.ppmNCH = x;
lcd_putsiAtt(MODEL_PARAM_OFS+7*FW, y, STR_DSM2MODE, x, (attr && m_posHorz==1) ? blink : 0); lcd_putsiAtt(MODEL_PARAM_OFS+5*FW, y, STR_DSM2MODE, x, (attr && m_posHorz==1) ? blink : 0);
} }
#endif #endif
else if (attr) { else if (attr) {
@@ -755,16 +755,14 @@ void menuProcModel(uint8_t event)
// TODO port PPM16 ppmDelay from er9x // TODO port PPM16 ppmDelay from er9x
#if defined(DSM2) || defined(PXX) #if defined(DSM2) || defined(PXX)
else if (IS_DSM2_PROTOCOL(protocol) || IS_PXX_PROTOCOL(protocol)) { else if (IS_DSM2_PROTOCOL(protocol) || IS_PXX_PROTOCOL(protocol)) {
lcd_putsLeft( y, STR_RXNUM); if (attr && m_posHorz > 0 && IS_DSM2_PROTOCOL(protocol))
m_posHorz = 0;
lcd_putsLeft(y, STR_RXNUM);
lcd_outdezNAtt(MODEL_PARAM_OFS-(IS_DSM2_PROTOCOL(protocol) ? 0 : 3*FW), y, g_model.modelId, ((attr && m_posHorz==0) ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0) | LEADING0|LEFT, 2); lcd_outdezNAtt(MODEL_PARAM_OFS-(IS_DSM2_PROTOCOL(protocol) ? 0 : 3*FW), y, g_model.modelId, ((attr && m_posHorz==0) ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0) | LEADING0|LEFT, 2);
if (attr && (s_editMode>0 || p1valdiff)) { if (attr && (IS_DSM2_PROTOCOL(protocol) || (m_posHorz==0 && (s_editMode>0 || p1valdiff))))
switch (m_posHorz) { CHECK_INCDEC_MODELVAR(event, g_model.modelId, 0, 99);
case 0:
CHECK_INCDEC_MODELVAR(event, g_model.modelId, 0, 99);
break;
}
}
#if defined(PXX) #if defined(PXX)
if (protocol == PROTO_PXX) { if (protocol == PROTO_PXX) {
@@ -940,7 +938,7 @@ void menuProcPhasesAll(uint8_t event)
att = (sub==MAX_PHASES && !trimsCheckTimer) ? INVERS : 0; att = (sub==MAX_PHASES && !trimsCheckTimer) ? INVERS : 0;
lcd_putsAtt(0, 7*FH, STR_CHECKTRIMS, att); lcd_putsAtt(0, 7*FH, STR_CHECKTRIMS, att);
putsFlightPhase(6*FW, 7*FH, getFlightPhase()+1, att); putsFlightPhase(6*FW, 7*FH, s_perout_flight_phase+1, att);
} }
#endif #endif
@@ -1474,8 +1472,8 @@ void menuProcMixOne(uint8_t event)
break; break;
case MIX_FIELD_TRIM: case MIX_FIELD_TRIM:
lcd_puts(2*FW, y, STR_TRIM); lcd_puts(2*FW, y, STR_TRIM);
lcd_putsiAtt(FW*10, y, STR_VMIXTRIMS, (md2->srcRaw <= 4) ? md2->carryTrim : 1, attr); lcd_putsiAtt(FW*10, y, STR_VMIXTRIMS, 1-md2->carryTrim, attr);
if (attr) CHECK_INCDEC_MODELVAR( event, md2->carryTrim, TRIM_ON, TRIM_OFFSET); if (attr) md2->carryTrim = -checkIncDecModel(event, -(int8_t)md2->carryTrim, -TRIM_OFF, -TRIM_AIL);
break; break;
case MIX_FIELD_CURVE: case MIX_FIELD_CURVE:
lcd_puts(2*FW, y, STR_CURVES); lcd_puts(2*FW, y, STR_CURVES);
@@ -2457,7 +2455,6 @@ void menuProcTelemetry(uint8_t event)
#endif #endif
#ifdef TEMPLATES #ifdef TEMPLATES
// TODO s_noHi needed?
void menuProcTemplates(uint8_t _event) void menuProcTemplates(uint8_t _event)
{ {
uint8_t event = (s_warning ? 0 : _event); uint8_t event = (s_warning ? 0 : _event);
+15 -8
View File
@@ -49,11 +49,11 @@
#define BEEP_VAL ( (g_eeGeneral.warnOpts & WARN_BVAL_BIT) >>3 ) #define BEEP_VAL ( (g_eeGeneral.warnOpts & WARN_BVAL_BIT) >>3 )
#if defined(PCBARM) #if defined(PCBARM)
#define EEPROM_VER 208 #define EEPROM_VER 209
#elif defined(PCBV4) #elif defined(PCBV4)
#define EEPROM_VER 208 #define EEPROM_VER 209
#else #else
#define EEPROM_VER 208 #define EEPROM_VER 209
#endif #endif
#ifndef PACK #ifndef PACK
@@ -196,6 +196,10 @@ enum MixSources {
MIXSRC_REe, MIXSRC_REe,
#endif #endif
#endif #endif
MIXSRC_TrimRud,
MIXSRC_TrimEle,
MIXSRC_TrimThr,
MIXSRC_TrimAil,
MIXSRC_MAX , MIXSRC_MAX ,
MIXSRC_3POS, MIXSRC_3POS,
MIXSRC_THR, MIXSRC_THR,
@@ -224,9 +228,12 @@ enum MixSources {
MIXSRC_CH16 = MIXSRC_CH11 + 5 MIXSRC_CH16 = MIXSRC_CH11 + 5
}; };
#define TRIM_ON 0
#define TRIM_OFF 1 #define TRIM_OFF 1
#define TRIM_OFFSET 2 #define TRIM_ON 0
#define TRIM_RUD -1
#define TRIM_ELE -2
#define TRIM_THR -3
#define TRIM_AIL -4
#define MLTPX_ADD 0 #define MLTPX_ADD 0
#define MLTPX_MUL 1 #define MLTPX_MUL 1
@@ -247,7 +254,7 @@ PACK(typedef struct t_MixData {
uint8_t speedDown; // 0 nichts uint8_t speedDown; // 0 nichts
uint8_t srcRaw; // uint8_t srcRaw; //
int8_t differential; int8_t differential;
uint8_t carryTrim; int8_t carryTrim;
int8_t sOffset; int8_t sOffset;
}) MixData; }) MixData;
#else #else
@@ -263,9 +270,9 @@ PACK(typedef struct t_MixData {
uint8_t delayDown:4; uint8_t delayDown:4;
uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle)
uint8_t speedDown:4; // 0 nichts uint8_t speedDown:4; // 0 nichts
uint16_t srcRaw:7; // uint16_t srcRaw:6; //
int16_t differential:7; int16_t differential:7;
uint16_t carryTrim:2; int16_t carryTrim:3;
int8_t sOffset; int8_t sOffset;
}) MixData; }) MixData;
#endif #endif
+45 -67
View File
@@ -315,15 +315,12 @@ int16_t Expo::expo(int16_t x)
#endif #endif
void applyExpos(int16_t *anas, uint8_t phase) void applyExpos(int16_t *anas)
{ {
static int16_t anas2[NUM_STICKS]; // values before expo, to ensure same expo base when multiple expo lines are used static int16_t anas2[NUM_STICKS]; // values before expo, to ensure same expo base when multiple expo lines are used
memcpy(anas2, anas, sizeof(anas2)); memcpy(anas2, anas, sizeof(anas2));
if (phase == 255) uint8_t phase = s_perout_flight_phase + 1;
phase = getFlightPhase();
phase++;
int8_t cur_chn = -1; int8_t cur_chn = -1;
for (uint8_t i=0; i<MAX_EXPOS; i++) { for (uint8_t i=0; i<MAX_EXPOS; i++) {
@@ -408,6 +405,7 @@ int16_t getValue(uint8_t i)
#if defined(PCBV4) #if defined(PCBV4)
else if(i<NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS) return getRotaryEncoder(i-(NUM_STICKS+NUM_POTS)); else if(i<NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS) return getRotaryEncoder(i-(NUM_STICKS+NUM_POTS));
#endif #endif
else if(i<MIXSRC_TrimAil) return calc1000toRESX((int16_t)8 * getTrimValue(s_perout_flight_phase, i-(NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS)));
else if(i<MIXSRC_MAX) return 1024; else if(i<MIXSRC_MAX) return 1024;
else if(i<MIXSRC_3POS) return (keyState(SW_ID0) ? -1024 : (keyState(SW_ID1) ? 0 : 1024)); else if(i<MIXSRC_3POS) return (keyState(SW_ID0) ? -1024 : (keyState(SW_ID1) ? 0 : 1024));
else if(i<MIXSRC_3POS+3) else if(i<MIXSRC_3POS+3)
@@ -645,19 +643,12 @@ uint8_t getFlightPhase()
int16_t getRawTrimValue(uint8_t phase, uint8_t idx) int16_t getRawTrimValue(uint8_t phase, uint8_t idx)
{ {
int16_t result; PhaseData *p = phaseaddress(phase);
if (s_trimPtr[idx]) {
result = *s_trimPtr[idx];
}
else {
PhaseData *p = phaseaddress(phase);
#if defined(PCBSTD) #if defined(PCBSTD)
result = (((int16_t)p->trim[idx]) << 2) + ((p->trim_ext >> (2*idx)) & 0x03); return (((int16_t)p->trim[idx]) << 2) + ((p->trim_ext >> (2*idx)) & 0x03);
#else #else
result = p->trim[idx]; return p->trim[idx];
#endif #endif
}
return result;
} }
int16_t getTrimValue(uint8_t phase, uint8_t idx) int16_t getTrimValue(uint8_t phase, uint8_t idx)
@@ -667,18 +658,13 @@ int16_t getTrimValue(uint8_t phase, uint8_t idx)
void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim) void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim)
{ {
if (s_trimPtr[idx]) { PhaseData *p = phaseaddress(phase);
*s_trimPtr[idx] = limit((int16_t)-125, trim, (int16_t)+125);
}
else {
PhaseData *p = phaseaddress(phase);
#if defined(PCBSTD) #if defined(PCBSTD)
p->trim[idx] = (int8_t)(trim >> 2); p->trim[idx] = (int8_t)(trim >> 2);
p->trim_ext = (p->trim_ext & ~(0x03 << (2*idx))) + (((trim & 0x03) << (2*idx))); p->trim_ext = (p->trim_ext & ~(0x03 << (2*idx))) + (((trim & 0x03) << (2*idx)));
#else #else
p->trim[idx] = trim; p->trim[idx] = trim;
#endif #endif
}
STORE_MODELVARS; STORE_MODELVARS;
} }
@@ -696,11 +682,9 @@ uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx)
} }
#if defined(PCBV4) #if defined(PCBV4)
uint8_t s_perOut_flight_phase;
uint8_t getRotaryEncoderFlightPhase(uint8_t idx) uint8_t getRotaryEncoderFlightPhase(uint8_t idx)
{ {
uint8_t phase = s_perOut_flight_phase; uint8_t phase = s_perout_flight_phase;
for (uint8_t i=0; i<MAX_PHASES; i++) { for (uint8_t i=0; i<MAX_PHASES; i++) {
if (phase == 0) return 0; if (phase == 0) return 0;
int16_t value = phaseaddress(phase)->rotaryEncoders[idx]; int16_t value = phaseaddress(phase)->rotaryEncoders[idx];
@@ -928,7 +912,8 @@ void alert(const pm_char * s)
sleep(1/*ms*/); sleep(1/*ms*/);
#endif #endif
if (check_soft_power() > e_power_trainer) return; // Usb on or power off
if (check_soft_power() >= e_power_usb) return; // Usb on or power off
if (keyDown()) return; // wait for key release if (keyDown()) return; // wait for key release
@@ -954,8 +939,6 @@ void message(const pm_char *title, const pm_char *s, const pm_char *t, const cha
clearKeyEvents(); clearKeyEvents();
} }
int8_t *s_trimPtr[NUM_STICKS] = { NULL, NULL, NULL, NULL };
uint8_t checkTrim(uint8_t event) uint8_t checkTrim(uint8_t event)
{ {
int8_t k = (event & EVT_KEY_MASK) - TRM_BASE; int8_t k = (event & EVT_KEY_MASK) - TRM_BASE;
@@ -964,7 +947,7 @@ uint8_t checkTrim(uint8_t event)
if (k>=0 && k<8) { // && (event & _MSK_KEY_REPT)) if (k>=0 && k<8) { // && (event & _MSK_KEY_REPT))
//LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP //LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP
uint8_t idx = CONVERT_MODE(1+k/2) - 1; uint8_t idx = CONVERT_MODE(1+k/2) - 1;
uint8_t phase = getTrimFlightPhase(getFlightPhase(), idx); uint8_t phase = getTrimFlightPhase(s_perout_flight_phase, idx);
int16_t before = getRawTrimValue(phase, idx); int16_t before = getRawTrimValue(phase, idx);
int8_t v = (s==0) ? min(32, abs(before)/4+1) : 1 << (s-1); // 1=>1 2=>2 3=>4 4=>8 int8_t v = (s==0) ? min(32, abs(before)/4+1) : 1 << (s-1); // 1=>1 2=>2 3=>4 4=>8
bool thro = (idx==THR_STICK && g_model.thrTrim); bool thro = (idx==THR_STICK && g_model.thrTrim);
@@ -1295,8 +1278,9 @@ int32_t act [MAX_MIXERS] = {0};
uint8_t swOn [MAX_MIXERS] = {0}; uint8_t swOn [MAX_MIXERS] = {0};
uint8_t mixWarning; uint8_t mixWarning;
FORCEINLINE void evalTrims(uint8_t phase) FORCEINLINE void evalTrims()
{ {
uint8_t phase = s_perout_flight_phase;
for (uint8_t i=0; i<NUM_STICKS; i++) { for (uint8_t i=0; i<NUM_STICKS; i++) {
// do trim -> throttle trim if applicable // do trim -> throttle trim if applicable
// TODO avoid int32_t vv // TODO avoid int32_t vv
@@ -1325,7 +1309,7 @@ enum PerOutMode {
uint8_t s_perout_mode = e_perout_mode_normal; uint8_t s_perout_mode = e_perout_mode_normal;
BeepANACenter evalSticks(uint8_t phase) BeepANACenter evalSticks()
{ {
BeepANACenter anaCenter = 0; BeepANACenter anaCenter = 0;
@@ -1399,10 +1383,10 @@ BeepANACenter evalSticks(uint8_t phase)
} }
/* EXPOs */ /* EXPOs */
applyExpos(anas, phase); applyExpos(anas);
/* TRIMs */ /* TRIMs */
evalTrims(phase); evalTrims();
return anaCenter; return anaCenter;
} }
@@ -1525,13 +1509,10 @@ void evalFunctions()
} }
} }
void perOut(uint8_t phase) uint8_t s_perout_flight_phase;
void perOut()
{ {
#if defined(PCBV4) BeepANACenter anaCenter = evalSticks();
s_perOut_flight_phase = phase;
#endif
BeepANACenter anaCenter = evalSticks(phase);
if (s_perout_mode == e_perout_mode_normal) { if (s_perout_mode == e_perout_mode_normal) {
//===========BEEP CENTER================ //===========BEEP CENTER================
@@ -1603,17 +1584,13 @@ void perOut(uint8_t phase)
} }
} }
#endif #endif
s_trimPtr[0] = NULL;
s_trimPtr[1] = NULL;
s_trimPtr[2] = NULL;
s_trimPtr[3] = NULL;
} }
memset(chans, 0, sizeof(chans)); // All outputs to 0 memset(chans, 0, sizeof(chans)); // All outputs to 0
//========== MIXER LOOP =============== //========== MIXER LOOP ===============
uint8_t lv_mixWarning = 0; uint8_t lv_mixWarning = 0;
uint8_t phase = s_perout_flight_phase + 1;
for (uint8_t i=0; i<MAX_MIXERS; i++) { for (uint8_t i=0; i<MAX_MIXERS; i++) {
MixData *md = mixaddress( i ) ; MixData *md = mixaddress( i ) ;
@@ -1622,11 +1599,11 @@ void perOut(uint8_t phase)
if (md->phase != 0) { if (md->phase != 0) {
if (md->phase > 0) { if (md->phase > 0) {
if (phase+1 != md->phase) if (phase != md->phase)
continue; continue;
} }
else { else {
if (phase+1 == -md->phase) if (phase == -md->phase)
continue; continue;
} }
} }
@@ -1741,15 +1718,16 @@ void perOut(uint8_t phase)
v = applyCurve(v, md->curve); v = applyCurve(v, md->curve);
//========== TRIMS =============== //========== TRIMS ===============
if (k < NUM_STICKS) { if (s_perout_mode < e_perout_mode_zeros) {
if (s_perout_mode < e_perout_mode_zeros && md->carryTrim == TRIM_ON) { int8_t mix_trim = md->carryTrim;
v += trims[k]; if (mix_trim < TRIM_ON)
} mix_trim = -mix_trim-1;
if (s_perout_mode == e_perout_mode_normal && md->carryTrim == TRIM_OFFSET) { else if (mix_trim == TRIM_ON && k < NUM_STICKS)
v = md->sOffset; mix_trim = k;
v = calc1000toRESX(v << 3); else
s_trimPtr[k] = &md->sOffset; // use the value stored here for the trim mix_trim = -1;
} if (mix_trim >= 0)
v += trims[mix_trim];
} }
//========== MULTIPLEX =============== //========== MULTIPLEX ===============
@@ -1831,7 +1809,8 @@ void perMain()
weight = 0; weight = 0;
for (uint8_t p=0; p<MAX_PHASES; p++) { for (uint8_t p=0; p<MAX_PHASES; p++) {
if (s_fade_flight_phases & (1<<p)) { if (s_fade_flight_phases & (1<<p)) {
perOut(p); s_perout_flight_phase = p;
perOut();
for (uint8_t i=0; i<NUM_CHNOUT; i++) for (uint8_t i=0; i<NUM_CHNOUT; i++)
sum_chans512[i] += (chans[i] / 16) * fp_act[p]; sum_chans512[i] += (chans[i] / 16) * fp_act[p];
weight += fp_act[p]; weight += fp_act[p];
@@ -1839,9 +1818,11 @@ void perMain()
} }
// printf("sum=%d, weight=%d ", sum_chans512[2], weight); fflush(stdout); // printf("sum=%d, weight=%d ", sum_chans512[2], weight); fflush(stdout);
assert(weight); assert(weight);
s_perout_flight_phase = phase;
} }
else { else {
perOut(phase); s_perout_flight_phase = phase;
perOut();
} }
//========== LIMITS =============== //========== LIMITS ===============
@@ -2417,14 +2398,12 @@ ISR(USART0_UDRE_vect)
void instantTrim() void instantTrim()
{ {
uint8_t phase = getFlightPhase();
for (uint8_t i=0; i<NUM_STICKS; i++) { for (uint8_t i=0; i<NUM_STICKS; i++) {
if (i!=THR_STICK) { if (i!=THR_STICK) {
// don't instant trim the throttle stick // don't instant trim the throttle stick
uint8_t trim_phase = getTrimFlightPhase(phase, i); uint8_t trim_phase = getTrimFlightPhase(s_perout_flight_phase, i);
s_perout_mode = e_instant_trim; s_perout_mode = e_instant_trim;
evalSticks(phase); evalSticks();
s_perout_mode = e_perout_mode_normal; s_perout_mode = e_perout_mode_normal;
int16_t trim = (anas[i] + trims[i]) / 2; int16_t trim = (anas[i] + trims[i]) / 2;
if (trim < TRIM_EXTENDED_MIN) { if (trim < TRIM_EXTENDED_MIN) {
@@ -2444,16 +2423,15 @@ void instantTrim()
void moveTrimsToOffsets() // copy state of 3 primary to subtrim void moveTrimsToOffsets() // copy state of 3 primary to subtrim
{ {
int16_t zeros[NUM_CHNOUT]; int16_t zeros[NUM_CHNOUT];
uint8_t phase = getFlightPhase();
s_perout_mode = e_perout_mode_zeros; s_perout_mode = e_perout_mode_zeros;
perOut(phase); // do output loop - zero input sticks and trims perOut(); // do output loop - zero input sticks and trims
for (uint8_t i=0; i<NUM_CHNOUT; i++) { for (uint8_t i=0; i<NUM_CHNOUT; i++) {
zeros[i] = applyLimits(i, chans[i]); zeros[i] = applyLimits(i, chans[i]);
} }
s_perout_mode = e_perout_mode_trims; s_perout_mode = e_perout_mode_trims;
perOut(phase); // do output loop - only trims perOut(); // do output loop - only trims
s_perout_mode = e_perout_mode_normal; s_perout_mode = e_perout_mode_normal;
for (uint8_t i=0; i<NUM_CHNOUT; i++) { for (uint8_t i=0; i<NUM_CHNOUT; i++) {
@@ -2468,7 +2446,7 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim
// reset all trims, except throttle (if throttle trim) // reset all trims, except throttle (if throttle trim)
for (uint8_t i=0; i<NUM_STICKS; i++) { for (uint8_t i=0; i<NUM_STICKS; i++) {
if (i!=THR_STICK || !g_model.thrTrim) { if (i!=THR_STICK || !g_model.thrTrim) {
int16_t original_trim = getTrimValue(phase, i); int16_t original_trim = getTrimValue(s_perout_flight_phase, i);
for (uint8_t phase=0; phase<MAX_PHASES; phase++) { for (uint8_t phase=0; phase<MAX_PHASES; phase++) {
int16_t trim = getRawTrimValue(phase, i); int16_t trim = getRawTrimValue(phase, i);
if (trim <= TRIM_EXTENDED_MAX) if (trim <= TRIM_EXTENDED_MAX)
+5 -6
View File
@@ -380,7 +380,8 @@ extern Key keys[NUM_KEYS];
#define NUM_STICKS 4 #define NUM_STICKS 4
#define NUM_POTS 3 #define NUM_POTS 3
#define CSW_PPM_BASE (MIXSRC_3POS+3/*CYC1-CYC3*/) // because srcRaw is shifted +1! #define NUM_CYC 3
#define CSW_PPM_BASE (MIXSRC_3POS+NUM_CYC) // because srcRaw is shifted +1!
#define NUM_CAL_PPM 4 #define NUM_CAL_PPM 4
#define NUM_PPM 8 #define NUM_PPM 8
#define CSW_CHOUT_BASE (CSW_PPM_BASE+NUM_PPM) #define CSW_CHOUT_BASE (CSW_PPM_BASE+NUM_PPM)
@@ -403,7 +404,7 @@ extern Key keys[NUM_KEYS];
#define NUM_TELEMETRY TELEM_TM2 #define NUM_TELEMETRY TELEM_TM2
#endif #endif
#define NUM_XCHNRAW (NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+1/*MAX*/+1/*ID3*/+3/*CYC1-CYC3*/+NUM_PPM+NUM_CHNOUT) #define NUM_XCHNRAW (NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+1/*MAX*/+1/*ID3*/+NUM_CYC+NUM_PPM+NUM_CHNOUT)
#define NUM_XCHNCSW (NUM_XCHNRAW+NUM_TELEMETRY) #define NUM_XCHNCSW (NUM_XCHNRAW+NUM_TELEMETRY)
#define NUM_XCHNMIX (NUM_XCHNRAW+MAX_SWITCH) #define NUM_XCHNMIX (NUM_XCHNRAW+MAX_SWITCH)
@@ -512,9 +513,7 @@ extern int16_t getRawTrimValue(uint8_t phase, uint8_t idx);
extern int16_t getTrimValue(uint8_t phase, uint8_t idx); extern int16_t getTrimValue(uint8_t phase, uint8_t idx);
extern void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim); extern void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim);
#if defined(PCBV4) extern uint8_t s_perout_flight_phase;
extern uint8_t s_perOut_flight_phase;
#endif
#if defined(ROTARY_ENCODERS) #if defined(ROTARY_ENCODERS)
int16_t getRotaryEncoder(uint8_t idx); int16_t getRotaryEncoder(uint8_t idx);
@@ -745,7 +744,7 @@ extern uint16_t expou(uint16_t x, uint16_t k);
extern int16_t expo(int16_t x, int16_t k); extern int16_t expo(int16_t x, int16_t k);
extern int16_t intpol(int16_t, uint8_t); extern int16_t intpol(int16_t, uint8_t);
extern int16_t applyCurve(int16_t, int8_t); extern int16_t applyCurve(int16_t, int8_t);
extern void applyExpos(int16_t *anas, uint8_t phase=255); extern void applyExpos(int16_t *anas);
extern uint16_t anaIn(uint8_t chan); extern uint16_t anaIn(uint8_t chan);
extern int16_t calibratedStick[7]; extern int16_t calibratedStick[7];
+1
View File
@@ -86,6 +86,7 @@ void sig(int sgn)
#undef max #undef max
#define APM #define APM
#define __REV
typedef const unsigned char pm_uchar; typedef const unsigned char pm_uchar;
typedef const char pm_char; typedef const char pm_char;
+3 -3
View File
@@ -82,8 +82,8 @@
#define LEN_VMLTPX2 "\002" #define LEN_VMLTPX2 "\002"
#define TR_VMLTPX2 "+=""*="":=" #define TR_VMLTPX2 "+=""*="":="
#define LEN_VMIXTRIMS "\006" #define LEN_VMIXTRIMS "\003"
#define TR_VMIXTRIMS "ZAP ""VYP ""Offset" #define TR_VMIXTRIMS "OFF""ON ""Rud""Ele""Thr""Ail"
#define LEN_VCSWFUNC "\007" #define LEN_VCSWFUNC "\007"
#define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""|v|>ofs""|v|<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 " #define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""|v|>ofs""|v|<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 "
@@ -204,7 +204,7 @@
#else #else
#define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]" #define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]"
#endif #endif
#define TR_VSRCRAW "Smer""Vysk""Plyn""Krid""Pot1""Pot2""Pot3" TR_ROTARY_ENCODERS_VSRCRAW "MAX ""3POS" TR_CYC_VSRCRAW #define TR_VSRCRAW "Smer""Vysk""Plyn""Krid""Pot1""Pot2""Pot3" TR_ROTARY_ENCODERS_VSRCRAW "TrmR" "TrmE" "TrmT" "TrmA" "MAX ""3POS" TR_CYC_VSRCRAW
#define LEN_VTMRMODES "\003" #define LEN_VTMRMODES "\003"
#define TR_VTMRMODES "VYP""ABS""THs""TH%""THt" #define TR_VTMRMODES "VYP""ABS""THs""TH%""THt"
+3 -3
View File
@@ -82,8 +82,8 @@
#define LEN_VMLTPX2 "\002" #define LEN_VMLTPX2 "\002"
#define TR_VMLTPX2 "+=""*="":=" #define TR_VMLTPX2 "+=""*="":="
#define LEN_VMIXTRIMS "\006" #define LEN_VMIXTRIMS "\003"
#define TR_VMIXTRIMS "ON ""OFF ""Offset" #define TR_VMIXTRIMS "OFF""ON ""Rud""Ele""Thr""Ail"
#define LEN_VCSWFUNC "\007" #define LEN_VCSWFUNC "\007"
#define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""|v|>ofs""|v|<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 " #define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""|v|>ofs""|v|<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 "
@@ -204,7 +204,7 @@
#else #else
#define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]" #define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]"
#endif #endif
#define TR_VSRCRAW "Rud ""Ele ""Thr ""Ail ""P1 ""P2 ""P3 " TR_ROTARY_ENCODERS_VSRCRAW "MAX ""3POS" TR_CYC_VSRCRAW #define TR_VSRCRAW "Rud ""Ele ""Thr ""Ail ""P1 ""P2 ""P3 " TR_ROTARY_ENCODERS_VSRCRAW "TrmR" "TrmE" "TrmT" "TrmA" "MAX ""3POS" TR_CYC_VSRCRAW
#define LEN_VTMRMODES "\003" #define LEN_VTMRMODES "\003"
#define TR_VTMRMODES "OFF""ABS""THs""TH%""THt" #define TR_VTMRMODES "OFF""ABS""THs""TH%""THt"
+3 -3
View File
@@ -82,8 +82,8 @@
#define LEN_VMLTPX2 "\002" #define LEN_VMLTPX2 "\002"
#define TR_VMLTPX2 "+=""*="":=" #define TR_VMLTPX2 "+=""*="":="
#define LEN_VMIXTRIMS "\006" #define LEN_VMIXTRIMS "\003"
#define TR_VMIXTRIMS "ON ""OFF ""Offset" #define TR_VMIXTRIMS "OFF""ON ""Dir""Prf""Gaz""Ail"
#define LEN_VCSWFUNC "\007" #define LEN_VCSWFUNC "\007"
#define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""|v|>ofs""|v|<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 " #define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""|v|>ofs""|v|<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 "
@@ -207,7 +207,7 @@
#else #else
#define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]" #define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]"
#endif #endif
#define TR_VSRCRAW "Dir ""Prf ""Gaz ""Ail ""P1 ""P2 ""P3 " TR_ROTARY_ENCODERS_VSRCRAW "MAX ""3POS" TR_CYC_VSRCRAW #define TR_VSRCRAW "Dir ""Prf ""Gaz ""Ail ""P1 ""P2 ""P3 " TR_ROTARY_ENCODERS_VSRCRAW "TrmD" "TrmP" "TrmG" "TrmA" "MAX ""3POS" TR_CYC_VSRCRAW
#define LEN_VTMRMODES "\003" #define LEN_VTMRMODES "\003"
#define TR_VTMRMODES "OFF""ABS""GZs""GZ%""GZt" #define TR_VTMRMODES "OFF""ABS""GZs""GZ%""GZt"
+3 -3
View File
@@ -82,8 +82,8 @@
#define LEN_VMLTPX2 "\002" #define LEN_VMLTPX2 "\002"
#define TR_VMLTPX2 "+=""*="":=" #define TR_VMLTPX2 "+=""*="":="
#define LEN_VMIXTRIMS "\006" #define LEN_VMIXTRIMS "\003"
#define TR_VMIXTRIMS "ON ""OFF ""Offset" #define TR_VMIXTRIMS "OFF""ON ""Rud""Ele""Thr""Ail"
#define LEN_VCSWFUNC "\007" #define LEN_VCSWFUNC "\007"
#define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""|v|>ofs""|v|<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 " #define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""|v|>ofs""|v|<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 "
@@ -204,7 +204,7 @@
#else #else
#define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]" #define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]"
#endif #endif
#define TR_VSRCRAW "Rud ""Ele ""Thr ""Ail ""P1 ""P2 ""P3 " TR_ROTARY_ENCODERS_VSRCRAW "MAX ""3POS" TR_CYC_VSRCRAW #define TR_VSRCRAW "Rud ""Ele ""Thr ""Ail ""P1 ""P2 ""P3 " TR_ROTARY_ENCODERS_VSRCRAW "TrmR" "TrmE" "TrmT" "TrmA" "MAX ""3POS" TR_CYC_VSRCRAW
#define LEN_VTMRMODES "\003" #define LEN_VTMRMODES "\003"
#define TR_VTMRMODES "OFF""ABS""THs""TH%""THt" #define TR_VTMRMODES "OFF""ABS""THs""TH%""THt"
+3 -3
View File
@@ -82,8 +82,8 @@
#define LEN_VMLTPX2 "\002" #define LEN_VMLTPX2 "\002"
#define TR_VMLTPX2 "+=""*="":=" #define TR_VMLTPX2 "+=""*="":="
#define LEN_VMIXTRIMS "\006" #define LEN_VMIXTRIMS "\003"
#define TR_VMIXTRIMS "P\203 ""AV ""Offset" #define TR_VMIXTRIMS "OFF""ON ""Rud""Ele""Thr""Ail"
#define LEN_VCSWFUNC "\007" #define LEN_VCSWFUNC "\007"
#define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""(v)>ofs""(v)<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 " #define TR_VCSWFUNC "----\0 ""v>ofs ""v<ofs ""(v)>ofs""(v)<ofs""AND ""OR ""XOR ""v1==v2 ""v1!=v2 ""v1>v2 ""v1<v2 ""v1>=v2 ""v1<=v2 "
@@ -207,7 +207,7 @@
#else #else
#define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]" #define TR_CYC_VSRCRAW "[C1]""[C2]""[C3]"
#endif #endif
#define TR_VSRCRAW "ROD ""H\205J ""GAS ""SKE ""P1 ""P2 ""P3 " TR_ROTARY_ENCODERS_VSRCRAW "MAX ""FULL" TR_CYC_VSRCRAW #define TR_VSRCRAW "ROD ""H\205J ""GAS ""SKE ""P1 ""P2 ""P3 " TR_ROTARY_ENCODERS_VSRCRAW "TrmR" "TrmE" "TrmT" "TrmA" "MAX ""3POS" TR_CYC_VSRCRAW
#define LEN_VTMRMODES "\003" #define LEN_VTMRMODES "\003"
#define TR_VTMRMODES "AV ""ABS""THs""TH%""THt" #define TR_VTMRMODES "AV ""ABS""THs""TH%""THt"