Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* USB EHCI Host for Teensy 3.6
  2. * Copyright 2017 Paul Stoffregen (paul@pjrc.com)
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <Arduino.h>
  24. #include "USBHost_t36.h" // Read this header first for key info
  25. hidclaim_t MouseController::claim_collection(USBHIDParser *driver, Device_t *dev, uint32_t topusage)
  26. {
  27. // only claim Desktop/Mouse
  28. if (topusage != 0x10002) return CLAIM_NO;
  29. // only claim from one physical device
  30. if (mydevice != NULL && dev != mydevice) return CLAIM_NO;
  31. mydevice = dev;
  32. collections_claimed++;
  33. return CLAIM_REPORT;
  34. }
  35. void MouseController::disconnect_collection(Device_t *dev)
  36. {
  37. if (--collections_claimed == 0) {
  38. mydevice = NULL;
  39. }
  40. }
  41. void MouseController::hid_input_begin(uint32_t topusage, uint32_t type, int lgmin, int lgmax)
  42. {
  43. // TODO: check if absolute coordinates
  44. hid_input_begin_ = true;
  45. }
  46. void MouseController::hid_input_data(uint32_t usage, int32_t value)
  47. {
  48. //Serial.printf("Mouse: usage=%X, value=%d\n", usage, value);
  49. uint32_t usage_page = usage >> 16;
  50. usage &= 0xFFFF;
  51. if (usage_page == 9 && usage >= 1 && usage <= 8) {
  52. if (value == 0) {
  53. buttons &= ~(1 << (usage -1));
  54. } else {
  55. buttons |= (1 << (usage -1));
  56. }
  57. } else if (usage_page == 1) {
  58. switch (usage) {
  59. case 0x30:
  60. mouseX = value;
  61. break;
  62. case 0x31:
  63. mouseY = value;
  64. break;
  65. case 0x32: // Apple uses this for horizontal scroll
  66. wheelH = value;
  67. break;
  68. case 0x38:
  69. wheel = value;
  70. break;
  71. }
  72. } else if (usage_page == 12) {
  73. if (usage == 0x238) { // Microsoft uses this for horizontal scroll
  74. wheelH = value;
  75. }
  76. }
  77. }
  78. void MouseController::hid_input_end()
  79. {
  80. if (hid_input_begin_) {
  81. mouseEvent = true;
  82. hid_input_begin_ = false;
  83. }
  84. }
  85. void MouseController::mouseDataClear() {
  86. mouseEvent = false;
  87. buttons = 0;
  88. mouseX = 0;
  89. mouseY = 0;
  90. wheel = 0;
  91. wheelH = 0;
  92. }