2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2015-05-04 03:15:12 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2012-12-17 23:56:21 -04:00
|
|
|
|
|
|
|
#include "RCInput.h"
|
|
|
|
|
2015-05-04 03:15:12 -03:00
|
|
|
using namespace HALSITL;
|
2012-12-17 23:56:21 -04:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
2015-12-02 11:14:20 -04:00
|
|
|
void SITLRCInput::init()
|
2012-12-17 23:56:21 -04:00
|
|
|
{
|
|
|
|
clear_overrides();
|
|
|
|
}
|
|
|
|
|
2015-05-04 21:59:07 -03:00
|
|
|
bool SITLRCInput::new_input()
|
2015-02-08 18:56:47 -04:00
|
|
|
{
|
|
|
|
if (_sitlState->new_rc_input) {
|
|
|
|
_sitlState->new_rc_input = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-12-17 23:56:21 -04:00
|
|
|
}
|
|
|
|
|
2016-01-03 17:22:02 -04:00
|
|
|
uint16_t SITLRCInput::read(uint8_t ch)
|
|
|
|
{
|
|
|
|
if (ch >= SITL_RC_INPUT_CHANNELS) {
|
2014-11-11 00:15:28 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-12-17 23:56:21 -04:00
|
|
|
return _override[ch]? _override[ch] : _sitlState->pwm_input[ch];
|
|
|
|
}
|
|
|
|
|
2016-01-03 17:22:02 -04:00
|
|
|
uint8_t SITLRCInput::read(uint16_t* periods, uint8_t len)
|
|
|
|
{
|
|
|
|
if (len > SITL_RC_INPUT_CHANNELS) {
|
|
|
|
len = SITL_RC_INPUT_CHANNELS;
|
|
|
|
}
|
2012-12-17 23:56:21 -04:00
|
|
|
for (uint8_t i=0; i<len; i++) {
|
2015-05-04 21:59:07 -03:00
|
|
|
periods[i] = _override[i]? _override[i] : _sitlState->pwm_input[i];
|
2012-12-17 23:56:21 -04:00
|
|
|
}
|
2014-03-25 00:39:41 -03:00
|
|
|
return 8;
|
2012-12-17 23:56:21 -04:00
|
|
|
}
|
|
|
|
|
2016-01-03 17:22:02 -04:00
|
|
|
bool SITLRCInput::set_overrides(int16_t *overrides, uint8_t len)
|
|
|
|
{
|
2012-12-17 23:56:21 -04:00
|
|
|
bool res = false;
|
2016-01-03 17:22:02 -04:00
|
|
|
if (len > SITL_RC_INPUT_CHANNELS) {
|
|
|
|
len = SITL_RC_INPUT_CHANNELS;
|
|
|
|
}
|
2012-12-17 23:56:21 -04:00
|
|
|
for (uint8_t i = 0; i < len; i++) {
|
|
|
|
res |= set_override(i, overrides[i]);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-01-03 17:22:02 -04:00
|
|
|
bool SITLRCInput::set_override(uint8_t channel, int16_t override)
|
|
|
|
{
|
2012-12-17 23:56:21 -04:00
|
|
|
if (override < 0) return false; /* -1: no change. */
|
2016-01-03 17:22:02 -04:00
|
|
|
if (channel < SITL_RC_INPUT_CHANNELS) {
|
2012-12-17 23:56:21 -04:00
|
|
|
_override[channel] = override;
|
|
|
|
if (override != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SITLRCInput::clear_overrides()
|
|
|
|
{
|
2016-01-03 17:22:02 -04:00
|
|
|
memset(_override, 0, sizeof(_override));
|
2012-12-17 23:56:21 -04:00
|
|
|
}
|
2012-12-18 05:04:47 -04:00
|
|
|
#endif
|