In order to use an old Logitech Gamepad as a cheap input interface, to get the buttons events to trigger some scripts like reboot, umount USB disk, send report by email, .... I would like to be able to interpret the HID frames that I can read in /dev/input/js0
I can see that a have 16 bytes frames each time I click on a button, but I would like to understand what I get. I can't find on Internet a simple description of the frames, does one of you already did this ?
Thanks
Hid protocol for a Gamepad
4 posts
- Posts: 3
- Joined: Mon Nov 05, 2012 9:04 am
Ok, I could make some progress, with my logitech rumblepad, I got frames of 8 bytes :
AA BB CC DD EE FF GG HH
EE FF : Signed value in 2 complement
GG : 1 for push buttons and 2 for analog pads
HH : number of the button
This is quite nice for a first start.
The AA BB CC DD are quite dark for me.
Here my C++ code I used to reverse engenere the frames :
AA BB CC DD EE FF GG HH
EE FF : Signed value in 2 complement
GG : 1 for push buttons and 2 for analog pads
HH : number of the button
This is quite nice for a first start.
The AA BB CC DD are quite dark for me.
Here my C++ code I used to reverse engenere the frames :
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#define FS 8
int main(int argc, char* argv[])
{
printf("Start PAD observer\n");
FILE* f = fopen("/dev/input/js0", "r");
if( f ) {
unsigned char buf[256];
int nb = 0;
while( nb >= 0 ) {
int i = 0;
while( i < nb ) {
printf("%02X ", buf[i]);
i++;
}
if( nb == FS ) {
short value = (buf[5] << 8) | buf[4];
int btnum = buf[7];
int group = buf[6];
printf(" Group=%d BT=%d Value=%d\n", group, btnum, value);
}
printf("\n");
nb = fread(buf, 1, FS, f);
}
fclose(f);
} else {
printf("Can't open file\n");
}
printf("End PAD observer\n");
return(0);
}
- Posts: 3
- Joined: Mon Nov 05, 2012 9:04 am
Aren't the first few digits in those types of results just some sort of timestamp?
note: I may or may not know what I'm talking about...
- Posts: 774
- Joined: Thu Aug 18, 2011 9:21 pm
Thank you, it is exaclty this, timestamp :
gives a number in milisecond, with the origin set to the machine startup.
Thank you.
- Code: Select all
unsigned int tist = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
gives a number in milisecond, with the origin set to the machine startup.
Thank you.
- Posts: 3
- Joined: Mon Nov 05, 2012 9:04 am