AP_RCProtocol: lock onto a single protocol to reduce CPU cost
This commit is contained in:
parent
d7c62602ed
commit
f87668c15c
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user