HAL_Linux: added RCInput_Multi

this allows for multiple RCInput methods on one board. On Disco it
combines RCInput_115200 with RCInput_SBUS
This commit is contained in:
Andrew Tridgell 2016-09-16 18:43:27 +10:00 committed by Lucas De Marchi
parent 5909552f67
commit 3eb8b5e99f
3 changed files with 112 additions and 2 deletions

View File

@ -28,6 +28,8 @@
#include "RCInput_SBUS.h"
#include "RCInput_UART.h"
#include "RCInput_UDP.h"
#include "RCInput_115200.h"
#include "RCInput_Multi.h"
#include "RCOutput_AeroIO.h"
#include "RCOutput_AioPRU.h"
#include "RCOutput_Bebop.h"
@ -146,8 +148,9 @@ static RCInput_UDP rcinDriver;
static RCInput_UART rcinDriver("/dev/ttyS2");
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_QFLIGHT
static RCInput_DSM rcinDriver;
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_AERO
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
static RCInput_Multi rcinDriver{2, new RCInput_SBUS, new RCInput_115200("/dev/uart-sumd")};
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_AERO
static RCInput_SBUS rcinDriver;
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2
static RCInput_Navio2 rcinDriver;

View File

@ -0,0 +1,68 @@
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
/*
This program 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 program 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/>.
*/
/*
this is a driver for multiple RCInput methods on one board
*/
#include <AP_HAL/AP_HAL.h>
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
#include "RCInput_Multi.h"
extern const AP_HAL::HAL& hal;
using namespace Linux;
// constructor
RCInput_Multi::RCInput_Multi(uint8_t _num_inputs, ...) :
num_inputs(_num_inputs)
{
va_list ap;
inputs = new RCInput*[num_inputs];
if (inputs == nullptr) {
AP_HAL::panic("failed to allocated RCInput array");
}
va_start(ap, _num_inputs);
for (uint8_t i=0; i<num_inputs; i++) {
inputs[i] = va_arg(ap, RCInput *);
if (inputs[i] == nullptr) {
AP_HAL::panic("Bad RCInput object");
}
}
va_end(ap);
}
void RCInput_Multi::init()
{
for (uint8_t i=0; i<num_inputs; i++) {
inputs[i]->init();
}
}
void RCInput_Multi::_timer_tick(void)
{
for (uint8_t i=0; i<num_inputs; i++) {
inputs[i]->_timer_tick();
if (inputs[i]->new_input()) {
inputs[i]->read(_pwm_values, inputs[i]->num_channels());
_num_channels = inputs[i]->num_channels();
new_rc_input = true;
}
}
}
#endif // CONFIG_HAL_BOARD_SUBTYPE

View File

@ -0,0 +1,39 @@
/*
This program 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 program 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/>.
*/
#pragma once
#include <AP_HAL/AP_HAL.h>
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO
#include "RCInput.h"
#include <stdarg.h>
namespace Linux {
class RCInput_Multi : public RCInput
{
public:
RCInput_Multi(uint8_t num_inputs, ...);
void init() override;
void _timer_tick(void) override;
private:
uint8_t num_inputs;
RCInput **inputs;
};
};
#endif // CONFIG_HAL_BOARD_SUBTYPE