Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 1 of 1

Thread: usb_mouse_move 16 bit x and y request

  1. #1

    usb_mouse_move 16 bit x and y request

    I have a bit of a strange request.

    Maybe someone saw in my last thread that I wanted to implement an adjustable polling rate for the mouse. To do a double blind test.
    I never really intended to add this feature but since the first comment was immediatly about that it is not perceivable and all, I kind of want to add it now.

    The problem I was running into is that at lower polling rates the 8 bit x and y value start to overflow of the int usb_mouse_move(int16_t x, int16_t y, int8_t wheel, int8_t horiz) function in the cores/teensy4/usb_mouse.c file.
    At higher polling rates this is not a problem since 8 values of 64 do not go over the limit of 128 but one value of 512 obviously does.
    This already started to become a problem at a 1000Hz if I move the mouse very quickly it would spin out and malfunction at 125Hz I can only move it really slow.

    So I implemented the function to support 16 bit values by changing the HID mouse descriptor and the functions.
    Now everything works fine for me but I was wondering if this change could be added in the next update of teensyduino. ​
    It still works properly with 8 bit values, well with the exception of my very specific issue.
    So I dont think there are incompatibility issues with older code.

    Parts of the code that I changed full code is also attached in the .zip:

    usb_mouse.h
    int usb_mouse_move(int16_t x, int16_t y, int8_t wheel, int8_t horiz);

    usb_mouse.c
    // Move the mouse. x, y and wheel are -32767 to 32767. Use 0 for no movement.
    int usb_mouse_move(int16_t x, int16_t y, int8_t wheel, int8_t horiz)
    {
    //printf("move\n");
    if (x == -32768) x = -32767;
    if (y == -32768) y = -32767;
    if (wheel == -128) wheel = -127;
    if (horiz == -128) horiz = -127;

    int8_t buffer[8];
    buffer[0] = 1;
    buffer[1] = usb_mouse_buttons_state;
    buffer[2] = x;
    buffer[3] = (x >> 8);
    buffer[4] = y;
    buffer[5] = (y >> 8);
    buffer[6] = wheel;
    buffer[7] = horiz;
    return usb_mouse_transmit(buffer, 8);
    }

    usb_desc.c

    #ifdef MOUSE_INTERFACE
    // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
    static uint8_t mouse_report_desc[] = {
    0x05, 0x01, // Usage Page (Generic Desktop)
    0x09, 0x02, // Usage (Mouse)
    0xA1, 0x01, // Collection (Application)
    0x85, 0x01, // REPORT_ID (1)
    0x05, 0x09, // Usage Page (Button)
    0x19, 0x01, // Usage Minimum (Button #1)
    0x29, 0x08, // Usage Maximum (Button #8)
    0x15, 0x00, // Logical Minimum (0)
    0x25, 0x01, // Logical Maximum (1)
    0x95, 0x08, // Report Count (8)
    0x75, 0x01, // Report Size (1)
    0x81, 0x02, // Input (Data, Variable, Absolute)
    0x05, 0x01, // Usage Page (Generic Desktop)
    0x09, 0x30, // Usage (X)
    0x09, 0x31, // Usage (Y)
    0x16, 0x01, 0x80, // Logical Minimum (-32767)
    0x26, 0xFF, 0x7F, // Logical Maximum (32767)
    0x75, 0x10, // Report Size (16),
    0x95, 0x02, // Report Count (2),
    0x81, 0x06, // Input (Data, Variable, Relative)
    0x05, 0x01, // Usage Page (Generic Desktop)
    0x09, 0x38, // Usage (Wheel)
    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)
    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)
    0xA1, 0x01, // Collection (Application)
    0x85, 0x02, // REPORT_ID (2)
    0x05, 0x01, // Usage Page (Generic Desktop)
    0x09, 0x30, // Usage (X)
    0x09, 0x31, // Usage (Y)
    0x15, 0x00, // Logical Minimum (0)
    0x26, 0xFF, 0x7F, // Logical Maximum (32767)
    0x75, 0x10, // Report Size (16),
    0x95, 0x02, // Report Count (2),
    0x81, 0x02, // Input (Data, Variable, Absolute)
    0xC0 // End Collection
    };
    #endif
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •