Teensy 4.1 core updated for C++20
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. 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, int8_t horiz);
  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, int8_t horiz=0) {
  61. usb_mouse_move(x, y, wheel, horiz);
  62. }
  63. void moveTo(uint16_t x, uint16_t y) { usb_mouse_position(x, y); }
  64. void screenSize(uint16_t width, uint16_t height, bool isMacintosh = false) {
  65. usb_mouse_screen_size(width, height, isMacintosh ? 1 : 0);
  66. }
  67. void click(uint8_t b = MOUSE_LEFT) {
  68. usb_mouse_buttons_state = b;
  69. usb_mouse_move(0, 0, 0, 0);
  70. usb_mouse_buttons_state = 0;
  71. usb_mouse_move(0, 0, 0, 0);
  72. }
  73. void scroll(int8_t wheel, int8_t horiz=0) { usb_mouse_move(0, 0, wheel, horiz); }
  74. void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0) {
  75. usb_mouse_buttons(left, middle, right, back, forward);
  76. }
  77. void press(uint8_t b = MOUSE_LEFT) {
  78. uint8_t buttons = usb_mouse_buttons_state | (b & MOUSE_ALL);
  79. if (buttons != usb_mouse_buttons_state) {
  80. usb_mouse_buttons_state = buttons;
  81. usb_mouse_move(0, 0, 0, 0);
  82. }
  83. }
  84. void release(uint8_t b = MOUSE_LEFT) {
  85. uint8_t buttons = usb_mouse_buttons_state & ~(b & MOUSE_ALL);
  86. if (buttons != usb_mouse_buttons_state) {
  87. usb_mouse_buttons_state = buttons;
  88. usb_mouse_move(0, 0, 0, 0);
  89. }
  90. }
  91. bool isPressed(uint8_t b = MOUSE_ALL) {
  92. return ((usb_mouse_buttons_state & (b & MOUSE_ALL)) != 0);
  93. }
  94. };
  95. extern usb_mouse_class Mouse;
  96. #endif // __cplusplus
  97. #endif // MOUSE_INTERFACE
  98. #endif // USBmouse_h_