AP_Button.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #pragma once
  14. #include <AP_HAL/AP_HAL.h>
  15. #include <AP_Param/AP_Param.h>
  16. // allow buttons for up to 4 pins
  17. #define AP_BUTTON_NUM_PINS 4
  18. // how often we send reports
  19. #define AP_BUTTON_REPORT_PERIOD_MS 1000
  20. class AP_Button {
  21. public:
  22. // constructor
  23. AP_Button(void);
  24. static const struct AP_Param::GroupInfo var_info[];
  25. // update button state and send messages, called periodically by main loop
  26. void update(void);
  27. private:
  28. AP_Int8 enable;
  29. AP_Int8 pin[AP_BUTTON_NUM_PINS];
  30. // number of seconds to send change notifications
  31. AP_Int16 report_send_time;
  32. // last button press mask
  33. uint8_t last_mask;
  34. // when the mask last changed
  35. uint64_t last_change_time_ms;
  36. // time of last report
  37. uint32_t last_report_ms;
  38. // has the timer been installed?
  39. bool initialised:1;
  40. // called by timer thread
  41. void timer_update(void);
  42. // get current mask
  43. uint8_t get_mask(void);
  44. // send a BUTTON_CHANGE report
  45. void send_report(void);
  46. // setup pins as pullup input
  47. void setup_pins();
  48. };