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.

digitizer.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. void DigitizerController::init()
  26. {
  27. USBHIDParser::driver_ready_for_hid_collection(this);
  28. }
  29. hidclaim_t DigitizerController::claim_collection(USBHIDParser *driver, Device_t *dev, uint32_t topusage)
  30. {
  31. // only claim Desktop/Mouse
  32. if (topusage != 0xff0d0001) return CLAIM_NO;
  33. // only claim from one physical device
  34. if (mydevice != NULL && dev != mydevice) return CLAIM_NO;
  35. mydevice = dev;
  36. collections_claimed++;
  37. return CLAIM_REPORT;
  38. }
  39. void DigitizerController::disconnect_collection(Device_t *dev)
  40. {
  41. if (--collections_claimed == 0) {
  42. mydevice = NULL;
  43. }
  44. }
  45. void DigitizerController::hid_input_begin(uint32_t topusage, uint32_t type, int lgmin, int lgmax)
  46. {
  47. // TODO: check if absolute coordinates
  48. hid_input_begin_ = true;
  49. }
  50. void DigitizerController::hid_input_data(uint32_t usage, int32_t value)
  51. {
  52. USBHDBGSerial.printf("Digitizer: usage=%X, value=%d\n", usage, value);
  53. uint32_t usage_page = usage >> 16;
  54. usage &= 0xFFFF;
  55. USBHDBGSerial.printf("Digitizer: &usage=%X, usage_page=%x\n", usage, usage_page);
  56. // This is Mikes version...
  57. if (usage_page == 0xff00 && usage >= 100 && usage <= 0x108) {
  58. switch (usage) {
  59. case 0x102:
  60. mouseX = value;
  61. break;
  62. case 0x103:
  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. digiAxes[usage & 0xf] = value;
  73. }
  74. if (usage_page == 0xff0D) {
  75. if (usage >= 0 && usage < 0x138) { //at least to start
  76. switch (usage) {
  77. case 0x130:
  78. mouseX = value;
  79. break;
  80. case 0x131:
  81. mouseY = value;
  82. break;
  83. case 0x132: // Apple uses this for horizontal scroll
  84. wheelH = value;
  85. break;
  86. case 0x138:
  87. wheel = value;
  88. break;
  89. case 0x30: digiAxes[0] = value; break;
  90. case 0x32: digiAxes[1] = value; break;
  91. case 0x36: digiAxes[2] = value; break;
  92. case 0x42: digiAxes[3] = value; break;
  93. case 0x44: digiAxes[4] = value; break;
  94. case 0x5A: digiAxes[5] = value; break;
  95. case 0x5B: digiAxes[6] = value; break;
  96. case 0x5C: digiAxes[7] = value; break;
  97. case 0x77: digiAxes[8] = value; break;
  98. }
  99. //digiAxes[usage & 0xf] = value;
  100. } else if (usage >= 0x910 && usage <= 0x91f) {
  101. if (value == 0) {
  102. buttons &= ~(1 << (usage - 0x910));
  103. } else {
  104. buttons |= (1 << (usage - 0x910));
  105. }
  106. }
  107. }
  108. }
  109. void DigitizerController::hid_input_end()
  110. {
  111. if (hid_input_begin_) {
  112. digitizerEvent = true;
  113. hid_input_begin_ = false;
  114. }
  115. }
  116. void DigitizerController::digitizerDataClear() {
  117. digitizerEvent = false;
  118. buttons = 0;
  119. mouseX = 0;
  120. mouseY = 0;
  121. wheel = 0;
  122. wheelH = 0;
  123. }