Skip to content

Commit 8cd37e5

Browse files
committed
Windows Support
1 parent 7b89a3b commit 8cd37e5

File tree

3 files changed

+706
-7
lines changed

3 files changed

+706
-7
lines changed

debug.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ THE SOFTWARE.
2222
#ifndef __DEBUG_H__
2323
#define __DEBUG_H__
2424

25-
#define fatal(msg...) { \
26-
fprintf(stderr, msg); \
25+
#define fatal(...) { \
26+
fprintf(stderr, __VA_ARGS__); \
2727
fprintf(stderr, " [%s(), %s:%u]\n", __FUNCTION__, __FILE__, __LINE__); \
2828
exit(1); \
2929
}

footswitch.c

+45-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
*/
2323
#include <stdio.h>
24-
#include <string.h>
2524
#include <stdlib.h>
25+
#include <string.h>
2626
#include <errno.h>
27-
#include <unistd.h>
28-
#include <hidapi.h>
2927
#include "common.h"
3028
#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
3138

3239
hid_device *dev = NULL;
3340

@@ -73,7 +80,7 @@ void usage() {
7380
}
7481

7582
void init_pid(unsigned short vid, unsigned short pid) {
76-
#ifdef OSX
83+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
7784
hid_init();
7885
dev = hid_open(vid, pid, NULL);
7986
#else
@@ -139,11 +146,22 @@ void deinit() {
139146
}
140147

141148
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
142155
int r = hid_write(dev, data, 8);
156+
#endif
143157
if (r < 0) {
144158
fatal("error writing data (%ls)", hid_error(dev));
145159
}
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
147165
}
148166

149167
void print_mouse(unsigned char data[]) {
@@ -238,6 +256,24 @@ void read_pedals() {
238256
for (i = 0 ; i < 3 ; i++) {
239257
query[3] = i + 1;
240258
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+
241277
r = hid_read(dev, response, 8);
242278
if (r < 0) {
243279
fatal("error reading data (%ls)", hid_error(dev));
@@ -481,7 +517,11 @@ void write_pedals() {
481517
}
482518
*/
483519
usb_write(pd.start);
520+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
521+
Sleep(1000 * 1000);
522+
#else
484523
usleep(1000*1000);
524+
#endif
485525
write_pedal(&pd.pedals[0]);
486526
write_pedal(&pd.pedals[1]);
487527
write_pedal(&pd.pedals[2]);

0 commit comments

Comments
 (0)