Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shota3527 committed Aug 31, 2023
1 parent bf0c0d8 commit 1d0d5be
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/main/flight/servos.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ int16_t servo[MAX_SUPPORTED_SERVOS];

static uint8_t servoRuleCount = 0;
static servoMixer_t currentServoMixer[MAX_SERVO_RULES*MAX_MIXER_PROFILE_COUNT];
static bool currentServoMixerActivative[MAX_SERVO_RULES*MAX_MIXER_PROFILE_COUNT];// if true, the rule is used by current servo mixer
static bool servoOutputEnabled;

static bool mixerUsesServos;
Expand Down Expand Up @@ -194,7 +193,7 @@ void loadCustomServoMixer(void)
}

memcpy(&currentServoMixer[servoRuleCount], &tmp_customServoMixers[i], sizeof(servoMixer_t));
currentServoMixerActivative[servoRuleCount] = j==currentMixerProfileIndex;
currentServoMixer[servoRuleCount].rate = (j==currentMixerProfileIndex) ? currentServoMixer[servoRuleCount].rate : 0; //set rate to 0 if not active profile
servoRuleCount++;
}
}
Expand Down Expand Up @@ -353,9 +352,6 @@ void servoMixer(float dT)
inputRaw = 0;
}
#endif
if (!currentServoMixerActivative[i]) {
inputRaw = 0;
}
/*
* Apply mixer speed limit. 1 [one] speed unit is defined as 10us/s:
* 0 = no limiting
Expand Down Expand Up @@ -438,7 +434,7 @@ void processServoAutotrimMode(void)
if (ARMING_FLAG(ARMED)) {
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
for (int i = 0; i < servoRuleCount; i++) {
if (!currentServoMixerActivative[i]) {continue;}
if (currentServoMixer[i].rate==0) {continue;}
// Reset servo middle accumulator
const uint8_t target = currentServoMixer[i].targetChannel;
const uint8_t source = currentServoMixer[i].inputSource;
Expand All @@ -461,7 +457,7 @@ void processServoAutotrimMode(void)
if (ARMING_FLAG(ARMED)) {
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
for (int i = 0; i < servoRuleCount; i++) {
if (!currentServoMixerActivative[i]) {continue;}
if (currentServoMixer[i].rate==0) {continue;}
const uint8_t target = currentServoMixer[i].targetChannel;
const uint8_t source = currentServoMixer[i].inputSource;
if (source == axis) {
Expand All @@ -474,7 +470,7 @@ void processServoAutotrimMode(void)
if ((millis() - trimStartedAt) > SERVO_AUTOTRIM_TIMER_MS) {
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
for (int i = 0; i < servoRuleCount; i++) {
if (!currentServoMixerActivative[i]) {continue;}
if (currentServoMixer[i].rate==0) {continue;}
const uint8_t target = currentServoMixer[i].targetChannel;
const uint8_t source = currentServoMixer[i].inputSource;
if (source == axis) {
Expand Down Expand Up @@ -508,7 +504,7 @@ void processServoAutotrimMode(void)
if (trimState == AUTOTRIM_SAVE_PENDING) {
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
for (int i = 0; i < servoRuleCount; i++) {
if (!currentServoMixerActivative[i]) {continue;}
if (currentServoMixer[i].rate==0) {continue;}
const uint8_t target = currentServoMixer[i].targetChannel;
const uint8_t source = currentServoMixer[i].inputSource;
if (source == axis) {
Expand Down

0 comments on commit 1d0d5be

Please sign in to comment.