Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 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. int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward);
  40. int usb_mouse_move(int8_t x, int8_t y, int8_t wheel);
  41. int usb_mouse_position(uint16_t x, uint16_t y);
  42. void usb_mouse_screen_size(uint16_t width, uint16_t height, uint8_t mac);
  43. extern uint8_t usb_mouse_buttons_state;
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #define MOUSE_LEFT 1
  48. #define MOUSE_MIDDLE 4
  49. #define MOUSE_RIGHT 2
  50. #define MOUSE_BACK 8
  51. #define MOUSE_FORWARD 16
  52. #define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_BACK | MOUSE_FORWARD)
  53. // C++ interface
  54. #ifdef __cplusplus
  55. class usb_mouse_class
  56. {
  57. public:
  58. void begin(void) { }
  59. void end(void) { }
  60. void move(int8_t x, int8_t y, int8_t wheel=0) { usb_mouse_move(x, y, wheel); }
  61. void moveTo(uint16_t x, uint16_t y) { usb_mouse_position(x, y); }
  62. void screenSize(uint16_t width, uint16_t height, bool isMacintosh = false) {
  63. usb_mouse_screen_size(width, height, isMacintosh ? 1 : 0);
  64. }
  65. void click(uint8_t b = MOUSE_LEFT) {
  66. usb_mouse_buttons_state = b;
  67. usb_mouse_move(0, 0, 0);
  68. usb_mouse_buttons_state = 0;
  69. usb_mouse_move(0, 0, 0);
  70. }
  71. void scroll(int8_t wheel) { usb_mouse_move(0, 0, wheel); }
  72. void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0) {
  73. usb_mouse_buttons(left, middle, right, back, forward);
  74. }
  75. void press(uint8_t b = MOUSE_LEFT) {
  76. uint8_t buttons = usb_mouse_buttons_state | (b & MOUSE_ALL);
  77. if (buttons != usb_mouse_buttons_state) {
  78. usb_mouse_buttons_state = buttons;
  79. usb_mouse_move(0, 0, 0);
  80. }
  81. }
  82. void release(uint8_t b = MOUSE_LEFT) {
  83. uint8_t buttons = usb_mouse_buttons_state & ~(b & MOUSE_ALL);
  84. if (buttons != usb_mouse_buttons_state) {
  85. usb_mouse_buttons_state = buttons;
  86. usb_mouse_move(0, 0, 0);
  87. }
  88. }
  89. bool isPressed(uint8_t b = MOUSE_ALL) {
  90. return ((usb_mouse_buttons_state & (b & MOUSE_ALL)) != 0);
  91. }
  92. };
  93. extern usb_mouse_class Mouse;
  94. #endif // __cplusplus
  95. #endif // MOUSE_INTERFACE
  96. #endif // USBmouse_h_