PaulStoffregen il y a 8 ans
Parent
révision
8b85a32552
3 fichiers modifiés avec 22 ajouts et 11 suppressions
  1. +8
    -1
      teensy3/usb_desc.c
  2. +5
    -3
      teensy3/usb_mouse.c
  3. +9
    -7
      teensy3/usb_mouse.h

+ 8
- 1
teensy3/usb_desc.c Voir le fichier

@@ -68,7 +68,7 @@
static uint8_t device_descriptor[] = {
18, // bLength
1, // bDescriptorType
0x00, 0x02, // bcdUSB
0x01, 0x01, // bcdUSB
#ifdef DEVICE_CLASS
DEVICE_CLASS, // bDeviceClass
#else
@@ -193,6 +193,13 @@ static uint8_t mouse_report_desc[] = {
0x75, 0x08, // Report Size (8),
0x95, 0x03, // Report Count (3),
0x81, 0x06, // Input (Data, Variable, Relative)
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),
0x81, 0x06, // Input (Data, Variable, Relative)
0xC0, // End Collection
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x02, // Usage (Mouse)

+ 5
- 3
teensy3/usb_mouse.c Voir le fichier

@@ -105,7 +105,7 @@ int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back,
if (back) mask |= 8;
if (forward) mask |= 16;
usb_mouse_buttons_state = mask;
return usb_mouse_move(0, 0, 0);
return usb_mouse_move(0, 0, 0, 0);
}


@@ -139,7 +139,7 @@ static uint8_t transmit_previous_timeout=0;


// Move the mouse. x, y and wheel are -127 to 127. Use 0 for no movement.
int usb_mouse_move(int8_t x, int8_t y, int8_t wheel)
int usb_mouse_move(int8_t x, int8_t y, int8_t wheel, int8_t horiz)
{
uint32_t wait_count=0;
usb_packet_t *tx_packet;
@@ -149,6 +149,7 @@ int usb_mouse_move(int8_t x, int8_t y, int8_t wheel)
if (x == -128) x = -127;
if (y == -128) y = -127;
if (wheel == -128) wheel = -127;
if (horiz == -128) horiz = -127;

while (1) {
if (!usb_configuration) {
@@ -170,7 +171,8 @@ int usb_mouse_move(int8_t x, int8_t y, int8_t wheel)
*(tx_packet->buf + 2) = x;
*(tx_packet->buf + 3) = y;
*(tx_packet->buf + 4) = wheel;
tx_packet->len = 5;
*(tx_packet->buf + 5) = horiz; // horizontal scroll
tx_packet->len = 6;
usb_tx(MOUSE_ENDPOINT, tx_packet);
return 0;
}

+ 9
- 7
teensy3/usb_mouse.h Voir le fichier

@@ -42,7 +42,7 @@
extern "C" {
#endif
int usb_mouse_buttons(uint8_t left, uint8_t middle, uint8_t right, uint8_t back, uint8_t forward);
int usb_mouse_move(int8_t x, int8_t y, int8_t wheel);
int usb_mouse_move(int8_t x, int8_t y, int8_t wheel, int8_t horiz);
int usb_mouse_position(uint16_t x, uint16_t y);
void usb_mouse_screen_size(uint16_t width, uint16_t height, uint8_t mac);
extern uint8_t usb_mouse_buttons_state;
@@ -65,18 +65,20 @@ class usb_mouse_class
public:
void begin(void) { }
void end(void) { }
void move(int8_t x, int8_t y, int8_t wheel=0) { usb_mouse_move(x, y, wheel); }
void move(int8_t x, int8_t y, int8_t wheel=0, int8_t horiz=0) {
usb_mouse_move(x, y, wheel, horiz);
}
void moveTo(uint16_t x, uint16_t y) { usb_mouse_position(x, y); }
void screenSize(uint16_t width, uint16_t height, bool isMacintosh = false) {
usb_mouse_screen_size(width, height, isMacintosh ? 1 : 0);
}
void click(uint8_t b = MOUSE_LEFT) {
usb_mouse_buttons_state = b;
usb_mouse_move(0, 0, 0);
usb_mouse_move(0, 0, 0, 0);
usb_mouse_buttons_state = 0;
usb_mouse_move(0, 0, 0);
usb_mouse_move(0, 0, 0, 0);
}
void scroll(int8_t wheel) { usb_mouse_move(0, 0, wheel); }
void scroll(int8_t wheel, int8_t horiz=0) { usb_mouse_move(0, 0, wheel, horiz); }
void set_buttons(uint8_t left, uint8_t middle=0, uint8_t right=0, uint8_t back=0, uint8_t forward=0) {
usb_mouse_buttons(left, middle, right, back, forward);
}
@@ -84,14 +86,14 @@ class usb_mouse_class
uint8_t buttons = usb_mouse_buttons_state | (b & MOUSE_ALL);
if (buttons != usb_mouse_buttons_state) {
usb_mouse_buttons_state = buttons;
usb_mouse_move(0, 0, 0);
usb_mouse_move(0, 0, 0, 0);
}
}
void release(uint8_t b = MOUSE_LEFT) {
uint8_t buttons = usb_mouse_buttons_state & ~(b & MOUSE_ALL);
if (buttons != usb_mouse_buttons_state) {
usb_mouse_buttons_state = buttons;
usb_mouse_move(0, 0, 0);
usb_mouse_move(0, 0, 0, 0);
}
}
bool isPressed(uint8_t b = MOUSE_ALL) {

Chargement…
Annuler
Enregistrer