Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

MotorController

Reverse engineered code to control USB joystick rumble motors.

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

MotorController

This is an application I wrote to control the rumble motors in Dualshock-like USB joysticks. It is written in Delphi for Windows and I reused this code to control the motors in my Lollybot (a.k.a. Suckerbot) robot.

motorcontroller

The code to control the motors can be found in ControlPanel.pas. I also added an option to choose the joystick from a list of available USB devices which is implemented in the file ChooseJoystick.pas

choosejoystick

Reverse Engineering the USB Commands

I reverse engineered the commands to control the motors using the USB sniffing tool SnoopyPro. I plugged a joystick into the computer, started monitoring the USB data with SnoopyPro, and then exercised the rumble motors using the standard Windows game controller tool.

When I examined the data being sent over USB it appeared that the single command f3 00 00 00 00 00 00 was being sent (in the "down" direction) to stop the motor and that two commands were sent to start the motor: 51 00 fe 00 fe 00 00 followed by fa fe 00 00 00 00 00. See a screenshot of the output below.

snoopypro

I observed that with different rumble "strengths" the two fe values would change. These are two 8-bit values corresponding to the power level for each motor from 00 (off) to fe (full power). See ControlPanel.pas for more details.

Download

Note that the code uses the HidController package written by Robert Marquardt which you will need to install if you want to compile the Delphi project from the source code.

Download the executable for Windows: MotorController.exe (458 KB)