diff options
author | Simon Wilks <sjwilks@gmail.com> | 2013-03-06 20:37:01 +0100 |
---|---|---|
committer | Simon Wilks <sjwilks@gmail.com> | 2013-03-06 20:37:01 +0100 |
commit | ae98836db8948edbcf59333627b25f69df4127d4 (patch) | |
tree | 83107bc280ee4c7de36f2b446da2915fb632fb6a /apps/px4io/registers.c | |
parent | 5cca76f4144d5e431f8768b39ddb4953dcc261be (diff) | |
download | px4-firmware-ae98836db8948edbcf59333627b25f69df4127d4.tar.gz px4-firmware-ae98836db8948edbcf59333627b25f69df4127d4.tar.bz2 px4-firmware-ae98836db8948edbcf59333627b25f69df4127d4.zip |
Correct RC config sanity checking and report back when RC config errors occur.
Diffstat (limited to 'apps/px4io/registers.c')
-rw-r--r-- | apps/px4io/registers.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/apps/px4io/registers.c b/apps/px4io/registers.c index 5ec2f7258..dac09021d 100644 --- a/apps/px4io/registers.c +++ b/apps/px4io/registers.c @@ -180,6 +180,12 @@ uint16_t r_page_rc_input_config[MAX_CONTROL_CHANNELS * PX4IO_P_RC_CONFIG_STRIDE uint16_t r_page_servo_failsafe[IO_SERVO_COUNT]; void +registers_init(void) +{ + r_status_flags |= PX4IO_P_STATUS_FLAGS_INIT_OK; +} + +void registers_set(uint8_t page, uint8_t offset, const uint16_t *values, unsigned num_values) { @@ -390,27 +396,44 @@ registers_set_one(uint8_t page, uint8_t offset, uint16_t value) /* should the channel be enabled? */ /* this option is normally set last */ if (value & PX4IO_P_RC_CONFIG_OPTIONS_ENABLED) { + uint8_t count = 0; + /* assert min..center..max ordering */ - if (conf[PX4IO_P_RC_CONFIG_MIN] < 500) - break; - if (conf[PX4IO_P_RC_CONFIG_MAX] > 2500) - break; - if (conf[PX4IO_P_RC_CONFIG_CENTER] < conf[PX4IO_P_RC_CONFIG_MIN]) - break; - if (conf[PX4IO_P_RC_CONFIG_CENTER] > conf[PX4IO_P_RC_CONFIG_MAX]) - break; + if (conf[PX4IO_P_RC_CONFIG_MIN] < 500) { + count++; + } + if (conf[PX4IO_P_RC_CONFIG_MAX] > 2500) { + count++; + } + if (conf[PX4IO_P_RC_CONFIG_CENTER] < conf[PX4IO_P_RC_CONFIG_MIN]) { + count++; + } + if (conf[PX4IO_P_RC_CONFIG_CENTER] > conf[PX4IO_P_RC_CONFIG_MAX]) { + count++; + } + /* assert deadzone is sane */ - if (conf[PX4IO_P_RC_CONFIG_DEADZONE] > 500) - break; - if (conf[PX4IO_P_RC_CONFIG_MIN] > (conf[PX4IO_P_RC_CONFIG_CENTER] - conf[PX4IO_P_RC_CONFIG_DEADZONE])) - break; - if (conf[PX4IO_P_RC_CONFIG_MAX] < (conf[PX4IO_P_RC_CONFIG_CENTER] + conf[PX4IO_P_RC_CONFIG_DEADZONE])) - break; - if (conf[PX4IO_P_RC_CONFIG_ASSIGNMENT] >= MAX_CONTROL_CHANNELS) - break; + if (conf[PX4IO_P_RC_CONFIG_DEADZONE] > 500) { + count++; + } + // The following check isn't needed as constraint checks in controls.c will catch this. + //if (conf[PX4IO_P_RC_CONFIG_MIN] > (conf[PX4IO_P_RC_CONFIG_CENTER] - conf[PX4IO_P_RC_CONFIG_DEADZONE])) { + // count++; + //} + //if (conf[PX4IO_P_RC_CONFIG_MAX] < (conf[PX4IO_P_RC_CONFIG_CENTER] + conf[PX4IO_P_RC_CONFIG_DEADZONE])) { + // count++; + //} + if (conf[PX4IO_P_RC_CONFIG_ASSIGNMENT] >= MAX_CONTROL_CHANNELS) { + count++; + } /* sanity checks pass, enable channel */ - conf[index] |= PX4IO_P_RC_CONFIG_OPTIONS_ENABLED; + if (count) { + isr_debug(0, "ERROR: %d config error(s) for RC%d.\n", count, (channel + 1)); + r_status_flags &= ~PX4IO_P_STATUS_FLAGS_INIT_OK; + } else { + conf[index] |= PX4IO_P_RC_CONFIG_OPTIONS_ENABLED; + } } break; /* inner switch: case PX4IO_P_RC_CONFIG_OPTIONS */ |