Dernière activité 1 month ago

racerxdl's Avatar Lucas Teske a révisé ce gist 6 years ago. Aller à la révision

1 file changed, 166 insertions

rift-s-test.c(fichier créé)

@@ -0,0 +1,166 @@
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 + }
Plus récent Plus ancien