1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 01:05:10 +03:00

Reduced number of logical switch context to 2. Now we have only active fm context (lswFM[0]) and other context that is used for all other fms (lswFm[1]).

Much smaller RAM usage, but possible (I beleave unimportant) errors when trasitioning between more than two flight modes.
This commit is contained in:
Damjan Adamic 2014-05-18 18:08:41 +02:00
parent fbb1b65fd6
commit e14734c8af
3 changed files with 16 additions and 19 deletions

View file

@ -524,7 +524,7 @@ uint8_t s_current_mixer_flight_mode;
void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms)
{
evalInputs(mode);
evalLogicalSwitches(mode);
evalLogicalSwitches();
#if defined(MODULE_ALWAYS_SEND_PULSES)
checkStartupWarnings();
@ -918,6 +918,7 @@ int32_t sum_chans512[NUM_CHNOUT] = {0};
#define MAX_ACT 0xffff
uint8_t s_last_phase = 255; // TODO reinit everything here when the model changes, no???
void evalMixes(uint8_t tick10ms)
{
@ -928,7 +929,6 @@ void evalMixes(uint8_t tick10ms)
static uint16_t fp_act[MAX_FLIGHT_MODES] = {0};
static uint16_t delta = 0;
static ACTIVE_PHASES_TYPE s_fade_flight_phases = 0;
static uint8_t s_last_phase = 255; // TODO reinit everything here when the model changes, no???
uint8_t phase = getFlightPhase();
@ -951,7 +951,7 @@ void evalMixes(uint8_t tick10ms)
fp_act[s_last_phase] = 0;
fp_act[phase] = MAX_ACT;
}
logicalSwitchesCopyState(s_last_phase, phase); //push last logical switches state from old to new phase
logicalSwitchesCopyState(); //push last logical switches state from old to new phase
}
s_last_phase = phase;
}

View file

@ -671,6 +671,7 @@ enum StartupWarningStates {
#endif
extern uint8_t s_current_mixer_flight_mode;
extern uint8_t s_last_phase;
#if defined(CPUARM)
#define bitfield_channels_t uint32_t
@ -695,8 +696,8 @@ getvalue_t getValue(uint8_t i);
bool getSwitch(int8_t swtch);
void logicalSwitchesTimerTick();
void logicalSwitchesReset();
void evalLogicalSwitches(uint8_t mode);
void logicalSwitchesCopyState(uint8_t oldPhase, uint8_t newPhase);
void evalLogicalSwitches();
void logicalSwitchesCopyState();
#if defined(PCBTARANIS)
void getSwitchesPosition(bool startup);

View file

@ -51,7 +51,7 @@ PACK(typedef struct {
lsw_struct ls[NUM_LOGICAL_SWITCH];
}) lsw_array;
lsw_array lswFm[MAX_FLIGHT_MODES];
lsw_array lswFm[2];
#if defined(PCBTARANIS)
tmr10ms_t switchesMidposStart[6] = { 0 };
@ -218,7 +218,7 @@ bool getSwitch(int8_t swtch)
#endif
else {
cs_idx -= SWSRC_FIRST_LOGICAL_SWITCH;
result = lswFm[s_current_mixer_flight_mode].ls[cs_idx].state;
result = lswFm[(s_last_phase == s_current_mixer_flight_mode)?0:1].ls[cs_idx].state;
}
return swtch > 0 ? result : !result;
@ -227,14 +227,14 @@ bool getSwitch(int8_t swtch)
/**
@brief Calculates new state of logical switches for s_current_mixer_flight_mode
*/
void evalLogicalSwitches(uint8_t mode)
void evalLogicalSwitches()
{
for(unsigned int cs_idx=0; cs_idx<NUM_LOGICAL_SWITCH; cs_idx++) {
bool result = false;
LogicalSwitchData * ls = lswAddress(cs_idx);
lsw_struct * lsd = &lswFm[s_current_mixer_flight_mode].ls[cs_idx];
lsw_struct * lsd = &lswFm[(s_last_phase == s_current_mixer_flight_mode)?0:1].ls[cs_idx];
#if defined(CPUARM)
int8_t s = ls->andsw;
@ -406,10 +406,10 @@ void evalLogicalSwitches(uint8_t mode)
#endif
if (result) {
if (!lsd->state && mode == e_perout_mode_normal) PLAY_LOGICAL_SWITCH_ON(cs_idx);
if (!lsd->state && s_last_phase == s_current_mixer_flight_mode) PLAY_LOGICAL_SWITCH_ON(cs_idx);
}
else {
if (lsd->state && mode == e_perout_mode_normal) PLAY_LOGICAL_SWITCH_OFF(cs_idx);
if (lsd->state && s_last_phase == s_current_mixer_flight_mode) PLAY_LOGICAL_SWITCH_OFF(cs_idx);
}
lsd->state = result;
}
@ -606,7 +606,7 @@ void checkSwitches()
}
void logicalSwitchesTimerTick() {
for (uint8_t fm=0; fm<MAX_FLIGHT_MODES; fm++) {
for (uint8_t fm=0; fm<2; fm++) {
for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) {
LogicalSwitchData * ls = lswAddress(i);
lsw_struct * lsd = &lswFm[fm].ls[i];
@ -708,12 +708,10 @@ int16_t lswTimerValue(delayval_t val)
}
void logicalSwitchesReset() {
for (uint8_t fm=0; fm<MAX_FLIGHT_MODES; fm++) {
for (uint8_t fm=0; fm<2; fm++) {
lsw_array * lsa = &lswFm[fm];
for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) {
lsa->ls[i].lastValue = CS_LAST_VALUE_INIT;
//todo other values
lsa->ls[i].state = false;
}
}
}
@ -732,8 +730,6 @@ getvalue_t convertLswTelemValue(LogicalSwitchData * ls)
return val;
}
void logicalSwitchesCopyState(uint8_t oldPhase, uint8_t newPhase) {
for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) {
lswFm[newPhase].ls[i].state = lswFm[oldPhase].ls[i].state;
}
void logicalSwitchesCopyState() {
lswFm[1] = lswFm[0];
}