AP_RCProtocol: lock onto a single protocol to reduce CPU cost

This commit is contained in:
Andrew Tridgell 2018-01-18 10:12:16 +11:00
parent d7c62602ed
commit f87668c15c
2 changed files with 15 additions and 1 deletions

View File

@ -29,12 +29,25 @@ void AP_RCProtocol::init()
void AP_RCProtocol::process_pulse(uint32_t width_s0, uint32_t width_s1)
{
uint32_t now = AP_HAL::millis();
// first try current protocol
if (_detected_protocol != AP_RCProtocol::NONE && now - _last_input_ms < 200) {
backend[_detected_protocol]->process_pulse(width_s0, width_s1);
if (backend[_detected_protocol]->new_input()) {
_new_input = true;
_last_input_ms = AP_HAL::millis();
}
return;
}
// otherwise scan all protocols
for (uint8_t i = 0; i < AP_RCProtocol::NONE; i++) {
if (backend[i] != nullptr) {
backend[i]->process_pulse(width_s0, width_s1);
if (backend[i]->new_input()) {
_new_input = true;
_detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i;
_last_input_ms = AP_HAL::millis();
}
}
}

View File

@ -41,6 +41,7 @@ private:
AP_RCProtocol_Backend *backend[NONE];
uint8_t num_backends = NONE;
bool _new_input = false;
uint32_t _last_input_ms;
};
#include "AP_RCProtocol_Backend.h"
#include "AP_RCProtocol_Backend.h"