How to build a mouse-repeater with a Raspberry Pi 4B?

  Kiến thức lập trình

I would like to build a mouse-repeater in a way that I can connect a physical mouse to a USB port of my raspi and connect the Raspi via USB to a PC.
The Raspi should take the USB-mouse-configuration (Vendor-ID, Product-ID etc.), copy it using ConfigFS and create a USB mouse in direction of the PC as soon as a physical mouse is connected.
It should receive the mouse events (movement, button click, wheel) and should send it to the PC.

I already did a OTG project with a Raspi Zero in which I simulate a mouse and can send commands.
So creating the USB mouse device in direction to the PC with configFS I will probably manage to do.

What I probably need to know:

  1. How do I get notified about newly attached physical mouse? udev?
  2. How do I read out the parameters (vendor-id, product-id, no. of buttons etc.) so that I can replicate the identical device with configFS? /dev/input/inputX?
  3. How do I get the actual movements/button presses/wheel events? Shall I read from /dev/input/inputX or is there a better/easier way?
  4. The OTG port should probably be the USB-C-Power port as explained here (RaspPi 4 USB-C power connector is also a USB OTG connector, right? And I could probably connect the physical mouse on either USB2 or USB3 port, right?

Help is as always greatly appreciated!

J.

LEAVE A COMMENT