Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

112 lines
3.7KB

  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2017 PJRC.COM, LLC.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * 1. The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * 2. If the Software is incorporated into a build system that allows
  17. * selection among a list of target devices, then similar target
  18. * devices manufactured by PJRC.COM must be included in the list of
  19. * target devices and selectable in the same manner.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  25. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  26. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  27. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. */
  30. #ifndef USBmouse_h_
  31. #define USBmouse_h_
  32. #include "usb_desc.h"
  33. #if defined(MOUSE_INTERFACE)
  34. #include <inttypes.h>
  35. // C language implementation
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. void usb_mouse_configure(void);
  40. int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward);
  41. int usb_mouse_move(int8_t x, int8_t y, int8_t wheel, int8_t horiz);
  42. int usb_mouse_position(uint16_t x, uint16_t y);
  43. void usb_mouse_screen_size(uint16_t width, uint16_t height, uint8_t mac);
  44. extern uint8_t usb_mouse_buttons_state;
  45. extern volatile uint8_t usb_configuration;
  46. #ifdef __cplusplus
  47. }
  48. #endif
  49. #define MOUSE_LEFT 1
  50. #define MOUSE_MIDDLE 4
  51. #define MOUSE_RIGHT 2
  52. #define MOUSE_BACK 8
  53. #define MOUSE_FORWARD 16
  54. #define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_BACK | MOUSE_FORWARD)
  55. // C++ interface
  56. #ifdef __cplusplus
  57. class usb_mouse_class
  58. {
  59. public:
  60. void begin(void) { }
  61. void end(void) { }
  62. void move(int8_t x, int8_t y, int8_t wheel=0, int8_t horiz=0) {
  63. usb_mouse_move(x, y, wheel, horiz);
  64. }
  65. void moveTo(uint16_t x, uint16_t y) { usb_mouse_position(x, y); }
  66. void screenSize(uint16_t width, uint16_t height, bool isMacintosh = false) {
  67. usb_mouse_screen_size(width, height, isMacintosh ? 1 : 0);
  68. }
  69. void click(uint8_t b = MOUSE_LEFT) {
  70. usb_mouse_buttons_state = b;
  71. usb_mouse_move(0, 0, 0, 0);
  72. usb_mouse_buttons_state = 0;
  73. usb_mouse_move(0, 0, 0, 0);
  74. }
  75. void scroll(int8_t wheel, int8_t horiz=0) { usb_mouse_move(0, 0, wheel, horiz); }
  76. void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0) {
  77. usb_mouse_buttons(left, middle, right, back, forward);
  78. }
  79. void press(uint8_t b = MOUSE_LEFT) {
  80. uint8_t buttons = usb_mouse_buttons_state | (b & MOUSE_ALL);
  81. if (buttons != usb_mouse_buttons_state) {
  82. usb_mouse_buttons_state = buttons;
  83. usb_mouse_move(0, 0, 0, 0);
  84. }
  85. }
  86. void release(uint8_t b = MOUSE_LEFT) {
  87. uint8_t buttons = usb_mouse_buttons_state & ~(b & MOUSE_ALL);
  88. if (buttons != usb_mouse_buttons_state) {
  89. usb_mouse_buttons_state = buttons;
  90. usb_mouse_move(0, 0, 0, 0);
  91. }
  92. }
  93. bool isPressed(uint8_t b = MOUSE_ALL) {
  94. return ((usb_mouse_buttons_state & (b & MOUSE_ALL)) != 0);
  95. }
  96. };
  97. extern usb_mouse_class Mouse;
  98. #endif // __cplusplus
  99. #endif // MOUSE_INTERFACE
  100. #endif // USBmouse_h_