diff options
Diffstat (limited to 'src/drivers/px4io')
-rw-r--r-- | src/drivers/px4io/px4io.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/drivers/px4io/px4io.cpp b/src/drivers/px4io/px4io.cpp index 3fa12261e..e5636ff0f 100644 --- a/src/drivers/px4io/px4io.cpp +++ b/src/drivers/px4io/px4io.cpp @@ -111,10 +111,6 @@ extern device::Device *PX4IO_serial_interface() weak_function; #define ORB_CHECK_INTERVAL 200000 // 200 ms -> 5 Hz #define IO_POLL_INTERVAL 20000 // 20 ms -> 50 Hz -#define RC_RSSI_PWM_MAX 1000 -#define RC_RSSI_PWM_MIN 1800 -#define RC_RSSI_PWM_CHAN 8 - /** * The PX4IO class. * @@ -307,6 +303,10 @@ private: uint64_t _battery_last_timestamp;///< last amp hour calculation timestamp bool _cb_flighttermination; ///< true if the flight termination circuit breaker is enabled + int32_t _rssi_pwm_chan; ///< RSSI PWM input channel + int32_t _rssi_pwm_max; ///< max RSSI input on PWM channel + int32_t _rssi_pwm_min; ///< min RSSI input on PWM channel + #ifdef CONFIG_ARCH_BOARD_PX4FMU_V1 bool _dsm_vcc_ctl; ///< true if relay 1 controls DSM satellite RX power #endif @@ -528,7 +528,10 @@ PX4IO::PX4IO(device::Device *interface) : _battery_amp_bias(0), _battery_mamphour_total(0), _battery_last_timestamp(0), - _cb_flighttermination(true) + _cb_flighttermination(true), + _rssi_pwm_chan(0), + _rssi_pwm_max(0), + _rssi_pwm_min(0) #ifdef CONFIG_ARCH_BOARD_PX4FMU_V1 , _dsm_vcc_ctl(false) #endif @@ -668,6 +671,10 @@ PX4IO::init() if (_max_rc_input > RC_INPUT_MAX_CHANNELS) _max_rc_input = RC_INPUT_MAX_CHANNELS; + param_get(param_find("RC_RSSI_PWM_CHAN"), &_rssi_pwm_chan); + param_get(param_find("RC_RSSI_PWM_MAX"), &_rssi_pwm_max); + param_get(param_find("RC_RSSI_PWM_MIN"), &_rssi_pwm_min); + /* * Check for IO flight state - if FMU was flagged to be in * armed state, FMU is recovering from an in-air reset. @@ -1073,6 +1080,10 @@ PX4IO::task_main() /* Update Circuit breakers */ _cb_flighttermination = circuit_breaker_enabled("CBRK_FLIGHTTERM", CBRK_FLIGHTTERM_KEY); + param_get(param_find("RC_RSSI_PWM_CHAN"), &_rssi_pwm_chan); + param_get(param_find("RC_RSSI_PWM_MAX"), &_rssi_pwm_max); + param_get(param_find("RC_RSSI_PWM_MIN"), &_rssi_pwm_min); + } } @@ -1637,10 +1648,13 @@ PX4IO::io_get_raw_rc_input(rc_input_values &input_rc) input_rc.values[i] = regs[prolog + i]; } - // get RSSI from channel 8, input range 1000 - 2000 - if (RC_RSSI_PWM_CHAN > -1 && RC_RSSI_PWM_CHAN <= RC_INPUT_MAX_CHANNELS) { - input_rc.rssi = (input_rc.values[RC_RSSI_PWM_CHAN - 1] - RC_RSSI_PWM_MIN) * - ((RC_RSSI_PWM_MAX - RC_RSSI_PWM_MIN) / 255); + /* get RSSI from input channel */ + if (_rssi_pwm_chan > 0 && _rssi_pwm_chan <= RC_INPUT_MAX_CHANNELS && _rssi_pwm_max - _rssi_pwm_min != 0) { + int rssi = (input_rc.values[_rssi_pwm_chan - 1] - _rssi_pwm_min) / + ((_rssi_pwm_max - _rssi_pwm_min) / 100); + rssi = rssi > 100 ? 100 : rssi; + rssi = rssi < 0 ? 0 : rssi; + input_rc.rssi = rssi; } return ret; |