Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

100 linhas
2.7KB

  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. bool MouseController::claim_collection(Device_t *dev, uint32_t topusage)
  26. {
  27. // only claim Desktop/Mouse
  28. if (topusage != 0x10002) return false;
  29. // only claim from one physical device
  30. if (mydevice != NULL && dev != mydevice) return false;
  31. mydevice = dev;
  32. collections_claimed++;
  33. return true;
  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. }
  45. void MouseController::hid_input_data(uint32_t usage, int32_t value)
  46. {
  47. //Serial.printf("Mouse: usage=%X, value=%d\n", usage, value);
  48. uint32_t usage_page = usage >> 16;
  49. usage &= 0xFFFF;
  50. if (usage_page == 9 && usage >= 1 && usage <= 8) {
  51. if (value == 0) {
  52. buttons &= ~(1 << (usage -1));
  53. } else {
  54. buttons |= (1 << (usage -1));
  55. }
  56. } else if (usage_page == 1) {
  57. switch (usage) {
  58. case 0x30:
  59. mouseX = value;
  60. break;
  61. case 0x31:
  62. mouseY = value;
  63. break;
  64. case 0x32: // Apple uses this for horizontal scroll
  65. wheelH = value;
  66. break;
  67. case 0x38:
  68. wheel = value;
  69. break;
  70. }
  71. } else if (usage_page == 12) {
  72. if (usage == 0x238) { // Microsoft uses this for horizontal scroll
  73. wheelH = value;
  74. }
  75. }
  76. }
  77. void MouseController::hid_input_end()
  78. {
  79. mouseEvent = true;
  80. }
  81. void MouseController::mouseDataClear() {
  82. mouseEvent = false;
  83. buttons = 0;
  84. mouseX = 0;
  85. mouseY = 0;
  86. wheel = 0;
  87. wheelH = 0;
  88. }