AP_RCProtocol: added multi-channel read() API

and use pulse_input_enable() to disable pulse input when not needed
This commit is contained in:
Andrew Tridgell 2020-01-29 18:36:56 +11:00 committed by Randy Mackay
parent 3ca8b7b40f
commit 07ee3b4c5e
4 changed files with 22 additions and 0 deletions

View File

@ -25,6 +25,8 @@
#include "AP_RCProtocol_ST24.h"
#include <AP_Math/AP_Math.h>
extern const AP_HAL::HAL& hal;
void AP_RCProtocol::init()
{
backend[AP_RCProtocol::PPM] = new AP_RCProtocol_PPMSum(*this);
@ -148,6 +150,9 @@ void AP_RCProtocol::process_byte(uint8_t byte, uint32_t baudrate)
memset(_good_frames, 0, sizeof(_good_frames));
_last_input_ms = now;
_detected_with_bytes = true;
// stop decoding pulses to save CPU
hal.rcin->pulse_input_enable(false);
break;
}
}
@ -240,6 +245,13 @@ uint16_t AP_RCProtocol::read(uint8_t chan)
return 0;
}
void AP_RCProtocol::read(uint16_t *pwm, uint8_t n)
{
if (_detected_protocol != AP_RCProtocol::NONE) {
backend[_detected_protocol]->read(pwm, n);
}
}
/*
ask for bind start on supported receivers (eg spektrum satellite)
*/

View File

@ -64,6 +64,7 @@ public:
}
uint8_t num_channels();
uint16_t read(uint8_t chan);
void read(uint16_t *pwm, uint8_t n);
bool new_input();
void start_bind(void);

View File

@ -46,6 +46,14 @@ uint16_t AP_RCProtocol_Backend::read(uint8_t chan)
return _pwm_values[chan];
}
void AP_RCProtocol_Backend::read(uint16_t *pwm, uint8_t n)
{
if (n >= MAX_RCIN_CHANNELS) {
n = MAX_RCIN_CHANNELS;
}
memcpy(pwm, _pwm_values, n*sizeof(pwm[0]));
}
/*
provide input from a backend
*/

View File

@ -28,6 +28,7 @@ public:
virtual void process_pulse(uint32_t width_s0, uint32_t width_s1) {}
virtual void process_byte(uint8_t byte, uint32_t baudrate) {}
uint16_t read(uint8_t chan);
void read(uint16_t *pwm, uint8_t n);
bool new_input();
uint8_t num_channels();