From db0188d3a348acb97ae8afe581c6e033d8dbde8c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 14 Mar 2024 16:47:43 +1100 Subject: [PATCH] AP_HAL_SITL: add support for RC input from SITL FDM data --- libraries/AP_HAL_SITL/RCInput.cpp | 42 ++++--------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/libraries/AP_HAL_SITL/RCInput.cpp b/libraries/AP_HAL_SITL/RCInput.cpp index 9cffbbed620a3..c703c012f22af 100644 --- a/libraries/AP_HAL_SITL/RCInput.cpp +++ b/libraries/AP_HAL_SITL/RCInput.cpp @@ -3,9 +3,7 @@ #if CONFIG_HAL_BOARD == HAL_BOARD_SITL && AP_RCPROTOCOL_ENABLED - #include "RCInput.h" -#include #include using namespace HALSITL; @@ -19,53 +17,23 @@ void RCInput::init() bool RCInput::new_input() { - if (!using_rc_protocol) { - if (AP::RC().new_input()) { - using_rc_protocol = true; - } - } - if (using_rc_protocol) { - return AP::RC().new_input(); - } - if (_sitlState->new_rc_input) { - _sitlState->new_rc_input = false; - return true; - } - return false; + return AP::RC().new_input(); } uint16_t RCInput::read(uint8_t ch) { - if (using_rc_protocol) { - return AP::RC().read(ch); - } - if (ch >= num_channels()) { - return 0; - } - return _sitlState->pwm_input[ch]; + return AP::RC().read(ch); } uint8_t RCInput::read(uint16_t* periods, uint8_t len) { - if (len > num_channels()) { - len = num_channels(); - } - for (uint8_t i=0; i < len; i++) { - periods[i] = read(i); - } - return len; + AP::RC().read(periods, len); + return MIN(len, num_channels()); } uint8_t RCInput::num_channels() { - if (using_rc_protocol) { - return AP::RC().num_channels(); - } - SITL::SIM *_sitl = AP::sitl(); - if (_sitl) { - return MIN(_sitl->rc_chancount.get(), SITL_RC_INPUT_CHANNELS); - } - return SITL_RC_INPUT_CHANNELS; + return AP::RC().num_channels(); } #endif