128 bytes RAM saved

This commit is contained in:
Bertrand Songis
2019-09-13 08:21:35 +02:00
parent 5dd2330128
commit 2bc42d9ecb
9 changed files with 57 additions and 61 deletions
+31 -32
View File
@@ -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; i<MAX_MIXERS; i++) {
#if defined(BOLD_FONT)
if (mode==e_perout_mode_normal && pass==0) swOn[i].activeMix = 0;
if (mode == e_perout_mode_normal && pass == 0)
swOn[i].activeMix = 0;
#endif
MixData *md = mixAddress(i);
MixData * md = mixAddress(i);
if (md->srcRaw == 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<int16_t>(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 (newValue<currentValue) currentValue = newValue; // Endposition; prevent toggling around the destination
}
}
else { // if is <0 because ==0 is not possible
if (s_mixer_first_run_done && md->speedDown > 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;