@@ -31,6 +31,10 @@ static uchar rt_usbHidReportDescriptorSize = 0;
31
31
static const uchar *rt_usbDeviceDescriptor = NULL ;
32
32
static uchar rt_usbDeviceDescriptorSize = 0 ;
33
33
34
+ #define MOUSEBTN_LEFT_MASK 0x01
35
+ #define MOUSEBTN_RIGHT_MASK 0x02
36
+ #define MOUSEBTN_MIDDLE_MASK 0x04
37
+
34
38
// TODO: Work around Arduino 12 issues better.
35
39
// #include <WConstants.h>
36
40
// #undef int()
@@ -53,6 +57,7 @@ static unsigned char idle_rate = DIGIMOUSE_DEFAULT_REPORT_INTERVAL / 4; // in un
53
57
static unsigned long last_report_time = 0 ;
54
58
55
59
60
+ char usb_hasCommed = 0 ;
56
61
57
62
const PROGMEM unsigned char mouse_usbHidReportDescriptor[] = { /* USB report descriptor */
58
63
0x05 , 0x01 , // USAGE_PAGE (Generic Desktop)
@@ -89,7 +94,7 @@ const PROGMEM unsigned char mouse_usbHidReportDescriptor[] = { /* USB report des
89
94
90
95
#define USBDESCR_DEVICE 1
91
96
92
- unsigned const char usbDescrDevice[] PROGMEM = { /* USB device descriptor */
97
+ const unsigned char usbDescrDevice[] PROGMEM = { /* USB device descriptor */
93
98
18 , /* sizeof(usbDescrDevice): length of descriptor in bytes */
94
99
USBDESCR_DEVICE, /* descriptor type */
95
100
0x01 , 0x01 , /* USB version supported */
@@ -145,16 +150,18 @@ void clearMove() {
145
150
class DigiMouseDevice {
146
151
public:
147
152
DigiMouseDevice () {
148
- // this timer stuff doesn't even make sense - it seems like someone got some code for Timer1
149
- // and haphazardly changed the 1's in the register names to 0's, but the two timers don't work
150
- // the same way, so this code doesn't do what it says at all. Is it even useful to have?
151
- /* configure timer 0 for a rate of 16M5/(1024 * 256) = 62.94 Hz (~16ms) */
152
- // TCCR0A = 5; /* timer 0 prescaler: 1024 */
153
-
154
153
155
-
156
- // TIMSK &= !(1<TOIE0);//interrupt off
154
+ }
155
+
156
+ char isConnected ()
157
+ {
158
+ return usb_hasCommed;
159
+ }
160
+
161
+ void begin (){
162
+
157
163
cli ();
164
+ PORTB &= ~(_BV (USB_CFG_DMINUS_BIT) | _BV (USB_CFG_DPLUS_BIT));
158
165
usbDeviceDisconnect ();
159
166
_delay_ms (250 );
160
167
usbDeviceConnect ();
@@ -170,6 +177,16 @@ class DigiMouseDevice {
170
177
sei ();
171
178
last_report_time = millis ();
172
179
}
180
+
181
+
182
+ void refresh () {
183
+ update ();
184
+ }
185
+
186
+ void poll () {
187
+ update ();
188
+ }
189
+
173
190
174
191
void update () {
175
192
usbPoll ();
@@ -231,6 +248,28 @@ class DigiMouseDevice {
231
248
last_built_report[2 ] = *(reinterpret_cast <unsigned char *>(&deltaY));
232
249
last_built_report[3 ] = *(reinterpret_cast <unsigned char *>(&deltaS));
233
250
}
251
+
252
+ void move (char deltaX, char deltaY, char deltaS, char buttons) {
253
+ if (deltaX == -128 ) deltaX = -127 ;
254
+ if (deltaY == -128 ) deltaY = -127 ;
255
+ if (deltaS == -128 ) deltaS = -127 ;
256
+ last_built_report[0 ] = buttons;
257
+ last_built_report[1 ] = *(reinterpret_cast <unsigned char *>(&deltaX));
258
+ last_built_report[2 ] = *(reinterpret_cast <unsigned char *>(&deltaY));
259
+ last_built_report[3 ] = *(reinterpret_cast <unsigned char *>(&deltaS));
260
+ }
261
+
262
+ void rightClick (){
263
+ last_built_report[0 ] = MOUSEBTN_RIGHT_MASK;
264
+ }
265
+
266
+ void leftClick (){
267
+ last_built_report[0 ] = MOUSEBTN_RIGHT_MASK;
268
+ }
269
+
270
+ void middleClick (){
271
+ last_built_report[0 ] = MOUSEBTN_RIGHT_MASK;
272
+ }
234
273
235
274
void setButtons (unsigned char buttons) {
236
275
last_built_report[0 ] = buttons;
@@ -254,6 +293,7 @@ extern "C"{
254
293
// USB_PUBLIC uchar usbFunctionSetup
255
294
256
295
uchar usbFunctionSetup (uchar data[8 ]) {
296
+ usb_hasCommed = 1 ;
257
297
usbRequest_t *rq = (usbRequest_t *)data;
258
298
259
299
usbMsgPtr = reportBuffer;
0 commit comments