mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-06 07:53:57 -04:00
AP_RCProtocol: added multi-channel read() API
and use pulse_input_enable() to disable pulse input when not needed
This commit is contained in:
parent
3105c6a050
commit
8e67c3459a
@ -26,6 +26,8 @@
|
||||
#include "AP_RCProtocol_FPort.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);
|
||||
@ -150,6 +152,9 @@ bool 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;
|
||||
}
|
||||
}
|
||||
@ -257,6 +262,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);
|
||||
}
|
||||
}
|
||||
|
||||
int16_t AP_RCProtocol::get_RSSI(void) const
|
||||
{
|
||||
if (_detected_protocol != AP_RCProtocol::NONE) {
|
||||
|
@ -62,6 +62,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);
|
||||
int16_t get_RSSI(void) const;
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user