1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 13:25:30 +03:00

Failsafe - Remove magic number usage. Cleanup whitespace

This commit is contained in:
Dominic Clifton 2015-08-03 16:58:49 +01:00
parent 8e79a117d1
commit 3436b08575
4 changed files with 20 additions and 17 deletions

View file

@ -403,7 +403,7 @@ static void resetConf(void)
masterConfig.rxConfig.rx_min_usec = 885; // any of first 4 channels below this value will trigger rx loss detection
masterConfig.rxConfig.rx_max_usec = 2115; // any of first 4 channels above this value will trigger rx loss detection
for (i = 0; i < MAX_SUPPORTED_RC_CHANNEL_COUNT-4; i++) {
for (i = 0; i < MAX_AUX_CHANNEL_COUNT; i++) {
masterConfig.rxConfig.rx_fail_usec_steps[i] = CHANNEL_VALUE_TO_RXFAIL_STEP(masterConfig.rxConfig.midrc);
}

View file

@ -567,7 +567,7 @@ static void cliRxFail(char *cmdline)
if (isEmpty(cmdline)) {
// print out rxConfig failsafe settings
for (channel = 0; channel < MAX_SUPPORTED_RC_CHANNEL_COUNT-4; channel++) {
for (channel = 0; channel < MAX_AUX_CHANNEL_COUNT; channel++) {
cliRxFail(itoa(channel, buf, 10));
}
} else {
@ -575,7 +575,7 @@ static void cliRxFail(char *cmdline)
char *ptr = cmdline;
channel = atoi(ptr++);
if ((channel < MAX_SUPPORTED_RC_CHANNEL_COUNT-4)) {
if ((channel < MAX_AUX_CHANNEL_COUNT)) {
ptr = strchr(ptr, ' ');
if (ptr) {
value = atoi(++ptr);
@ -590,9 +590,12 @@ static void cliRxFail(char *cmdline)
// 1. acknowledge interpretation on command,
// 2. query current setting on single item,
// 3. recursive use for full list.
printf("rxfail %u %d\r\n", channel, RXFAIL_STEP_TO_CHANNEL_VALUE(masterConfig.rxConfig.rx_fail_usec_steps[channel]));
printf("rxfail %u %d\r\n",
channel,
RXFAIL_STEP_TO_CHANNEL_VALUE(masterConfig.rxConfig.rx_fail_usec_steps[channel])
);
} else {
printf("channel must be < %u\r\n", MAX_SUPPORTED_RC_CHANNEL_COUNT-4);
printf("channel must be < %u\r\n", MAX_AUX_CHANNEL_COUNT);
}
}
}

View file

@ -311,18 +311,18 @@ static uint16_t calculateNonDataDrivenChannel(uint8_t chan, uint16_t sample)
return rcDataMean[chan] / PPM_AND_PWM_SAMPLE_COUNT;
}
static uint16_t getRxfailValue(uint8_t chan)
static uint16_t getRxfailValue(uint8_t channel)
{
switch (chan) {
case ROLL:
case PITCH:
case YAW:
return rxConfig->midrc;
case THROTTLE:
if (feature(FEATURE_3D)) return rxConfig->midrc;
else return rxConfig->rx_min_usec;
default:
return RXFAIL_STEP_TO_CHANNEL_VALUE(rxConfig->rx_fail_usec_steps[chan-4]);
switch (channel) {
case ROLL:
case PITCH:
case YAW:
return rxConfig->midrc;
case THROTTLE:
if (feature(FEATURE_3D)) return rxConfig->midrc;
else return rxConfig->rx_min_usec;
default:
return RXFAIL_STEP_TO_CHANNEL_VALUE(rxConfig->rx_fail_usec_steps[channel - NON_AUX_CHANNEL_COUNT]);
}
}

View file

@ -94,7 +94,7 @@ typedef struct rxConfig_s {
uint16_t rx_min_usec;
uint16_t rx_max_usec;
uint8_t rx_fail_usec_steps[MAX_SUPPORTED_RC_CHANNEL_COUNT-4];
uint8_t rx_fail_usec_steps[MAX_AUX_CHANNEL_COUNT];
} rxConfig_t;