From 41191765adab6d08579f6ddd8ef12f890d7f8f7c Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 27 Apr 2022 23:06:43 -0400 Subject: [PATCH] drivers/rc_input: RC_INPUT_PROTO parameter minimal implementation (#19539) Co-authored-by: chris1seto Co-authored-by: chris1seto --- src/drivers/rc_input/RCInput.cpp | 35 +++++++++++++++++++++++++++++--- src/drivers/rc_input/RCInput.hpp | 25 +++++++++++++---------- src/drivers/rc_input/module.yaml | 24 ++++++++++++++++++++++ 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/src/drivers/rc_input/RCInput.cpp b/src/drivers/rc_input/RCInput.cpp index 071a678d0d..a15591c559 100644 --- a/src/drivers/rc_input/RCInput.cpp +++ b/src/drivers/rc_input/RCInput.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2012-2021 PX4 Development Team. All rights reserved. + * Copyright (c) 2012-2022 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -63,6 +63,10 @@ RCInput::RCInput(const char *device) : strncpy(_device, device, sizeof(_device) - 1); _device[sizeof(_device) - 1] = '\0'; } + + if ((_param_rc_input_proto.get() >= 0) && (_param_rc_input_proto.get() <= RC_SCAN::RC_SCAN_GHST)) { + _rc_scan_state = static_cast(_param_rc_input_proto.get()); + } } RCInput::~RCInput() @@ -251,9 +255,21 @@ RCInput::fill_rc_in(uint16_t raw_rc_count_local, void RCInput::set_rc_scan_state(RC_SCAN newState) { - PX4_DEBUG("RCscan: %s failed, trying %s", RCInput::RC_SCAN_STRING[_rc_scan_state], RCInput::RC_SCAN_STRING[newState]); + if ((_param_rc_input_proto.get() > RC_SCAN::RC_SCAN_NONE) + && (_param_rc_input_proto.get() <= RC_SCAN::RC_SCAN_GHST)) { + + _rc_scan_state = static_cast(_param_rc_input_proto.get()); + + } else if (_param_rc_input_proto.get() < 0) { + // only auto change if RC_INPUT_PROTO set to auto (-1) + PX4_DEBUG("RCscan: %s failed, trying %s", RCInput::RC_SCAN_STRING[_rc_scan_state], RCInput::RC_SCAN_STRING[newState]); + _rc_scan_state = newState; + + } else { + _rc_scan_state = RC_SCAN::RC_SCAN_NONE; + } + _rc_scan_begin = 0; - _rc_scan_state = newState; _rc_scan_locked = false; _report_lock = true; @@ -419,6 +435,10 @@ void RCInput::Run() } switch (_rc_scan_state) { + case RC_SCAN_NONE: + // do nothing + break; + case RC_SCAN_SBUS: if (_rc_scan_begin == 0) { _rc_scan_begin = cycle_timestamp; @@ -737,6 +757,12 @@ void RCInput::Run() if (_report_lock && _rc_scan_locked) { _report_lock = false; PX4_INFO("RC scan: %s RC input locked", RC_SCAN_STRING[_rc_scan_state]); + + if (!_armed && (_param_rc_input_proto.get() < 0)) { + // RC_INPUT_PROTO auto => locked selection + _param_rc_input_proto.set(_rc_scan_state); + _param_rc_input_proto.commit(); + } } } } @@ -823,6 +849,9 @@ int RCInput::print_status() if (_rc_scan_locked) { switch (_rc_scan_state) { + case RC_SCAN_NONE: + break; + case RC_SCAN_CRSF: PX4_INFO("CRSF Telemetry: %s", _crsf_telemetry ? "yes" : "no"); break; diff --git a/src/drivers/rc_input/RCInput.hpp b/src/drivers/rc_input/RCInput.hpp index 41c7dbbea1..d5b2e03ad2 100644 --- a/src/drivers/rc_input/RCInput.hpp +++ b/src/drivers/rc_input/RCInput.hpp @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2012-2019, 2021 PX4 Development Team. All rights reserved. + * Copyright (c) 2012-2022 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -91,21 +91,23 @@ public: private: enum RC_SCAN { - RC_SCAN_PPM = 0, - RC_SCAN_SBUS, - RC_SCAN_DSM, - RC_SCAN_SUMD, - RC_SCAN_ST24, - RC_SCAN_CRSF, - RC_SCAN_GHST + RC_SCAN_NONE = 0, + RC_SCAN_PPM = 1, + RC_SCAN_SBUS = 2, + RC_SCAN_DSM = 3, + RC_SCAN_ST24 = 5, + RC_SCAN_SUMD = 4, + RC_SCAN_CRSF = 6, + RC_SCAN_GHST = 7, } _rc_scan_state{RC_SCAN_SBUS}; - static constexpr char const *RC_SCAN_STRING[7] { + static constexpr char const *RC_SCAN_STRING[] { + "None", "PPM", "SBUS", "DSM", - "SUMD", "ST24", + "SUMD", "CRSF", "GHST" }; @@ -168,6 +170,7 @@ private: DEFINE_PARAMETERS( (ParamInt) _param_rc_rssi_pwm_chan, (ParamInt) _param_rc_rssi_pwm_min, - (ParamInt) _param_rc_rssi_pwm_max + (ParamInt) _param_rc_rssi_pwm_max, + (ParamInt) _param_rc_input_proto ) }; diff --git a/src/drivers/rc_input/module.yaml b/src/drivers/rc_input/module.yaml index a8492ef8ce..d0f9040a6f 100644 --- a/src/drivers/rc_input/module.yaml +++ b/src/drivers/rc_input/module.yaml @@ -1,4 +1,28 @@ module_name: RC Input Driver +parameters: + - group: RC Input + definitions: + RC_INPUT_PROTO: + description: + short: RC input protocol + long: | + Select your RC input protocol or auto to scan. + category: System + type: enum + values: + -1: Auto + 0: None + 1: PPM + 2: SBUS + 3: DSM + 4: ST24 + 5: SUMD + 6: CRSF + 7: GHST + min: -1 + max: 7 + default: -1 + serial_config: - command: set RC_INPUT_ARGS "-d ${SERIAL_DEV}" port_config_param: