|
@@ -34,6 +34,7 @@
|
34
|
34
|
#define FOOHID_SEND 2
|
35
|
35
|
#define FOOHID_LIST 3
|
36
|
36
|
#define VIRTUAL_DEVICE_NAME "Virtual Serial Transmitter"
|
|
37
|
+#define VIRTUAL_DEVICE_SERIAL "SN 123456"
|
37
|
38
|
|
38
|
39
|
struct gamepad_report_t {
|
39
|
40
|
int16_t leftX;
|
|
@@ -48,7 +49,8 @@ static int running = 1;
|
48
|
49
|
static io_iterator_t iterator;
|
49
|
50
|
static io_service_t service;
|
50
|
51
|
static io_connect_t connect;
|
51
|
|
-static uint64_t input[4];
|
|
52
|
+#define input_count 8
|
|
53
|
+static uint64_t input[input_count];
|
52
|
54
|
static struct gamepad_report_t gamepad;
|
53
|
55
|
|
54
|
56
|
/*
|
|
@@ -83,7 +85,7 @@ static int foohidInit() {
|
83
|
85
|
|
84
|
86
|
// get a reference to the IOService
|
85
|
87
|
kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault,
|
86
|
|
- IOServiceMatching("it_unbit_foohid"), &iterator);
|
|
88
|
+ IOServiceMatching(FOOHID_NAME), &iterator);
|
87
|
89
|
if (ret != KERN_SUCCESS) {
|
88
|
90
|
printf("Unable to access foohid IOService\n");
|
89
|
91
|
return 1;
|
|
@@ -111,9 +113,13 @@ static int foohidInit() {
|
111
|
113
|
input[2] = (uint64_t)report_descriptor;
|
112
|
114
|
input[3] = sizeof(report_descriptor);
|
113
|
115
|
|
114
|
|
- uint32_t output_count = 1;
|
115
|
|
- uint64_t output = 0;
|
116
|
|
- ret = IOConnectCallScalarMethod(connect, FOOHID_CREATE, input, 4, &output, &output_count);
|
|
116
|
+ input[4] = (uint64_t)strdup(VIRTUAL_DEVICE_SERIAL);
|
|
117
|
+ input[5] = strlen((char*)input[4]);
|
|
118
|
+
|
|
119
|
+ input[6] = (uint64_t)2; // vendor ID
|
|
120
|
+ input[7] = (uint64_t)3; // device ID
|
|
121
|
+
|
|
122
|
+ ret = IOConnectCallScalarMethod(connect, FOOHID_CREATE, input, input_count, NULL, 0);
|
117
|
123
|
if (ret != KERN_SUCCESS) {
|
118
|
124
|
printf("Unable to create virtual HID device\n");
|
119
|
125
|
return 1;
|
|
@@ -125,9 +131,7 @@ static int foohidInit() {
|
125
|
131
|
static void foohidClose() {
|
126
|
132
|
printf("Destroying virtual HID device\n");
|
127
|
133
|
|
128
|
|
- uint32_t output_count = 1;
|
129
|
|
- uint64_t output = 0;
|
130
|
|
- kern_return_t ret = IOConnectCallScalarMethod(connect, FOOHID_DESTROY, input, 2, &output, &output_count);
|
|
134
|
+ kern_return_t ret = IOConnectCallScalarMethod(connect, FOOHID_DESTROY, input, 2, NULL, 0);
|
131
|
135
|
if (ret != KERN_SUCCESS) {
|
132
|
136
|
printf("Unable to destroy virtual HID device\n");
|
133
|
137
|
}
|
|
@@ -160,9 +164,7 @@ static void foohidSend(uint16_t *data) {
|
160
|
164
|
input[2] = (uint64_t)&gamepad;
|
161
|
165
|
input[3] = sizeof(struct gamepad_report_t);
|
162
|
166
|
|
163
|
|
- uint32_t output_count = 1;
|
164
|
|
- uint64_t output = 0;
|
165
|
|
- kern_return_t ret = IOConnectCallScalarMethod(connect, FOOHID_SEND, input, 4, &output, &output_count);
|
|
167
|
+ kern_return_t ret = IOConnectCallScalarMethod(connect, FOOHID_SEND, input, 4, NULL, 0);
|
166
|
168
|
if (ret != KERN_SUCCESS) {
|
167
|
169
|
printf("Unable to send packet to virtual HID device\n");
|
168
|
170
|
}
|
|
@@ -196,6 +198,8 @@ int main(int argc, char* argv[]) {
|
196
|
198
|
return 1;
|
197
|
199
|
}
|
198
|
200
|
|
|
201
|
+ printf("Entering main-loop...\n");
|
|
202
|
+
|
199
|
203
|
while (running != 0) {
|
200
|
204
|
if (serialHasChar(fd)) {
|
201
|
205
|
unsigned char c1;
|