joypad_linux.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*************************************************************************/
  2. /* joypad_linux.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. //author: Andreas Haas <hondres, liugam3@gmail.com>
  31. #ifndef JOYPAD_LINUX_H
  32. #define JOYPAD_LINUX_H
  33. #ifdef JOYDEV_ENABLED
  34. #include "main/input_default.h"
  35. #include "os/mutex.h"
  36. #include "os/thread.h"
  37. struct input_absinfo;
  38. class JoypadLinux {
  39. public:
  40. JoypadLinux(InputDefault *in);
  41. ~JoypadLinux();
  42. void process_joypads();
  43. private:
  44. enum {
  45. JOYPADS_MAX = 16,
  46. MAX_ABS = 63,
  47. MAX_KEY = 767, // Hack because <linux/input.h> can't be included here
  48. };
  49. struct Joypad {
  50. InputDefault::JoyAxis curr_axis[MAX_ABS];
  51. int key_map[MAX_KEY];
  52. int abs_map[MAX_ABS];
  53. int dpad;
  54. int fd;
  55. String devpath;
  56. input_absinfo *abs_info[MAX_ABS];
  57. bool force_feedback;
  58. int ff_effect_id;
  59. uint64_t ff_effect_timestamp;
  60. Joypad();
  61. ~Joypad();
  62. void reset();
  63. };
  64. bool exit_udev;
  65. Mutex *joy_mutex;
  66. Thread *joy_thread;
  67. InputDefault *input;
  68. Joypad joypads[JOYPADS_MAX];
  69. Vector<String> attached_devices;
  70. static void joy_thread_func(void *p_user);
  71. int get_joy_from_path(String p_path) const;
  72. void setup_joypad_properties(int p_id);
  73. void close_joypad(int p_id = -1);
  74. #ifdef UDEV_ENABLED
  75. void enumerate_joypads(struct udev *p_udev);
  76. void monitor_joypads(struct udev *p_udev);
  77. #endif
  78. void monitor_joypads();
  79. void run_joypad_thread();
  80. void open_joypad(const char *p_path);
  81. void joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp);
  82. void joypad_vibration_stop(int p_id, uint64_t p_timestamp);
  83. InputDefault::JoyAxis axis_correct(const input_absinfo *p_abs, int p_value) const;
  84. };
  85. #endif
  86. #endif // JOYPAD_LINUX_H