New way of dealing with recursive mixers and Flight Phases which saves ram...

This commit is contained in:
bsongis
2012-02-25 10:57:02 +00:00
parent a88e168b69
commit e91ac3d7cf
2 changed files with 15 additions and 26 deletions
+9 -19
View File
@@ -1401,15 +1401,11 @@ void perMain()
lastTMR = tmr10ms; lastTMR = tmr10ms;
#define MAX_ACT 0xffff #define MAX_ACT 0xffff
static int16_t s_fp_chans[NUM_CHNOUT];
static uint16_t fp_act[MAX_PHASES] = {0}; static uint16_t fp_act[MAX_PHASES] = {0};
static uint16_t delta = 0; static uint16_t delta = 0;
static uint8_t s_fade_flight_phases = 0; static uint8_t s_fade_flight_phases = 0;
static uint8_t s_last_phase = 255; static uint8_t s_last_phase = 255;
#ifdef PCBV4
static int16_t s_fp_chans[NUM_CHNOUT][MAX_PHASES];
#else
static int8_t s_fp_chans[NUM_CHNOUT][MAX_PHASES];
#endif
uint8_t phase = getFlightPhase(); uint8_t phase = getFlightPhase();
if (s_last_phase != phase) { if (s_last_phase != phase) {
@@ -1419,6 +1415,10 @@ void perMain()
else { else {
uint8_t fadeTime = max(g_model.phaseData[s_last_phase].fadeOut, g_model.phaseData[phase].fadeIn); uint8_t fadeTime = max(g_model.phaseData[s_last_phase].fadeOut, g_model.phaseData[phase].fadeIn);
if (fadeTime) { if (fadeTime) {
if (!s_fade_flight_phases) {
for (uint8_t i=0; i<NUM_CHNOUT; i++)
s_fp_chans[i] = chans[i];
}
s_fade_flight_phases |= (1<<s_last_phase) + (1<<phase); s_fade_flight_phases |= (1<<s_last_phase) + (1<<phase);
delta = (MAX_ACT / 100) / fadeTime; delta = (MAX_ACT / 100) / fadeTime;
} }
@@ -1438,22 +1438,11 @@ void perMain()
int32_t weight = 0; int32_t 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)) {
for (uint8_t i=0; i<NUM_CHNOUT; i++) { for (uint8_t i=0; i<NUM_CHNOUT; i++)
#ifdef PCBV4 chans[i] = s_fp_chans[i];
chans[i] = ((int32_t)s_fp_chans[i][p]) << 2;
#else
chans[i] = ((int32_t)s_fp_chans[i][p]) << 10;
#endif
}
perOut(next_chans512, p); perOut(next_chans512, p);
for (uint8_t i=0; i<NUM_CHNOUT; i++) { for (uint8_t i=0; i<NUM_CHNOUT; i++)
#ifdef PCBV4
s_fp_chans[i][p] = chans[i] >> 2;
#else
s_fp_chans[i][p] = chans[i] >> 10;
#endif
sum_chans512[i] += (int32_t)next_chans512[i] * fp_act[p]; sum_chans512[i] += (int32_t)next_chans512[i] * fp_act[p];
}
weight += fp_act[p]; weight += fp_act[p];
} }
} }
@@ -1461,6 +1450,7 @@ void perMain()
assert(weight); assert(weight);
for (uint8_t i=0; i<NUM_CHNOUT; i++) { for (uint8_t i=0; i<NUM_CHNOUT; i++) {
next_chans512[i] = ((int32_t)sum_chans512[i] / weight); next_chans512[i] = ((int32_t)sum_chans512[i] / weight);
s_fp_chans[i] = next_chans512[i];
} }
// printf("output = %d\n", next_chans512[2]); fflush(stdout); // printf("output = %d\n", next_chans512[2]); fflush(stdout);
} }
-1
View File
@@ -65,7 +65,6 @@
#endif #endif
#include "file.h" #include "file.h"
#include "lcd.h" #include "lcd.h"
#include "myeeprom.h" #include "myeeprom.h"