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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Based on Obdev's AVRUSB code and under the same license.
  3. * Modified by Robin Thoni <robin@rthoni.com>
  4. */
  5. #ifndef __UsbKeyboard_h__
  6. #define __UsbKeyboard_h__
  7. #include <avr/pgmspace.h>
  8. #include <avr/interrupt.h>
  9. #include <string.h>
  10. #include "usbdrv.h"
  11. // TODO: Work around Arduino 12 issues better.
  12. //#include <WConstants.h>
  13. //#undef int()
  14. typedef uint8_t byte;
  15. #define WAIT_USB do { \
  16. UsbMouse.update(); \
  17. if (!usbInterruptIsReady()) \
  18. { \
  19. return; \
  20. } \
  21. } while(0)
  22. #define BUFFER_SIZE 4 // Minimum of 2: 1 for modifiers + 1 for keystroke
  23. typedef struct{
  24. uchar buttonMask;
  25. char dx;
  26. char dy;
  27. char dWheel;
  28. }report_t;
  29. #define MOUSE_BUTTON_LEFT 1
  30. #define MOUSE_BUTTON_RIGHT 2
  31. #define MOUSE_BUTTON_MIDDLE 4
  32. static uchar idleRate;/* repeat rate for keyboards, never used for mice */
  33. class UsbMouseDevice {
  34. public:
  35. UsbMouseDevice();
  36. bool isUsbReady();
  37. void update() {
  38. usbPoll();
  39. }
  40. void move(char dx, char dy);
  41. void moveWheel(char dy);
  42. void pressButton(char button);
  43. void releaseButton(char button);
  44. void setButtonState(char button, bool pressed);
  45. //void clickButton(char button);
  46. void updateStatus();
  47. void resetStatus();
  48. //private: TODO: Make friend?
  49. report_t reportBuffer; // buffer for HID reports [ 1 modifier byte + (len-1) key strokes]
  50. private:
  51. };
  52. #include "UsbMouse.hxx"
  53. #endif // __UsbKeyboard_h__