Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

USBHostMouse.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* mbed USBHost Library
  2. * Copyright (c) 2006-2013 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef USBHOSTMOUSE_H
  17. #define USBHOSTMOUSE_H
  18. #include "USBHostConf.h"
  19. #if USBHOST_MOUSE
  20. #include "USBHost.h"
  21. /**
  22. * A class to communicate a USB mouse
  23. */
  24. class USBHostMouse : public IUSBEnumerator {
  25. public:
  26. /**
  27. * Constructor
  28. */
  29. USBHostMouse();
  30. /**
  31. * Try to connect a mouse device
  32. *
  33. * @return true if connection was successful
  34. */
  35. bool connect();
  36. /**
  37. * Check if a mouse is connected
  38. *
  39. * @returns true if a mouse is connected
  40. */
  41. bool connected();
  42. /**
  43. * Attach a callback called when a mouse event is received
  44. *
  45. * @param ptr function pointer
  46. */
  47. inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) {
  48. if (ptr != NULL) {
  49. onUpdate = ptr;
  50. }
  51. }
  52. /**
  53. * Attach a callback called when the button state changes
  54. *
  55. * @param ptr function pointer
  56. */
  57. inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) {
  58. if (ptr != NULL) {
  59. onButtonUpdate = ptr;
  60. }
  61. }
  62. /**
  63. * Attach a callback called when the X axis value changes
  64. *
  65. * @param ptr function pointer
  66. */
  67. inline void attachXEvent(void (*ptr)(int8_t x)) {
  68. if (ptr != NULL) {
  69. onXUpdate = ptr;
  70. }
  71. }
  72. /**
  73. * Attach a callback called when the Y axis value changes
  74. *
  75. * @param ptr function pointer
  76. */
  77. inline void attachYEvent(void (*ptr)(int8_t y)) {
  78. if (ptr != NULL) {
  79. onYUpdate = ptr;
  80. }
  81. }
  82. /**
  83. * Attach a callback called when the Z axis value changes (scrolling)
  84. *
  85. * @param ptr function pointer
  86. */
  87. inline void attachZEvent(void (*ptr)(int8_t z)) {
  88. if (ptr != NULL) {
  89. onZUpdate = ptr;
  90. }
  91. }
  92. protected:
  93. //From IUSBEnumerator
  94. virtual void setVidPid(uint16_t vid, uint16_t pid);
  95. virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
  96. virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
  97. private:
  98. USBHost * host;
  99. USBDeviceConnected * dev;
  100. USBEndpoint * int_in;
  101. uint8_t report[4];
  102. bool dev_connected;
  103. bool mouse_device_found;
  104. int mouse_intf;
  105. uint8_t buttons;
  106. int8_t x;
  107. int8_t y;
  108. int8_t z;
  109. void rxHandler();
  110. void (*onUpdate)(uint8_t buttons, int8_t x, int8_t y, int8_t z);
  111. void (*onButtonUpdate)(uint8_t buttons);
  112. void (*onXUpdate)(int8_t x);
  113. void (*onYUpdate)(int8_t y);
  114. void (*onZUpdate)(int8_t z);
  115. int report_id;
  116. void init();
  117. };
  118. #endif
  119. #endif