Skip to content

Commit

Permalink
drivers/rc_input: RC_INPUT_PROTO parameter minimal implementation
Browse files Browse the repository at this point in the history
Co-authored-by: chris1seto <chris12892@gmail.com>
  • Loading branch information
dagar and chris1seto committed Apr 26, 2022
1 parent b2bcd26 commit b3e8e75
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
35 changes: 32 additions & 3 deletions 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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
}
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 14 additions & 11 deletions 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
Expand Down Expand Up @@ -91,21 +91,23 @@ class RCInput : public ModuleBase<RCInput>, public ModuleParams, public px4::Sch
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"
};
Expand Down Expand Up @@ -168,6 +170,7 @@ class RCInput : public ModuleBase<RCInput>, public ModuleParams, public px4::Sch
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 changes: 24 additions & 0 deletions 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:
Expand Down

0 comments on commit b3e8e75

Please sign in to comment.