AP_RCProtocol_Backend.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "AP_RCProtocol.h"
  18. #include <AP_Math/AP_Math.h>
  19. #include <RC_Channel/RC_Channel.h>
  20. #include <AP_Vehicle/AP_Vehicle_Type.h>
  21. AP_RCProtocol_Backend::AP_RCProtocol_Backend(AP_RCProtocol &_frontend) :
  22. frontend(_frontend),
  23. rc_input_count(0),
  24. last_rc_input_count(0),
  25. _num_channels(0)
  26. {}
  27. bool AP_RCProtocol_Backend::new_input()
  28. {
  29. bool ret = rc_input_count != last_rc_input_count;
  30. if (ret) {
  31. last_rc_input_count = rc_input_count;
  32. }
  33. return ret;
  34. }
  35. uint8_t AP_RCProtocol_Backend::num_channels()
  36. {
  37. return _num_channels;
  38. }
  39. uint16_t AP_RCProtocol_Backend::read(uint8_t chan)
  40. {
  41. return _pwm_values[chan];
  42. }
  43. /*
  44. provide input from a backend
  45. */
  46. void AP_RCProtocol_Backend::add_input(uint8_t num_values, uint16_t *values, bool in_failsafe)
  47. {
  48. num_values = MIN(num_values, MAX_RCIN_CHANNELS);
  49. memcpy(_pwm_values, values, num_values*sizeof(uint16_t));
  50. _num_channels = num_values;
  51. rc_frame_count++;
  52. #if !APM_BUILD_TYPE(APM_BUILD_iofirmware)
  53. if (rc().ignore_rc_failsafe()) {
  54. in_failsafe = false;
  55. }
  56. #endif
  57. if (!in_failsafe) {
  58. rc_input_count++;
  59. }
  60. }