1+ #if 1 // defined(USBCON)
2+
3+ #include " Mouse.h"
4+
5+ const u8 _hidReportDescriptor[] PROGMEM = {
6+
7+ // Mouse
8+ 0x05 , 0x01 , // USAGE_PAGE (Generic Desktop) // 54
9+ 0x09 , 0x02 , // USAGE (Mouse)
10+ 0xa1 , 0x01 , // COLLECTION (Application)
11+ 0x09 , 0x01 , // USAGE (Pointer)
12+ 0xa1 , 0x00 , // COLLECTION (Physical)
13+ 0x85 , 0x01 , // REPORT_ID (1)
14+ 0x05 , 0x09 , // USAGE_PAGE (Button)
15+ 0x19 , 0x01 , // USAGE_MINIMUM (Button 1)
16+ 0x29 , 0x03 , // USAGE_MAXIMUM (Button 3)
17+ 0x15 , 0x00 , // LOGICAL_MINIMUM (0)
18+ 0x25 , 0x01 , // LOGICAL_MAXIMUM (1)
19+ 0x95 , 0x03 , // REPORT_COUNT (3)
20+ 0x75 , 0x01 , // REPORT_SIZE (1)
21+ 0x81 , 0x02 , // INPUT (Data,Var,Abs)
22+ 0x95 , 0x01 , // REPORT_COUNT (1)
23+ 0x75 , 0x05 , // REPORT_SIZE (5)
24+ 0x81 , 0x03 , // INPUT (Cnst,Var,Abs)
25+ 0x05 , 0x01 , // USAGE_PAGE (Generic Desktop)
26+ 0x09 , 0x30 , // USAGE (X)
27+ 0x09 , 0x31 , // USAGE (Y)
28+ 0x09 , 0x38 , // USAGE (Wheel)
29+ 0x15 , 0x81 , // LOGICAL_MINIMUM (-127)
30+ 0x25 , 0x7f , // LOGICAL_MAXIMUM (127)
31+ 0x75 , 0x08 , // REPORT_SIZE (8)
32+ 0x95 , 0x03 , // REPORT_COUNT (3)
33+ 0x81 , 0x06 , // INPUT (Data,Var,Rel)
34+ 0xc0 , // END_COLLECTION
35+ 0xc0 , // END_COLLECTION
36+ };
37+
38+ size_t getsizeof_hidReportDescriptor () {
39+ return sizeof (_hidReportDescriptor);
40+ }
41+
42+ Mouse_ Mouse;
43+
44+ // ================================================================================
45+ // ================================================================================
46+ // Mouse
47+
48+ Mouse_::Mouse_ (void ) : _buttons(0 )
49+ {
50+ }
51+
52+ void Mouse_::begin (void )
53+ {
54+ }
55+
56+ void Mouse_::end (void )
57+ {
58+ }
59+
60+ void Mouse_::click (uint8_t b)
61+ {
62+ _buttons = b;
63+ move (0 ,0 ,0 );
64+ _buttons = 0 ;
65+ move (0 ,0 ,0 );
66+ }
67+
68+ void Mouse_::move (signed char x, signed char y, signed char wheel)
69+ {
70+ u8 m[4 ];
71+ m[0 ] = _buttons;
72+ m[1 ] = x;
73+ m[2 ] = y;
74+ m[3 ] = wheel;
75+ HID_SendReport (1 ,m,4 );
76+ }
77+
78+ void Mouse_::buttons (uint8_t b)
79+ {
80+ if (b != _buttons)
81+ {
82+ _buttons = b;
83+ move (0 ,0 ,0 );
84+ }
85+ }
86+
87+ void Mouse_::press (uint8_t b)
88+ {
89+ buttons (_buttons | b);
90+ }
91+
92+ void Mouse_::release (uint8_t b)
93+ {
94+ buttons (_buttons & ~b);
95+ }
96+
97+ bool Mouse_::isPressed (uint8_t b)
98+ {
99+ if ((b & _buttons) > 0 )
100+ return true ;
101+ return false ;
102+ }
103+
104+ #endif
0 commit comments