RCInput_Multi.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. this is a driver for multiple RCInput methods on one board
  15. */
  16. #include <AP_HAL/AP_HAL.h>
  17. #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO || \
  18. CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
  19. #include "RCInput_Multi.h"
  20. extern const AP_HAL::HAL& hal;
  21. using namespace Linux;
  22. // constructor
  23. RCInput_Multi::RCInput_Multi(uint8_t _num_inputs, ...) :
  24. num_inputs(_num_inputs)
  25. {
  26. va_list ap;
  27. inputs = new RCInput*[num_inputs];
  28. if (inputs == nullptr) {
  29. AP_HAL::panic("failed to allocated RCInput array");
  30. }
  31. va_start(ap, _num_inputs);
  32. for (uint8_t i=0; i<num_inputs; i++) {
  33. inputs[i] = va_arg(ap, RCInput *);
  34. if (inputs[i] == nullptr) {
  35. AP_HAL::panic("Bad RCInput object");
  36. }
  37. }
  38. va_end(ap);
  39. }
  40. void RCInput_Multi::init()
  41. {
  42. for (uint8_t i=0; i<num_inputs; i++) {
  43. inputs[i]->init();
  44. }
  45. }
  46. void RCInput_Multi::_timer_tick(void)
  47. {
  48. for (uint8_t i=0; i<num_inputs; i++) {
  49. inputs[i]->_timer_tick();
  50. if (inputs[i]->new_input()) {
  51. inputs[i]->read(_pwm_values, inputs[i]->num_channels());
  52. _num_channels = inputs[i]->num_channels();
  53. rc_input_count++;
  54. }
  55. }
  56. }
  57. #endif // CONFIG_HAL_BOARD_SUBTYPE