0xA1, 0x01, // Collection (Application) | 0xA1, 0x01, // Collection (Application) | ||||
0x05, 0x09, // Usage Page (Button) | 0x05, 0x09, // Usage Page (Button) | ||||
0x19, 0x01, // Usage Minimum (Button #1) | 0x19, 0x01, // Usage Minimum (Button #1) | ||||
0x29, 0x03, // Usage Maximum (Button #3) | |||||
0x29, 0x08, // Usage Maximum (Button #8) | |||||
0x15, 0x00, // Logical Minimum (0) | 0x15, 0x00, // Logical Minimum (0) | ||||
0x25, 0x01, // Logical Maximum (1) | 0x25, 0x01, // Logical Maximum (1) | ||||
0x95, 0x03, // Report Count (3) | |||||
0x95, 0x08, // Report Count (8) | |||||
0x75, 0x01, // Report Size (1) | 0x75, 0x01, // Report Size (1) | ||||
0x81, 0x02, // Input (Data, Variable, Absolute) | 0x81, 0x02, // Input (Data, Variable, Absolute) | ||||
0x95, 0x01, // Report Count (1) | |||||
0x75, 0x05, // Report Size (5) | |||||
0x81, 0x03, // Input (Constant) | |||||
0x05, 0x01, // Usage Page (Generic Desktop) | 0x05, 0x01, // Usage Page (Generic Desktop) | ||||
0x09, 0x30, // Usage (X) | 0x09, 0x30, // Usage (X) | ||||
0x09, 0x31, // Usage (Y) | 0x09, 0x31, // Usage (Y) | ||||
0x09, 0x38, // Usage (Wheel) | |||||
0x15, 0x81, // Logical Minimum (-127) | 0x15, 0x81, // Logical Minimum (-127) | ||||
0x25, 0x7F, // Logical Maximum (127) | 0x25, 0x7F, // Logical Maximum (127) | ||||
0x75, 0x08, // Report Size (8), | 0x75, 0x08, // Report Size (8), | ||||
0x95, 0x02, // Report Count (2), | |||||
0x95, 0x03, // Report Count (3), | |||||
0x81, 0x06, // Input (Data, Variable, Relative) | 0x81, 0x06, // Input (Data, Variable, Relative) | ||||
0x09, 0x38, // Usage (Wheel) | |||||
0x05, 0x0C, // Usage Page (Consumer) | |||||
0x0A, 0x38, 0x02, // Usage (AC Pan) | |||||
0x15, 0x81, // Logical Minimum (-127) | |||||
0x25, 0x7F, // Logical Maximum (127) | |||||
0x75, 0x08, // Report Size (8), | |||||
0x95, 0x01, // Report Count (1), | 0x95, 0x01, // Report Count (1), | ||||
0x81, 0x06, // Input (Data, Variable, Relative) | 0x81, 0x06, // Input (Data, Variable, Relative) | ||||
0xC0 // End Collection | 0xC0 // End Collection | ||||
UEDATX = 0; | UEDATX = 0; | ||||
UEDATX = 0; | UEDATX = 0; | ||||
UEDATX = 0; | UEDATX = 0; | ||||
UEDATX = 0; | |||||
usb_send_in(); | usb_send_in(); | ||||
return; | return; | ||||
} | } |
void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel) | |||||
void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel, int8_t horiz) | |||||
{ | { | ||||
uint8_t intr_state, timeout; | uint8_t intr_state, timeout; | ||||
if (x == -128) x = -127; | if (x == -128) x = -127; | ||||
if (y == -128) y = -127; | if (y == -128) y = -127; | ||||
if (wheel == -128) wheel = -127; | if (wheel == -128) wheel = -127; | ||||
if (horiz == -128) horiz = -127; | |||||
intr_state = SREG; | intr_state = SREG; | ||||
cli(); | cli(); | ||||
UENUM = MOUSE_ENDPOINT; | UENUM = MOUSE_ENDPOINT; | ||||
UEDATX = x; | UEDATX = x; | ||||
UEDATX = y; | UEDATX = y; | ||||
UEDATX = wheel; | UEDATX = wheel; | ||||
UEDATX = horiz; | |||||
UEINTX = 0x3A; | UEINTX = 0x3A; | ||||
SREG = intr_state; | SREG = intr_state; | ||||
} | } | ||||
void usb_mouse_class::click(uint8_t b) | void usb_mouse_class::click(uint8_t b) | ||||
{ | { | ||||
mouse_buttons = (b & 7); | |||||
mouse_buttons = b; | |||||
move(0, 0); | move(0, 0); | ||||
mouse_buttons = 0; | mouse_buttons = 0; | ||||
move(0, 0); | move(0, 0); | ||||
} | } | ||||
void usb_mouse_class::scroll(int8_t wheel) | |||||
void usb_mouse_class::scroll(int8_t wheel, int8_t horiz) | |||||
{ | { | ||||
move(0, 0, wheel); | |||||
move(0, 0, wheel, horiz); | |||||
} | } | ||||
void usb_mouse_class::set_buttons(uint8_t left, uint8_t middle, uint8_t right) | |||||
void usb_mouse_class::set_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward) | |||||
{ | { | ||||
uint8_t mask=0; | uint8_t mask=0; | ||||
if (left) mask |= 1; | if (left) mask |= 1; | ||||
if (middle) mask |= 4; | if (middle) mask |= 4; | ||||
if (right) mask |= 2; | if (right) mask |= 2; | ||||
if (back) mask |= 8; | |||||
if (forward) mask |= 16; | |||||
mouse_buttons = mask; | mouse_buttons = mask; | ||||
move(0, 0); | move(0, 0); | ||||
} | } |
#define MOUSE_LEFT 1 | #define MOUSE_LEFT 1 | ||||
#define MOUSE_MIDDLE 4 | #define MOUSE_MIDDLE 4 | ||||
#define MOUSE_RIGHT 2 | #define MOUSE_RIGHT 2 | ||||
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) | |||||
#define MOUSE_BACK 8 | |||||
#define MOUSE_FORWARD 16 | |||||
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_BACK | MOUSE_FORWARD) | |||||
class usb_mouse_class | class usb_mouse_class | ||||
{ | { | ||||
public: | public: | ||||
void begin(void) { } | void begin(void) { } | ||||
void end(void) { } | void end(void) { } | ||||
void move(int8_t x, int8_t y, int8_t wheel=0); | |||||
void move(int8_t x, int8_t y, int8_t wheel=0, int8_t horiz=0); | |||||
void click(uint8_t b = MOUSE_LEFT); | void click(uint8_t b = MOUSE_LEFT); | ||||
void scroll(int8_t wheel); | |||||
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0); | |||||
void scroll(int8_t wheel, int8_t horiz=0); | |||||
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0); | |||||
void press(uint8_t b = MOUSE_LEFT); | void press(uint8_t b = MOUSE_LEFT); | ||||
void release(uint8_t b = MOUSE_LEFT); | void release(uint8_t b = MOUSE_LEFT); | ||||
bool isPressed(uint8_t b = MOUSE_ALL); | bool isPressed(uint8_t b = MOUSE_ALL); |
0xA1, 0x01, // Collection (Application) | 0xA1, 0x01, // Collection (Application) | ||||
0x05, 0x09, // Usage Page (Button) | 0x05, 0x09, // Usage Page (Button) | ||||
0x19, 0x01, // Usage Minimum (Button #1) | 0x19, 0x01, // Usage Minimum (Button #1) | ||||
0x29, 0x03, // Usage Maximum (Button #3) | |||||
0x29, 0x08, // Usage Maximum (Button #8) | |||||
0x15, 0x00, // Logical Minimum (0) | 0x15, 0x00, // Logical Minimum (0) | ||||
0x25, 0x01, // Logical Maximum (1) | 0x25, 0x01, // Logical Maximum (1) | ||||
0x95, 0x03, // Report Count (3) | |||||
0x95, 0x08, // Report Count (8) | |||||
0x75, 0x01, // Report Size (1) | 0x75, 0x01, // Report Size (1) | ||||
0x81, 0x02, // Input (Data, Variable, Absolute) | 0x81, 0x02, // Input (Data, Variable, Absolute) | ||||
0x95, 0x01, // Report Count (1) | |||||
0x75, 0x05, // Report Size (5) | |||||
0x81, 0x03, // Input (Constant) | |||||
0x05, 0x01, // Usage Page (Generic Desktop) | 0x05, 0x01, // Usage Page (Generic Desktop) | ||||
0x09, 0x30, // Usage (X) | 0x09, 0x30, // Usage (X) | ||||
0x09, 0x31, // Usage (Y) | 0x09, 0x31, // Usage (Y) | ||||
0x09, 0x38, // Usage (Wheel) | |||||
0x15, 0x81, // Logical Minimum (-127) | 0x15, 0x81, // Logical Minimum (-127) | ||||
0x25, 0x7F, // Logical Maximum (127) | 0x25, 0x7F, // Logical Maximum (127) | ||||
0x75, 0x08, // Report Size (8), | 0x75, 0x08, // Report Size (8), | ||||
0x95, 0x02, // Report Count (2), | |||||
0x95, 0x03, // Report Count (3), | |||||
0x81, 0x06, // Input (Data, Variable, Relative) | 0x81, 0x06, // Input (Data, Variable, Relative) | ||||
0x09, 0x38, // Usage (Wheel) | |||||
0x05, 0x0C, // Usage Page (Consumer) | |||||
0x0A, 0x38, 0x02, // Usage (AC Pan) | |||||
0x15, 0x81, // Logical Minimum (-127) | |||||
0x25, 0x7F, // Logical Maximum (127) | |||||
0x75, 0x08, // Report Size (8), | |||||
0x95, 0x01, // Report Count (1), | 0x95, 0x01, // Report Count (1), | ||||
0x81, 0x06, // Input (Data, Variable, Relative) | 0x81, 0x06, // Input (Data, Variable, Relative) | ||||
0xC0 // End Collection | 0xC0 // End Collection | ||||
UEDATX = 0; | UEDATX = 0; | ||||
UEDATX = 0; | UEDATX = 0; | ||||
UEDATX = 0; | UEDATX = 0; | ||||
UEDATX = 0; | |||||
usb_send_in(); | usb_send_in(); | ||||
return; | return; | ||||
} | } |
void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel) | |||||
void usb_mouse_class::move(int8_t x, int8_t y, int8_t wheel, int8_t horiz) | |||||
{ | { | ||||
uint8_t intr_state, timeout; | uint8_t intr_state, timeout; | ||||
if (x == -128) x = -127; | if (x == -128) x = -127; | ||||
if (y == -128) y = -127; | if (y == -128) y = -127; | ||||
if (wheel == -128) wheel = -127; | if (wheel == -128) wheel = -127; | ||||
if (horiz == -128) horiz = -127; | |||||
intr_state = SREG; | intr_state = SREG; | ||||
cli(); | cli(); | ||||
UENUM = MOUSE_ENDPOINT; | UENUM = MOUSE_ENDPOINT; | ||||
UEDATX = x; | UEDATX = x; | ||||
UEDATX = y; | UEDATX = y; | ||||
UEDATX = wheel; | UEDATX = wheel; | ||||
UEDATX = horiz; | |||||
UEINTX = 0x3A; | UEINTX = 0x3A; | ||||
SREG = intr_state; | SREG = intr_state; | ||||
} | } | ||||
void usb_mouse_class::click(uint8_t b) | void usb_mouse_class::click(uint8_t b) | ||||
{ | { | ||||
mouse_buttons = (b & 7); | |||||
mouse_buttons = b; | |||||
move(0, 0); | move(0, 0); | ||||
mouse_buttons = 0; | mouse_buttons = 0; | ||||
move(0, 0); | move(0, 0); | ||||
} | } | ||||
void usb_mouse_class::scroll(int8_t wheel) | |||||
void usb_mouse_class::scroll(int8_t wheel, int8_t horiz) | |||||
{ | { | ||||
move(0, 0, wheel); | |||||
move(0, 0, wheel, horiz); | |||||
} | } | ||||
void usb_mouse_class::set_buttons(uint8_t left, uint8_t middle, uint8_t right) | |||||
void usb_mouse_class::set_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward) | |||||
{ | { | ||||
uint8_t mask=0; | uint8_t mask=0; | ||||
if (left) mask |= 1; | if (left) mask |= 1; | ||||
if (middle) mask |= 4; | if (middle) mask |= 4; | ||||
if (right) mask |= 2; | if (right) mask |= 2; | ||||
if (back) mask |= 8; | |||||
if (forward) mask |= 16; | |||||
mouse_buttons = mask; | mouse_buttons = mask; | ||||
move(0, 0); | move(0, 0); | ||||
} | } |
#define MOUSE_LEFT 1 | #define MOUSE_LEFT 1 | ||||
#define MOUSE_MIDDLE 4 | #define MOUSE_MIDDLE 4 | ||||
#define MOUSE_RIGHT 2 | #define MOUSE_RIGHT 2 | ||||
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) | |||||
#define MOUSE_BACK 8 | |||||
#define MOUSE_FORWARD 16 | |||||
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_BACK | MOUSE_FORWARD) | |||||
class usb_mouse_class | class usb_mouse_class | ||||
{ | { | ||||
public: | public: | ||||
void begin(void) { } | void begin(void) { } | ||||
void end(void) { } | void end(void) { } | ||||
void move(int8_t x, int8_t y, int8_t wheel=0); | |||||
void move(int8_t x, int8_t y, int8_t wheel=0, int8_t horiz=0); | |||||
void click(uint8_t b = MOUSE_LEFT); | void click(uint8_t b = MOUSE_LEFT); | ||||
void scroll(int8_t wheel); | |||||
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0); | |||||
void scroll(int8_t wheel, int8_t horiz=0); | |||||
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0); | |||||
void press(uint8_t b = MOUSE_LEFT); | void press(uint8_t b = MOUSE_LEFT); | ||||
void release(uint8_t b = MOUSE_LEFT); | void release(uint8_t b = MOUSE_LEFT); | ||||
bool isPressed(uint8_t b = MOUSE_ALL); | bool isPressed(uint8_t b = MOUSE_ALL); |