RCInput.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * This file is free software: you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This file is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. * Code by Andrew Tridgell and Siddharth Bharat Purohit
  16. */
  17. #pragma once
  18. #include "AP_HAL_ChibiOS.h"
  19. #include "Semaphores.h"
  20. #if HAL_RCINPUT_WITH_AP_RADIO
  21. #include <AP_Radio/AP_Radio.h>
  22. #endif
  23. #include <AP_RCProtocol/AP_RCProtocol.h>
  24. #if HAL_USE_ICU == TRUE
  25. #include "SoftSigReader.h"
  26. #endif
  27. #if HAL_USE_EICU == TRUE
  28. #include "SoftSigReaderInt.h"
  29. #endif
  30. #ifndef RC_INPUT_MAX_CHANNELS
  31. #define RC_INPUT_MAX_CHANNELS 18
  32. #endif
  33. class ChibiOS::RCInput : public AP_HAL::RCInput {
  34. public:
  35. void init() override;
  36. bool new_input() override;
  37. uint8_t num_channels() override;
  38. uint16_t read(uint8_t ch) override;
  39. uint8_t read(uint16_t* periods, uint8_t len) override;
  40. int16_t get_rssi(void) override {
  41. return _rssi;
  42. }
  43. const char *protocol() const override { return last_protocol; }
  44. void _timer_tick(void);
  45. bool rc_bind(int dsmMode) override;
  46. private:
  47. uint16_t _rc_values[RC_INPUT_MAX_CHANNELS] = {0};
  48. uint64_t _last_read;
  49. uint8_t _num_channels;
  50. Semaphore rcin_mutex;
  51. int16_t _rssi = -1;
  52. uint32_t _rcin_timestamp_last_signal;
  53. bool _init;
  54. const char *last_protocol;
  55. #if HAL_RCINPUT_WITH_AP_RADIO
  56. bool _radio_init;
  57. AP_Radio *radio;
  58. uint32_t last_radio_us;
  59. #endif
  60. #if HAL_USE_ICU == TRUE
  61. ChibiOS::SoftSigReader sig_reader;
  62. #endif
  63. #if HAL_USE_EICU == TRUE
  64. ChibiOS::SoftSigReaderInt sig_reader;
  65. #endif
  66. #if HAL_WITH_IO_MCU
  67. uint32_t last_iomcu_us;
  68. #endif
  69. };