analog_joystick.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <stdbool.h>
  18. #include <stdint.h>
  19. #ifndef ANALOG_JOYSTICK_X_AXIS_PIN
  20. # error No pin specified for X Axis
  21. #endif
  22. #ifndef ANALOG_JOYSTICK_Y_AXIS_PIN
  23. # error No pin specified for Y Axis
  24. #endif
  25. #ifndef ANALOG_JOYSTICK_AXIS_MIN
  26. # define ANALOG_JOYSTICK_AXIS_MIN 0
  27. #endif
  28. #ifndef ANALOG_JOYSTICK_AXIS_MAX
  29. # define ANALOG_JOYSTICK_AXIS_MAX 1023
  30. #endif
  31. #ifndef ANALOG_JOYSTICK_SPEED_REGULATOR
  32. # define ANALOG_JOYSTICK_SPEED_REGULATOR 20
  33. #endif
  34. #ifndef ANALOG_JOYSTICK_READ_INTERVAL
  35. # define ANALOG_JOYSTICK_READ_INTERVAL 10
  36. #endif
  37. #ifndef ANALOG_JOYSTICK_SPEED_MAX
  38. # define ANALOG_JOYSTICK_SPEED_MAX 2
  39. #endif
  40. typedef struct {
  41. int8_t x;
  42. int8_t y;
  43. bool button;
  44. } report_analog_joystick_t;
  45. report_analog_joystick_t analog_joystick_read(void);
  46. void analog_joystick_init(void);