Browse Source
this allows for multiple RCInput methods on one board. On Disco it combines RCInput_115200 with RCInput_SBUSmaster
3 changed files with 112 additions and 2 deletions
@ -0,0 +1,68 @@
@@ -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
|
||||
|
@ -0,0 +1,39 @@
@@ -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
|
Loading…
Reference in new issue