Skip to content

Instantly share code, notes, and snippets.

@Ape
Last active January 4, 2016 13:49
Show Gist options
  • Save Ape/8630768 to your computer and use it in GitHub Desktop.
Save Ape/8630768 to your computer and use it in GitHub Desktop.
DualShock 4 driver test using C
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
int main(int argc, char **argv) {
if (argc != 2) {
printf("Usage: %s hidraw_device\n", argv[0]);
return 0;
}
int fd = open(argv[1], O_RDWR);
if (fd < 0) {
perror("Unable to open device");
return 1;
}
char buf[78];
memset(buf, 0x0, sizeof(buf));
buf[0] = 0x11;
buf[1] = 128;
buf[3] = 255;
// Rumble
buf[6] = 0;
buf[7] = 0;
// LED (red, green, blue)
buf[8] = 0;
buf[9] = 0;
buf[10] = 255;
// Time to flash bright (255 = 2.5 seconds)
buf[11] = 0;
// Time to flash dark (255 = 2.5 seconds)
buf[12] = 0;
int res;
res = write(fd, buf, 78);
if (res < 0) {
perror("Unable to send report");
return 1;
}
for (;;) {
res = read(fd, buf, 78);
if (res < 0) {
perror("Unable to read report");
return 1;
}
for (int i = 0; i < res; ++i) {
printf("%2hhx ", buf[i]);
}
puts("\n");
}
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment