rift-s-test.c
· 3.0 KiB · C
Ham
#include <stdio.h>
#include <hidapi/hidapi.h>
void printBuffer(char *buff, int length) {
for (int i = 0; i < length; i++) {
printf("%02x ", buff[i] & 0xFF);
}
printf("\n");
}
void clear_buff(char *buff, int length) {
for (int i = 0; i < length; i++) {
buff[i] = 0x00;
}
}
void get_report(hid_device *hid, char id, char *buff, int length) {
buff[0] = id;
clear_buff(&buff[1], length-1);
hid_get_feature_report(hid, buff, length);
}
int main() {
struct hid_device_info* dev = hid_enumerate(0x2833, 0x0051);
if (dev == NULL) {
printf("Not found\n");
return 1;
}
struct hid_device_info *d = dev;
while (d != NULL) {
printf("%d\n", d->interface_number);
if (d->interface_number == 0x07) {
printf("FOUND\n");
break;
}
d = d->next;
}
if (d == NULL) {
printf("Not found\n");
return 1;
}
hid_device *hid = hid_open_path(d->path);
if (hid == NULL) {
printf("FAIL %s\n", hid_error(hid));
return 1;
}
char buff[65];
get_report(hid, 0x4A, buff, 65);
printBuffer(buff, 64);
for (int i = 1; i < 65; i++) {
buff[i] = 0x00;
}
buff[2] = 0x0D;
buff[7] = 0x0C;
printBuffer(buff, 64);
hid_send_feature_report(hid, buff, 64);
get_report(hid, 0x4A, buff, 64);
printBuffer(buff, 64);
clear_buff(buff, 65);
buff[0] = 0x4A;
buff[2] = 0x0D;
buff[3] = 0x0C;
buff[7] = 0x12;
hid_send_feature_report(hid, buff, 64);
get_report(hid, 0x4A, buff, 64);
printBuffer(buff, 64);
clear_buff(buff, 65);
buff[0] = 0x07;
buff[1] = 0x1B;
buff[2] = 0x01;
hid_send_feature_report(hid, buff, 3);
clear_buff(buff, 65);
// get_report(hid, 0x96, buff, 5);
// printBuffer(buff, 5);
// get_report(hid, 0x67, buff, 62);
// printBuffer(buff, 62);
clear_buff(buff, 65);
buff[0] = 0x14;
buff[1] = 0x01;
hid_send_feature_report(hid, buff, 2); // Enables Camera Device
// clear_buff(buff, 65);
// buff[0] = 0x93;
// buff[1] = 0x01;
// buff[2] = 0xB8;
// buff[3] = 0x0B;
// hid_send_feature_report(hid, buff, 6);
clear_buff(buff, 65);
buff[0] = 0x0A;
buff[1] = 0x02;
hid_send_feature_report(hid, buff, 2);
// clear_buff(buff, 65);
// buff[0] = 0x4A;
// buff[2] = 0x0F;
// buff[7] = 0x0C;
// hid_send_feature_report(hid, buff, 64);
// get_report(hid, 0x4A, buff, 64);
// printBuffer(buff, 64);
// TODO Several 0x4A
// clear_buff(buff, 65);
// buff[0] = 0x12;
// buff[1] = 0xE0;
// buff[2] = 0xC7;
// buff[3] = 0x10;
// buff[4] = 0xC0;
// buff[5] = 0xBD;
// buff[6] = 0x25;
// buff[7] = 0xED;
// buff[8] = 0xE5;
// buff[9] = 0x06;
// buff[10] = 0x00;
// buff[11] = 0xE8;
// buff[12] = 0x03;
// hid_send_feature_report(hid, buff, 61);
// clear_buff(buff, 65);
// buff[0] = 0x93;
// buff[1] = 0x01;
// buff[2] = 0xB8;
// buff[3] = 0x0B;
// hid_send_feature_report(hid, buff, 6);
clear_buff(buff, 65);
buff[0] = 0x02;
buff[1] = 0x01;
hid_send_feature_report(hid, buff, 2); // Enables HMD
hid_close(hid);
hid_free_enumeration(dev);
}
| 1 | #include <stdio.h> |
| 2 | #include <hidapi/hidapi.h> |
| 3 | |
| 4 | void printBuffer(char *buff, int length) { |
| 5 | for (int i = 0; i < length; i++) { |
| 6 | printf("%02x ", buff[i] & 0xFF); |
| 7 | } |
| 8 | |
| 9 | printf("\n"); |
| 10 | } |
| 11 | |
| 12 | void clear_buff(char *buff, int length) { |
| 13 | for (int i = 0; i < length; i++) { |
| 14 | buff[i] = 0x00; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | void get_report(hid_device *hid, char id, char *buff, int length) { |
| 19 | buff[0] = id; |
| 20 | clear_buff(&buff[1], length-1); |
| 21 | hid_get_feature_report(hid, buff, length); |
| 22 | } |
| 23 | |
| 24 | int main() { |
| 25 | struct hid_device_info* dev = hid_enumerate(0x2833, 0x0051); |
| 26 | if (dev == NULL) { |
| 27 | printf("Not found\n"); |
| 28 | return 1; |
| 29 | } |
| 30 | struct hid_device_info *d = dev; |
| 31 | while (d != NULL) { |
| 32 | printf("%d\n", d->interface_number); |
| 33 | if (d->interface_number == 0x07) { |
| 34 | printf("FOUND\n"); |
| 35 | break; |
| 36 | } |
| 37 | d = d->next; |
| 38 | } |
| 39 | |
| 40 | if (d == NULL) { |
| 41 | printf("Not found\n"); |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | hid_device *hid = hid_open_path(d->path); |
| 46 | if (hid == NULL) { |
| 47 | printf("FAIL %s\n", hid_error(hid)); |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | char buff[65]; |
| 52 | |
| 53 | get_report(hid, 0x4A, buff, 65); |
| 54 | printBuffer(buff, 64); |
| 55 | |
| 56 | for (int i = 1; i < 65; i++) { |
| 57 | buff[i] = 0x00; |
| 58 | } |
| 59 | |
| 60 | buff[2] = 0x0D; |
| 61 | buff[7] = 0x0C; |
| 62 | |
| 63 | printBuffer(buff, 64); |
| 64 | |
| 65 | hid_send_feature_report(hid, buff, 64); |
| 66 | |
| 67 | get_report(hid, 0x4A, buff, 64); |
| 68 | printBuffer(buff, 64); |
| 69 | |
| 70 | clear_buff(buff, 65); |
| 71 | buff[0] = 0x4A; |
| 72 | |
| 73 | buff[2] = 0x0D; |
| 74 | buff[3] = 0x0C; |
| 75 | buff[7] = 0x12; |
| 76 | |
| 77 | hid_send_feature_report(hid, buff, 64); |
| 78 | |
| 79 | get_report(hid, 0x4A, buff, 64); |
| 80 | printBuffer(buff, 64); |
| 81 | |
| 82 | clear_buff(buff, 65); |
| 83 | buff[0] = 0x07; |
| 84 | buff[1] = 0x1B; |
| 85 | buff[2] = 0x01; |
| 86 | |
| 87 | hid_send_feature_report(hid, buff, 3); |
| 88 | clear_buff(buff, 65); |
| 89 | |
| 90 | // get_report(hid, 0x96, buff, 5); |
| 91 | // printBuffer(buff, 5); |
| 92 | |
| 93 | // get_report(hid, 0x67, buff, 62); |
| 94 | // printBuffer(buff, 62); |
| 95 | |
| 96 | clear_buff(buff, 65); |
| 97 | buff[0] = 0x14; |
| 98 | buff[1] = 0x01; |
| 99 | |
| 100 | hid_send_feature_report(hid, buff, 2); // Enables Camera Device |
| 101 | |
| 102 | // clear_buff(buff, 65); |
| 103 | |
| 104 | // buff[0] = 0x93; |
| 105 | // buff[1] = 0x01; |
| 106 | // buff[2] = 0xB8; |
| 107 | // buff[3] = 0x0B; |
| 108 | |
| 109 | // hid_send_feature_report(hid, buff, 6); |
| 110 | |
| 111 | clear_buff(buff, 65); |
| 112 | |
| 113 | buff[0] = 0x0A; |
| 114 | buff[1] = 0x02; |
| 115 | |
| 116 | hid_send_feature_report(hid, buff, 2); |
| 117 | |
| 118 | // clear_buff(buff, 65); |
| 119 | |
| 120 | // buff[0] = 0x4A; |
| 121 | // buff[2] = 0x0F; |
| 122 | // buff[7] = 0x0C; |
| 123 | |
| 124 | // hid_send_feature_report(hid, buff, 64); |
| 125 | |
| 126 | // get_report(hid, 0x4A, buff, 64); |
| 127 | // printBuffer(buff, 64); |
| 128 | |
| 129 | // TODO Several 0x4A |
| 130 | |
| 131 | // clear_buff(buff, 65); |
| 132 | // buff[0] = 0x12; |
| 133 | // buff[1] = 0xE0; |
| 134 | // buff[2] = 0xC7; |
| 135 | // buff[3] = 0x10; |
| 136 | // buff[4] = 0xC0; |
| 137 | // buff[5] = 0xBD; |
| 138 | // buff[6] = 0x25; |
| 139 | // buff[7] = 0xED; |
| 140 | // buff[8] = 0xE5; |
| 141 | // buff[9] = 0x06; |
| 142 | // buff[10] = 0x00; |
| 143 | // buff[11] = 0xE8; |
| 144 | // buff[12] = 0x03; |
| 145 | |
| 146 | // hid_send_feature_report(hid, buff, 61); |
| 147 | |
| 148 | // clear_buff(buff, 65); |
| 149 | |
| 150 | // buff[0] = 0x93; |
| 151 | // buff[1] = 0x01; |
| 152 | // buff[2] = 0xB8; |
| 153 | // buff[3] = 0x0B; |
| 154 | |
| 155 | // hid_send_feature_report(hid, buff, 6); |
| 156 | |
| 157 | clear_buff(buff, 65); |
| 158 | |
| 159 | buff[0] = 0x02; |
| 160 | buff[1] = 0x01; |
| 161 | |
| 162 | hid_send_feature_report(hid, buff, 2); // Enables HMD |
| 163 | |
| 164 | hid_close(hid); |
| 165 | hid_free_enumeration(dev); |
| 166 | } |