Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
r0ketlauncher hidapi c example
#include <stdio.h>
#include <string.h>
#include "hidapi.h"
#define MSG_NONE 0x00
#define MSG_DOWN 0x01
#define MSG_UP 0x02
#define MSG_LEFT 0x04
#define MSG_RIGHT 0x08
#define MSG_FIRE 0x10
#define MSG_STOP 0x20
#define MSG_STATUS 0x40
using namespace std;
int main(int argc, char* argv[])
{
int res;
unsigned char buf[256];
#define MAX_STR 255
wchar_t wstr[MAX_STR];
hid_device *handle;
if(argc < 2){
printf("use -l -r -u -d -f to control left, right, up, down, or fire\n");
return 1;
}
handle = hid_open(0x0a81, 0x0701, NULL);
if (!handle) {
printf("unable to open r0ketlauncher\n");
return 1;
}
// Read the Manufacturer String
wstr[0] = 0x0000;
res = hid_get_manufacturer_string(handle, wstr, MAX_STR);
if (res < 0)
printf("Unable to read manufacturer string\n");
printf("Manufacturer String: %ls\n", wstr);
// Read the Product String
wstr[0] = 0x0000;
res = hid_get_product_string(handle, wstr, MAX_STR);
if (res < 0)
printf("Unable to read product string\n");
printf("Product String: %ls\n", wstr);
// Read Indexed String 1
wstr[0] = 0x0000;
res = hid_get_indexed_string(handle, 1, wstr, MAX_STR);
if (res < 0)
printf("Unable to read indexed string 1\n");
printf("Indexed String 1: %ls\n", wstr);
hid_set_nonblocking(handle, 1);
if(!strcmp(argv[1],"-l")){
buf[0] = 0x00;
buf[1] = MSG_RIGHT;
res = hid_write(handle, buf, 2);
if (res < 0) {
printf("Unable to write()\n");
printf("Error: %ls\n", hid_error(handle));
}
}
if(!strcmp(argv[1],"-r")){
buf[0] = 0x00;
buf[1] = MSG_LEFT;
res = hid_write(handle, buf, 2);
if (res < 0) {
printf("Unable to write()\n");
printf("Error: %ls\n", hid_error(handle));
}
}
if(!strcmp(argv[1],"-s")){
buf[0] = 0x00;
buf[1] = MSG_STOP;
res = hid_write(handle, buf, 2);
if (res < 0) {
printf("Unable to write()\n");
printf("Error: %ls\n", hid_error(handle));
}
}
if(!strcmp(argv[1],"-u")){
buf[0] = 0x00;
buf[1] = MSG_UP;
res = hid_write(handle, buf, 2);
if (res < 0) {
printf("Unable to write()\n");
printf("Error: %ls\n", hid_error(handle));
}
}
if(!strcmp(argv[1],"-d")){
buf[0] = 0x00;
buf[1] = MSG_DOWN;
res = hid_write(handle, buf, 2);
if (res < 0) {
printf("Unable to write()\n");
printf("Error: %ls\n", hid_error(handle));
}
}
if(!strcmp(argv[1],"-f")){
buf[0] = 0x00;
buf[1] = MSG_FIRE;
res = hid_write(handle, buf, 2);
if (res < 0) {
printf("Unable to write()\n");
printf("Error: %ls\n", hid_error(handle));
}
}
hid_close(handle);
hid_exit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.