2018-01-17 15:31:11 -04:00
|
|
|
/*
|
|
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-07-20 01:25:40 -03:00
|
|
|
*
|
2018-01-17 15:31:11 -04:00
|
|
|
* Code by Andrew Tridgell and Siddharth Bharat Purohit
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AP_RCProtocol.h"
|
2018-01-18 17:40:07 -04:00
|
|
|
#include <AP_Math/AP_Math.h>
|
2019-03-11 18:28:23 -03:00
|
|
|
#include <RC_Channel/RC_Channel.h>
|
2019-03-12 19:05:25 -03:00
|
|
|
#include <AP_Vehicle/AP_Vehicle_Type.h>
|
2020-05-11 02:56:24 -03:00
|
|
|
#include <AP_Logger/AP_Logger.h>
|
2018-01-17 15:31:11 -04:00
|
|
|
|
2018-07-20 01:25:40 -03:00
|
|
|
AP_RCProtocol_Backend::AP_RCProtocol_Backend(AP_RCProtocol &_frontend) :
|
2018-01-17 15:31:11 -04:00
|
|
|
frontend(_frontend),
|
|
|
|
rc_input_count(0),
|
|
|
|
last_rc_input_count(0),
|
|
|
|
_num_channels(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool AP_RCProtocol_Backend::new_input()
|
|
|
|
{
|
|
|
|
bool ret = rc_input_count != last_rc_input_count;
|
|
|
|
if (ret) {
|
|
|
|
last_rc_input_count = rc_input_count;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t AP_RCProtocol_Backend::num_channels()
|
|
|
|
{
|
|
|
|
return _num_channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t AP_RCProtocol_Backend::read(uint8_t chan)
|
|
|
|
{
|
|
|
|
return _pwm_values[chan];
|
|
|
|
}
|
|
|
|
|
2020-01-29 03:36:56 -04:00
|
|
|
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]));
|
|
|
|
}
|
|
|
|
|
2018-01-18 17:40:07 -04:00
|
|
|
/*
|
|
|
|
provide input from a backend
|
|
|
|
*/
|
2020-05-11 02:56:24 -03:00
|
|
|
void AP_RCProtocol_Backend::add_input(uint8_t num_values, uint16_t *values, bool in_failsafe, int16_t _rssi)
|
2018-01-18 17:40:07 -04:00
|
|
|
{
|
|
|
|
num_values = MIN(num_values, MAX_RCIN_CHANNELS);
|
|
|
|
memcpy(_pwm_values, values, num_values*sizeof(uint16_t));
|
|
|
|
_num_channels = num_values;
|
2018-11-05 02:13:46 -04:00
|
|
|
rc_frame_count++;
|
2019-03-12 19:05:25 -03:00
|
|
|
#if !APM_BUILD_TYPE(APM_BUILD_iofirmware)
|
2019-03-29 07:27:50 -03:00
|
|
|
if (rc().ignore_rc_failsafe()) {
|
2019-03-12 19:05:25 -03:00
|
|
|
in_failsafe = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (!in_failsafe) {
|
2018-01-18 17:40:07 -04:00
|
|
|
rc_input_count++;
|
|
|
|
}
|
2020-05-11 02:56:24 -03:00
|
|
|
rssi = _rssi;
|
2018-01-18 17:40:07 -04:00
|
|
|
}
|
2020-05-11 02:56:24 -03:00
|
|
|
|