2

I am building an application on raspberry pi pico. A USB mouse is connected to the pico, and then the pico is connected to the PC. The pico logs the mouse's button presses and mouse's movements and sends the HID report over to the PC - where it is viewed from the serial terminal. I am using Arduino and its Raspberry Pi core to program the pi.

The problem is that the mouse's scroll wheel is not logged. All the other buttons - including the middle button are logged correctly. The mouse movement is properly logged HOWEVER, when the mouse moves (in any direction), it also incorrecly logs it as scroll wheel movement.

These are mouse button presses:

Mouse: B:0x0 X:-57 Y:3 W:1 [0x0 0xC7 0x3 *0x1 0x2 0x0 0x0 0x0]
Mouse: B:0x4 X:-57 Y:3 W:1 [0x4 0xC7 0x3 *0x1 0x2 0x0 0x0 0x0]
Mouse: B:0x0 X:-57 Y:3 W:1 [0x0 0xC7 0x3 *0x1 0x2 0x0 0x0 0x0]
Mouse: B:0x8 X:-57 Y:3 W:1 [0x8 0xC7 0x3 *0x1 0x2 0x0 0x0 0x0]
Mouse: B:0x0 X:-57 Y:3 W:1 [0x0 0xC7 0x3 *0x1 0x2 0x0 0x0 0x0]
Mouse: B:0x10 X:-57 Y:3 W:1 [0x10 0xC7 0x3 *0x1 0x2 0x0 0x0 0x0]
Mouse: B:0x0 X:-57 Y:3 W:1 [0x0 0xC7 0x3 *0x1 0x2 0x0 0x0 0x0]

And this is mouse movement (3 examples):

Mouse: B:0x0 X:70 Y:3 W:15 [0x0 0x46 0x3 *0xF 0x2 0x0 0x0 0x0]
WHEEL EVENT: 14 (Raw: 0xE)
Mouse: B:0x0 X:91 Y:3 W:14 [0x0 0x5B 0x3 *0xE 0x2 0x0 0x0 0x0]
WHEEL EVENT: 10 (Raw: 0xA)
Mouse: B:0x0 X:-121 Y:3 W:10 [0x0 0x87 0x3 *0xA 0x2 0x0 0x0 0x0]
WHEEL EVENT: 5 (Raw: 0x5)

This is my code:

#include "Arduino.h"
#include "RP2040_PIO_USB_Host.h"

#define USB_DP_PIN 0 #define MOUSE_DATA_SIZE 8 // Reduced to focus on standard reports

bool _mouseUpdated = false; uint8_t mouseData[MOUSE_DATA_SIZE] = {0};

// Wheel detection int8_t lastWheel = 0; const uint8_t WHEEL_POSITION = 3; // Force standard position bool wheelMovementOnly = false;

void setup() { Serial.begin(115200); Serial.println("Precision Mouse Wheel Debugger"); Serial.println("Using standard wheel position (byte 3)"); }

void printMouseHID();

void loop() { if (_mouseUpdated) { printMouseHID(); _mouseUpdated = false; } }

void setup1() { USB_Mouse.begin(USB_DP_PIN, mouseData, MOUSE_DATA_SIZE); }

void loop1() { if (USB_Mouse.update()) { _mouseUpdated = true; } }

void printMouseHID() { // Extract standard mouse data uint8_t buttons = mouseData[0]; int8_t x = (int8_t)mouseData[1]; int8_t y = (int8_t)mouseData[2]; int8_t wheel = (int8_t)mouseData[WHEEL_POSITION];

// Only report wheel when buttons haven't changed and mouse isn't moving bool isPureWheelEvent = (buttons == 0) && (x == 0) && (y == 0);

if (isPureWheelEvent || wheel != lastWheel) { Serial.print("WHEEL EVENT: "); Serial.print(wheel); Serial.print(" (Raw: 0x"); Serial.print(mouseData[WHEEL_POSITION], HEX); Serial.println(")"); lastWheel = wheel; }

// Full report for debugging Serial.print("Mouse: B:0x"); Serial.print(buttons, HEX); Serial.print(" X:"); Serial.print(x); Serial.print(" Y:"); Serial.print(y); Serial.print(" W:"); Serial.print(wheel); Serial.print(" ["); for (uint8_t i = 0; i < MOUSE_DATA_SIZE; i++) { if (i == WHEEL_POSITION) Serial.print("*"); Serial.print("0x"); Serial.print(mouseData[i], HEX); if (i < MOUSE_DATA_SIZE-1) Serial.print(" "); } Serial.println("]"); }

Could someone please help me with this because I am stuck for days... Also, I have to note that I tried two different USB mouses (Dell and HP), and the result is the same

user1584421
  • 117
  • 6

0 Answers0