@@ -21,13 +21,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
THE SOFTWARE.
22
22
*/
23
23
#include <stdio.h>
24
- #include <string.h>
25
24
#include <stdlib.h>
25
+ #include <string.h>
26
26
#include <errno.h>
27
- #include <unistd.h>
28
- #include <hidapi.h>
29
27
#include "common.h"
30
28
#include "debug.h"
29
+ #if defined(WIN32 ) || defined(_WIN32 ) || defined(__WIN32__ ) || defined(__NT__ )
30
+ #include <Windows.h>
31
+ #include "getopt.h"
32
+ #include "hidapi.h"
33
+ #else
34
+ #include <hidapi.h>
35
+ #include <string.h>
36
+ #include <unistd.h>
37
+ #endif
31
38
32
39
hid_device * dev = NULL ;
33
40
@@ -73,7 +80,7 @@ void usage() {
73
80
}
74
81
75
82
void init_pid (unsigned short vid , unsigned short pid ) {
76
- #ifdef OSX
83
+ #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __NT__ )
77
84
hid_init ();
78
85
dev = hid_open (vid , pid , NULL );
79
86
#else
@@ -139,11 +146,22 @@ void deinit() {
139
146
}
140
147
141
148
void usb_write (unsigned char data [8 ]) {
149
+ #if defined(WIN32 ) || defined(_WIN32 ) || defined(__WIN32__ ) || defined(__NT__ )
150
+ unsigned char win_data [9 ];
151
+ win_data [0 ] = 0 ;
152
+ for (int i = 0 ; i < 8 ; i ++ ) win_data [i + 1 ] = data [i ];
153
+ int r = hid_write (dev , win_data , 9 );
154
+ #else
142
155
int r = hid_write (dev , data , 8 );
156
+ #endif
143
157
if (r < 0 ) {
144
158
fatal ("error writing data (%ls)" , hid_error (dev ));
145
159
}
146
- usleep (30 * 1000 );
160
+ #if defined(WIN32 ) || defined(_WIN32 ) || defined(__WIN32__ ) || defined(__NT__ )
161
+ Sleep (30 * 1000 );
162
+ #else
163
+ usleep (30 * 1000 )
164
+ #endif
147
165
}
148
166
149
167
void print_mouse (unsigned char data []) {
@@ -238,6 +256,24 @@ void read_pedals() {
238
256
for (i = 0 ; i < 3 ; i ++ ) {
239
257
query [3 ] = i + 1 ;
240
258
usb_write (query );
259
+ // Read the Manufacturer String
260
+ #define MAX_STR 255
261
+ int res ;
262
+ wchar_t wstr [MAX_STR ];
263
+ res = hid_get_manufacturer_string (dev , wstr , MAX_STR );
264
+ wprintf (L"Manufacturer String: %s\n" , wstr );
265
+ // Read the Product String
266
+ res = hid_get_product_string (dev , wstr , MAX_STR );
267
+ wprintf (L"Product String: %s\n" , wstr );
268
+
269
+ // Read the Serial Number String
270
+ res = hid_get_serial_number_string (dev , wstr , MAX_STR );
271
+ wprintf (L"Serial Number String: (%d) %s\n" , wstr [0 ], wstr );
272
+
273
+ // Read Indexed String 1
274
+ res = hid_get_indexed_string (dev , 2 , wstr , MAX_STR );
275
+ wprintf (L"Indexed String 1: %s\n" , wstr );
276
+
241
277
r = hid_read (dev , response , 8 );
242
278
if (r < 0 ) {
243
279
fatal ("error reading data (%ls)" , hid_error (dev ));
@@ -481,7 +517,11 @@ void write_pedals() {
481
517
}
482
518
*/
483
519
usb_write (pd .start );
520
+ #if defined(WIN32 ) || defined(_WIN32 ) || defined(__WIN32__ ) || defined(__NT__ )
521
+ Sleep (1000 * 1000 );
522
+ #else
484
523
usleep (1000 * 1000 );
524
+ #endif
485
525
write_pedal (& pd .pedals [0 ]);
486
526
write_pedal (& pd .pedals [1 ]);
487
527
write_pedal (& pd .pedals [2 ]);
0 commit comments