Skip to content

Commit 964ba35

Browse files
committed
Windows Support
1 parent 7b89a3b commit 964ba35

File tree

3 files changed

+705
-7
lines changed

3 files changed

+705
-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

+44-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@ 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>
27+
#include "hidapi.h"
2928
#include "common.h"
3029
#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
3137

3238
hid_device *dev = NULL;
3339

@@ -73,7 +79,7 @@ void usage() {
7379
}
7480

7581
void init_pid(unsigned short vid, unsigned short pid) {
76-
#ifdef OSX
82+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
7783
hid_init();
7884
dev = hid_open(vid, pid, NULL);
7985
#else
@@ -139,11 +145,22 @@ void deinit() {
139145
}
140146

141147
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
142154
int r = hid_write(dev, data, 8);
155+
#endif
143156
if (r < 0) {
144157
fatal("error writing data (%ls)", hid_error(dev));
145158
}
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
147164
}
148165

149166
void print_mouse(unsigned char data[]) {
@@ -238,6 +255,24 @@ void read_pedals() {
238255
for (i = 0 ; i < 3 ; i++) {
239256
query[3] = i + 1;
240257
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+
241276
r = hid_read(dev, response, 8);
242277
if (r < 0) {
243278
fatal("error reading data (%ls)", hid_error(dev));
@@ -481,7 +516,11 @@ void write_pedals() {
481516
}
482517
*/
483518
usb_write(pd.start);
519+
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
520+
Sleep(1000 * 1000);
521+
#else
484522
usleep(1000*1000);
523+
#endif
485524
write_pedal(&pd.pedals[0]);
486525
write_pedal(&pd.pedals[1]);
487526
write_pedal(&pd.pedals[2]);

0 commit comments

Comments
 (0)