Skip to content

Commit 158d655

Browse files
committed
fix digimouse
1 parent de2937f commit 158d655

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

hardware/digistump/avr/libraries/DigiMouse/DigiMouse.h

+49-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ static uchar rt_usbHidReportDescriptorSize = 0;
3131
static const uchar *rt_usbDeviceDescriptor = NULL;
3232
static uchar rt_usbDeviceDescriptorSize = 0;
3333

34+
#define MOUSEBTN_LEFT_MASK 0x01
35+
#define MOUSEBTN_RIGHT_MASK 0x02
36+
#define MOUSEBTN_MIDDLE_MASK 0x04
37+
3438
// TODO: Work around Arduino 12 issues better.
3539
//#include <WConstants.h>
3640
//#undef int()
@@ -53,6 +57,7 @@ static unsigned char idle_rate = DIGIMOUSE_DEFAULT_REPORT_INTERVAL / 4; // in un
5357
static unsigned long last_report_time = 0;
5458

5559

60+
char usb_hasCommed = 0;
5661

5762
const PROGMEM unsigned char mouse_usbHidReportDescriptor[] = { /* USB report descriptor */
5863
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
@@ -89,7 +94,7 @@ const PROGMEM unsigned char mouse_usbHidReportDescriptor[] = { /* USB report des
8994

9095
#define USBDESCR_DEVICE 1
9196

92-
unsigned const char usbDescrDevice[] PROGMEM = { /* USB device descriptor */
97+
const unsigned char usbDescrDevice[] PROGMEM = { /* USB device descriptor */
9398
18, /* sizeof(usbDescrDevice): length of descriptor in bytes */
9499
USBDESCR_DEVICE, /* descriptor type */
95100
0x01, 0x01, /* USB version supported */
@@ -145,16 +150,18 @@ void clearMove() {
145150
class DigiMouseDevice {
146151
public:
147152
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-
154153

155-
156-
//TIMSK &= !(1<TOIE0);//interrupt off
154+
}
155+
156+
char isConnected()
157+
{
158+
return usb_hasCommed;
159+
}
160+
161+
void begin(){
162+
157163
cli();
164+
PORTB &= ~(_BV(USB_CFG_DMINUS_BIT) | _BV(USB_CFG_DPLUS_BIT));
158165
usbDeviceDisconnect();
159166
_delay_ms(250);
160167
usbDeviceConnect();
@@ -170,6 +177,16 @@ class DigiMouseDevice {
170177
sei();
171178
last_report_time = millis();
172179
}
180+
181+
182+
void refresh() {
183+
update();
184+
}
185+
186+
void poll() {
187+
update();
188+
}
189+
173190

174191
void update() {
175192
usbPoll();
@@ -231,6 +248,28 @@ class DigiMouseDevice {
231248
last_built_report[2] = *(reinterpret_cast<unsigned char *>(&deltaY));
232249
last_built_report[3] = *(reinterpret_cast<unsigned char *>(&deltaS));
233250
}
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+
}
234273

235274
void setButtons(unsigned char buttons) {
236275
last_built_report[0] = buttons;
@@ -254,6 +293,7 @@ extern "C"{
254293
// USB_PUBLIC uchar usbFunctionSetup
255294

256295
uchar usbFunctionSetup(uchar data[8]) {
296+
usb_hasCommed = 1;
257297
usbRequest_t *rq = (usbRequest_t *)data;
258298

259299
usbMsgPtr = reportBuffer;

0 commit comments

Comments
 (0)