Browse Source

drivers/rc_input: RC_INPUT_PROTO parameter minimal implementation (#19539)

Co-authored-by: chris1seto <chris12892@gmail.com>

Co-authored-by: chris1seto <chris12892@gmail.com>
main
Daniel Agar 3 years ago committed by GitHub
parent
commit
a15432fac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      src/drivers/rc_input/RCInput.cpp
  2. 25
      src/drivers/rc_input/RCInput.hpp
  3. 24
      src/drivers/rc_input/module.yaml

35
src/drivers/rc_input/RCInput.cpp

@ -1,6 +1,6 @@ @@ -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) : @@ -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<RC_SCAN>(_param_rc_input_proto.get());
}
}
RCInput::~RCInput()
@ -251,9 +255,21 @@ RCInput::fill_rc_in(uint16_t raw_rc_count_local, @@ -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<RC_SCAN>(_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() @@ -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() @@ -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() @@ -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;

25
src/drivers/rc_input/RCInput.hpp

@ -1,6 +1,6 @@ @@ -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: @@ -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: @@ -168,6 +170,7 @@ private:
DEFINE_PARAMETERS(
(ParamInt<px4::params::RC_RSSI_PWM_CHAN>) _param_rc_rssi_pwm_chan,
(ParamInt<px4::params::RC_RSSI_PWM_MIN>) _param_rc_rssi_pwm_min,
(ParamInt<px4::params::RC_RSSI_PWM_MAX>) _param_rc_rssi_pwm_max
(ParamInt<px4::params::RC_RSSI_PWM_MAX>) _param_rc_rssi_pwm_max,
(ParamInt<px4::params::RC_INPUT_PROTO>) _param_rc_input_proto
)
};

24
src/drivers/rc_input/module.yaml

@ -1,4 +1,28 @@ @@ -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:

Loading…
Cancel
Save