Teensy 4.1 core updated for C++20
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

106 lines
3.4KB

  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);
  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_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
  51. // C++ interface
  52. #ifdef __cplusplus
  53. class usb_mouse_class
  54. {
  55. public:
  56. void begin(void) { }
  57. void end(void) { }
  58. void move(int8_t x, int8_t y, int8_t wheel=0) { usb_mouse_move(x, y, wheel); }
  59. void moveTo(uint16_t x, uint16_t y) { usb_mouse_position(x, y); }
  60. void screenSize(uint16_t width, uint16_t height, bool isMacintosh = false) {
  61. usb_mouse_screen_size(width, height, isMacintosh ? 1 : 0);
  62. }
  63. void click(uint8_t b = MOUSE_LEFT) {
  64. usb_mouse_buttons_state = b;
  65. usb_mouse_move(0, 0, 0);
  66. usb_mouse_buttons_state = 0;
  67. usb_mouse_move(0, 0, 0);
  68. }
  69. void scroll(int8_t wheel) { usb_mouse_move(0, 0, wheel); }
  70. void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0) {
  71. usb_mouse_buttons(left, middle, right);
  72. }
  73. void press(uint8_t b = MOUSE_LEFT) {
  74. uint8_t buttons = usb_mouse_buttons_state | (b & MOUSE_ALL);
  75. if (buttons != usb_mouse_buttons_state) {
  76. usb_mouse_buttons_state = buttons;
  77. usb_mouse_move(0, 0, 0);
  78. }
  79. }
  80. void release(uint8_t b = MOUSE_LEFT) {
  81. uint8_t buttons = usb_mouse_buttons_state & ~(b & MOUSE_ALL);
  82. if (buttons != usb_mouse_buttons_state) {
  83. usb_mouse_buttons_state = buttons;
  84. usb_mouse_move(0, 0, 0);
  85. }
  86. }
  87. bool isPressed(uint8_t b = MOUSE_ALL) {
  88. return ((usb_mouse_buttons_state & (b & MOUSE_ALL)) != 0);
  89. }
  90. };
  91. extern usb_mouse_class Mouse;
  92. #endif // __cplusplus
  93. #endif // MOUSE_INTERFACE
  94. #endif // USBmouse_h_