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