diff --git a/radio/src/gui/128x64/menu_model.cpp b/radio/src/gui/128x64/menu_model.cpp index 0f64fab14..4a450d143 100644 --- a/radio/src/gui/128x64/menu_model.cpp +++ b/radio/src/gui/128x64/menu_model.cpp @@ -23,7 +23,7 @@ uint8_t editDelay(coord_t y, event_t event, uint8_t attr, const char * str, uint8_t delay) { lcdDrawTextAlignedLeft(y, str); - lcdDrawNumber(MIXES_2ND_COLUMN, y, (10/DELAY_STEP)*delay, attr|PREC1|LEFT); + lcdDrawNumber(MIXES_2ND_COLUMN, y, delay, attr|PREC1|LEFT); if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, delay, DELAY_MAX); return delay; } diff --git a/radio/src/gui/212x64/menu_model.cpp b/radio/src/gui/212x64/menu_model.cpp index 11e58a68c..402189fb5 100644 --- a/radio/src/gui/212x64/menu_model.cpp +++ b/radio/src/gui/212x64/menu_model.cpp @@ -44,7 +44,7 @@ const MenuHandlerFunc menuTabModel[] = { uint8_t editDelay(coord_t y, event_t event, uint8_t attr, const char * str, uint8_t delay) { lcdDrawTextAlignedLeft(y, str); - lcdDrawNumber(MIXES_2ND_COLUMN, y, (10/DELAY_STEP)*delay, attr|PREC1|LEFT); + lcdDrawNumber(MIXES_2ND_COLUMN, y, delay, attr|PREC1|LEFT); if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, delay, DELAY_MAX); return delay; } diff --git a/radio/src/gui/212x64/model_flightmodes.cpp b/radio/src/gui/212x64/model_flightmodes.cpp index 2b7eb05c9..efa287ee1 100644 --- a/radio/src/gui/212x64/model_flightmodes.cpp +++ b/radio/src/gui/212x64/model_flightmodes.cpp @@ -126,12 +126,12 @@ void menuModelFlightModesAll(event_t event) } case ITEM_FLIGHT_MODES_FADE_IN: - lcdDrawNumber(32*FW-2, y, (10/DELAY_STEP)*p->fadeIn, attr|PREC1|RIGHT); + lcdDrawNumber(32*FW-2, y, p->fadeIn, attr|PREC1|RIGHT); if (active) p->fadeIn = checkIncDec(event, p->fadeIn, 0, DELAY_MAX, EE_MODEL|NO_INCDEC_MARKS); break; case ITEM_FLIGHT_MODES_FADE_OUT: - lcdDrawNumber(35*FW, y, (10/DELAY_STEP)*p->fadeOut, attr|PREC1|RIGHT); + lcdDrawNumber(35*FW, y, p->fadeOut, attr|PREC1|RIGHT); if (active) p->fadeOut = checkIncDec(event, p->fadeOut, 0, DELAY_MAX, EE_MODEL|NO_INCDEC_MARKS); break; diff --git a/radio/src/gui/480x272/menu_model.cpp b/radio/src/gui/480x272/menu_model.cpp index 93a7710e5..761bc9180 100644 --- a/radio/src/gui/480x272/menu_model.cpp +++ b/radio/src/gui/480x272/menu_model.cpp @@ -43,7 +43,7 @@ void editCurveRef(coord_t x, coord_t y, CurveRef & curve, event_t event, LcdFlag uint8_t editDelay(coord_t x, coord_t y, event_t event, uint8_t attr, uint8_t delay) { - lcdDrawNumber(x+MIXES_2ND_COLUMN, y, (10/DELAY_STEP)*delay, attr|PREC1|LEFT); + lcdDrawNumber(x+MIXES_2ND_COLUMN, y, delay, attr|PREC1|LEFT); if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, delay, DELAY_MAX); return delay; } diff --git a/radio/src/gui/480x272/model_flightmodes.cpp b/radio/src/gui/480x272/model_flightmodes.cpp index c4d40d121..e6210bd92 100644 --- a/radio/src/gui/480x272/model_flightmodes.cpp +++ b/radio/src/gui/480x272/model_flightmodes.cpp @@ -159,12 +159,12 @@ bool menuModelFlightModesAll(event_t event) case ITEM_FLIGHT_MODES_FADE_IN: if (active) p->fadeIn = checkIncDec(event, p->fadeIn, 0, DELAY_MAX, EE_MODEL|NO_INCDEC_MARKS); - lcdDrawNumber(FLIGHT_MODES_FADEIN_COLUMN, y, (10/DELAY_STEP)*p->fadeIn, attr|PREC1|RIGHT); + lcdDrawNumber(FLIGHT_MODES_FADEIN_COLUMN, y, p->fadeIn, attr|PREC1|RIGHT); break; case ITEM_FLIGHT_MODES_FADE_OUT: if (active) p->fadeOut = checkIncDec(event, p->fadeOut, 0, DELAY_MAX, EE_MODEL|NO_INCDEC_MARKS); - lcdDrawNumber(FLIGHT_MODES_FADEOUT_COLUMN, y, (10/DELAY_STEP)*p->fadeOut, attr|PREC1|RIGHT); + lcdDrawNumber(FLIGHT_MODES_FADEOUT_COLUMN, y, p->fadeOut, attr|PREC1|RIGHT); break; } diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index 8905ca00d..72f8f85e1 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -546,8 +546,8 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) { evalInputs(mode); - if (tick10ms) evalLogicalSwitches(mode==e_perout_mode_normal); - + if (tick10ms) + evalLogicalSwitches(mode==e_perout_mode_normal); #if defined(HELI) int heliEleValue = getValue(g_model.swashR.elevatorSource); @@ -613,7 +613,7 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) } #endif - memclear(chans, sizeof(chans)); // All outputs to 0 + memclear(chans, sizeof(chans)); // all outputs to 0 //========== MIXER LOOP =============== uint8_t lv_mixWarning = 0; @@ -623,27 +623,27 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) bitfield_channels_t dirtyChannels = (bitfield_channels_t)-1; // all dirty when mixer starts do { - bitfield_channels_t passDirtyChannels = 0; for (uint8_t i=0; isrcRaw == 0) break; + if (md->srcRaw == 0) + break; mixsrc_t stickIndex = md->srcRaw - MIXSRC_Rud; - if (!(dirtyChannels & ((bitfield_channels_t)1 << md->destCh))) continue; + if (!(dirtyChannels & ((bitfield_channels_t)1 << md->destCh))) + continue; // if this is the first calculation for the destination channel, initialize it with 0 (otherwise would be random) - if (i == 0 || md->destCh != (md-1)->destCh) { + if (i == 0 || md->destCh != (md-1)->destCh) chans[md->destCh] = 0; - } //========== FLIGHT MODE && SWITCH ===== bool mixCondition = (md->flightModes != 0 || md->swtch); @@ -668,44 +668,43 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) //========== VALUE =============== getvalue_t v = 0; if (mode > e_perout_mode_inactive_flight_mode) { - if (!mixEnabled) { - continue; - } - else { + if (mixEnabled) v = getValue(md->srcRaw); - } + else + continue; } else { mixsrc_t srcRaw = MIXSRC_Rud + stickIndex; v = getValue(srcRaw); srcRaw -= MIXSRC_CH1; - if (srcRaw<=MIXSRC_LAST_CH-MIXSRC_CH1 && md->destCh != srcRaw) { + if (srcRaw <= MIXSRC_LAST_CH-MIXSRC_CH1 && md->destCh != srcRaw) { if (dirtyChannels & ((bitfield_channels_t)1 << srcRaw) & (passDirtyChannels|~(((bitfield_channels_t) 1 << md->destCh)-1))) passDirtyChannels |= (bitfield_channels_t) 1 << md->destCh; if (srcRaw < md->destCh || pass > 0) v = chans[srcRaw] >> 8; } if (!mixCondition) { - mixEnabled = v >> DELAY_POS_SHIFT; + mixEnabled = v; } } - bool apply_offset_and_curve = true; + bool applyOffsetAndCurve = true; //========== DELAYS =============== delayval_t _swOn = swOn[i].now; delayval_t _swPrev = swOn[i].prev; bool swTog = (mixEnabled > _swOn+DELAY_POS_MARGIN || mixEnabled < _swOn-DELAY_POS_MARGIN); - if (mode==e_perout_mode_normal && swTog) { - if (!swOn[i].delay) _swPrev = _swOn; - swOn[i].delay = (mixEnabled > _swOn ? md->delayUp : md->delayDown) * (100/DELAY_STEP); + if (mode == e_perout_mode_normal && swTog) { + if (!swOn[i].delay) + _swPrev = _swOn; + swOn[i].delay = (mixEnabled > _swOn ? md->delayUp : md->delayDown) * 10; swOn[i].now = mixEnabled; swOn[i].prev = _swPrev; } - if (mode==e_perout_mode_normal && swOn[i].delay > 0) { + if (mode == e_perout_mode_normal && swOn[i].delay > 0) { swOn[i].delay = max(0, (int16_t)swOn[i].delay - tick10ms); if (!mixCondition) - v = _swPrev << DELAY_POS_SHIFT; + v = _swPrev; else if (mixEnabled) continue; } @@ -717,7 +716,7 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) if ((md->speedDown || md->speedUp) && md->mltpx!=MLTPX_REP) { if (mixCondition) { v = (md->mltpx == MLTPX_ADD ? 0 : RESX); - apply_offset_and_curve = false; + applyOffsetAndCurve = false; } } else if (mixCondition) { @@ -733,7 +732,7 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) #endif } - if (apply_offset_and_curve) { + if (applyOffsetAndCurve) { //========== TRIMS ================ if (!(mode & e_perout_mode_notrims)) { @@ -756,7 +755,7 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) int16_t diff = v - (tact>>DEL_MULT_SHIFT); if (diff) { // open.20.fsguruh: speed is defined in % movement per second; In menu we specify the full movement (-100% to 100%) = 200% in total - // the unit of the stored value is the value from md->speedUp or md->speedDown divide SLOW_STEP seconds; e.g. value 4 means 4/SLOW_STEP = 2 seconds for CPU64 + // the unit of the stored value is the value from md->speedUp or md->speedDown * 0.1s; e.g. value 4 means 0.4 seconds // because we get a tick each 10msec, we need 100 ticks for one second // the value in md->speedXXX gives the time it should take to do a full movement from -100 to 100 therefore 200%. This equals 2048 in recalculated internal range if (tick10ms || !s_mixer_first_run_done) { @@ -768,14 +767,14 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) if (diff > 0) { if (s_mixer_first_run_done && md->speedUp > 0) { // if a speed upwards is defined recalculate the new value according configured speed; the higher the speed the smaller the add value is - int32_t newValue = tact+rate/((int16_t)(100/SLOW_STEP)*md->speedUp); + int32_t newValue = tact+rate/((int16_t)10*md->speedUp); if (newValuespeedDown > 0) { // see explanation in speedUp - int32_t newValue = tact-rate/((int16_t)(100/SLOW_STEP)*md->speedDown); + int32_t newValue = tact-rate/((int16_t)10*md->speedDown); if (newValue>currentValue) currentValue = newValue; // Endposition; prevent toggling around the destination } } @@ -787,7 +786,7 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) } //========== CURVES =============== - if (apply_offset_and_curve && md->curve.type != CURVE_REF_DIFF && md->curve.value) { + if (applyOffsetAndCurve && md->curve.type != CURVE_REF_DIFF && md->curve.value) { v = applyCurve(v, md->curve); } @@ -796,7 +795,7 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) dv = div_and_round(dv, 10); //========== OFFSET / AFTER =============== - if (apply_offset_and_curve) { + if (applyOffsetAndCurve) { int32_t offset = GET_GVAR_PREC1(MD_OFFSET(md), GV_RANGELARGE_NEG, GV_RANGELARGE, mixerCurrentFlightMode); if (offset) dv += div_and_round(calc100toRESX_16Bits(offset), 10) << 8; } @@ -911,7 +910,7 @@ void evalMixes(uint8_t tick10ms) ACTIVE_PHASES_TYPE transitionMask = ((ACTIVE_PHASES_TYPE)1 << lastFlightMode) + ((ACTIVE_PHASES_TYPE)1 << fm); if (fadeTime) { flightModesFade |= transitionMask; - delta = (MAX_ACT / (100/SLOW_STEP)) / fadeTime; + delta = (MAX_ACT / 10) / fadeTime; } else { flightModesFade &= ~transitionMask; diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index f1ec2e322..dcd7e20d9 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -147,10 +147,8 @@ enum CurveRefType { #define GV1_LARGE 1024 #define GV_RANGE_WEIGHT 500 #define GV_RANGE_OFFSET 500 -#define DELAY_STEP 10 -#define SLOW_STEP 10 -#define DELAY_MAX (25*DELAY_STEP) /* 25 seconds */ -#define SLOW_MAX (25*SLOW_STEP) /* 25 seconds */ +#define DELAY_MAX 250 /* 25 seconds */ +#define SLOW_MAX 250 /* 25 seconds */ #define MD_WEIGHT(md) (md->weight) #define MD_WEIGHT_TO_UNION(md, var) var.word = md->weight diff --git a/radio/src/opentx.h b/radio/src/opentx.h index b005f1b39..a2c3d86ca 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -865,16 +865,15 @@ void copySticksToOffset(uint8_t ch); void moveTrimsToOffsets(); typedef uint16_t ACTIVE_PHASES_TYPE; -#define DELAY_POS_SHIFT 0 #define DELAY_POS_MARGIN 3 typedef int16_t delayval_t; -PACK(typedef struct { - uint16_t delay; +PACK(struct SwOn { + uint16_t delay:14; // max = 2550 + uint8_t activeMix:1; + uint8_t activeExpo:1; int16_t now; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw int16_t prev; - uint8_t activeMix; - uint8_t activeExpo; -}) SwOn; +}); extern SwOn swOn[MAX_MIXERS]; extern int32_t act[MAX_MIXERS]; diff --git a/radio/src/tests/mixer.cpp b/radio/src/tests/mixer.cpp index 4c84a8944..8d8058d31 100644 --- a/radio/src/tests/mixer.cpp +++ b/radio/src/tests/mixer.cpp @@ -441,8 +441,8 @@ TEST_F(MixerTest, SlowOnPhase) g_model.mixData[0].srcRaw = MIXSRC_MAX; g_model.mixData[0].weight = 100; g_model.mixData[0].flightModes = 0x2 + 0x4 + 0x8 + 0x10 /*only enabled in phase 0*/; - g_model.mixData[0].speedUp = SLOW_STEP*5; - g_model.mixData[0].speedDown = SLOW_STEP*5; + g_model.mixData[0].speedUp = 50; + g_model.mixData[0].speedDown = 50; s_mixer_first_run_done = true; mixerCurrentFlightMode = 0; @@ -468,8 +468,8 @@ TEST_F(MixerTest, SlowOnSwitchSource) int switchIndex = 0; #endif g_model.mixData[0].weight = 100; - g_model.mixData[0].speedUp = SLOW_STEP*5; - g_model.mixData[0].speedDown = SLOW_STEP*5; + g_model.mixData[0].speedUp = 50; + g_model.mixData[0].speedDown = 50; s_mixer_first_run_done = true; @@ -487,8 +487,8 @@ TEST_F(MixerTest, SlowDisabledOnStartup) g_model.mixData[0].mltpx = MLTPX_ADD; g_model.mixData[0].srcRaw = MIXSRC_MAX; g_model.mixData[0].weight = 100; - g_model.mixData[0].speedUp = SLOW_STEP*5; - g_model.mixData[0].speedDown = SLOW_STEP*5; + g_model.mixData[0].speedUp = 50; + g_model.mixData[0].speedDown = 50; evalFlightModeMixes(e_perout_mode_normal, 0); EXPECT_EQ(chans[0], CHANNEL_MAX); @@ -507,8 +507,8 @@ TEST_F(MixerTest, DelayOnSwitch) g_model.mixData[0].swtch = SWSRC_THR; int switch_index = 1; #endif - g_model.mixData[0].delayUp = DELAY_STEP*5; - g_model.mixData[0].delayDown = DELAY_STEP*5; + g_model.mixData[0].delayUp = 50; + g_model.mixData[0].delayDown = 50; evalFlightModeMixes(e_perout_mode_normal, 0); EXPECT_EQ(chans[0], 0); @@ -537,8 +537,8 @@ TEST_F(MixerTest, SlowOnMultiply) g_model.mixData[1].srcRaw = MIXSRC_MAX; g_model.mixData[1].weight = 100; g_model.mixData[1].swtch = TR(SWSRC_THR, SWSRC_SA0); - g_model.mixData[1].speedUp = SLOW_STEP*5; - g_model.mixData[1].speedDown = SLOW_STEP*5; + g_model.mixData[1].speedUp = 50; + g_model.mixData[1].speedDown = 50; s_mixer_first_run_done = true; @@ -653,8 +653,8 @@ TEST(Trainer, UnpluggedTest) g_model.mixData[0].mltpx = MLTPX_ADD; g_model.mixData[0].srcRaw = MIXSRC_FIRST_TRAINER; g_model.mixData[0].weight = 100; - g_model.mixData[0].delayUp = DELAY_STEP*5; - g_model.mixData[0].delayDown = DELAY_STEP*5; + g_model.mixData[0].delayUp = 50; + g_model.mixData[0].delayDown = 50; ppmInputValidityTimer = 0; ppmInput[0] = 1024; CHECK_DELAY(0, 5000);