39 #define LO(x) ((x) & 0x0F)
40 #define HI(x) (((x) & 0xF0) >> 8)
41 #define HEX(x) ("0123456789abcdef"[(x)])
56 main(
int argc,
char *argv[])
60 const char *device =
"/dev/input/js0";
66 fd = fopen(device,
"r");
68 int save_errno = errno;
69 fprintf(stderr,
"fopen(\"%s\")=%d %s\n", device, save_errno, strerror(save_errno));
74 uint8_t maxbt = 0, maxlc = 0;
85 rc = fread((
void *)&buf[0], 1,
sizeof(buf), fd);
87 fprintf(stderr,
"fread returned no data\n");
91 cnt = *((uint32_t *)&buf[0]);
92 value = *((int16_t *)&buf[4]);
93 type = *((uint8_t *)&buf[6]);
94 idx = *((uint8_t *)&buf[7]);
97 if (!(type & 0x80U)) {
98 printf(
"buttons=%d (max=%u) linear controls=%d (max=%u)\n\n", nbt, maxbt, nlc, maxlc);
102 switch (type & 0x7FU) {
118 printf(
"0x%8x %s[%2u]=%6d\n", cnt,
type2str(type & 0x7FU), idx, value);
124 printf(
"0x%8x %s[%2u]=%6d\n", cnt,
type2str(type), idx, value);
int main(int argc, char *argv[])
static doublereal buf[BUFSIZE]
static const char * type2str(uint8_t type)