Browse Source

Fix to work properly with foohid 0.2.1

Thomas Buck 7 years ago
parent
commit
ff2c9965b8
No account linked to committer's email address

BIN
SerialGamepad.xcodeproj/project.xcworkspace/xcuserdata/thomas.xcuserdatad/UserInterfaceState.xcuserstate View File


+ 1
- 1
SerialGamepad/Info.plist View File

21
 	<key>CFBundleSignature</key>
21
 	<key>CFBundleSignature</key>
22
 	<string>????</string>
22
 	<string>????</string>
23
 	<key>CFBundleVersion</key>
23
 	<key>CFBundleVersion</key>
24
-	<string>100</string>
24
+	<string>101</string>
25
 	<key>LSApplicationCategoryType</key>
25
 	<key>LSApplicationCategoryType</key>
26
 	<string>public.app-category.utilities</string>
26
 	<string>public.app-category.utilities</string>
27
 	<key>LSMinimumSystemVersion</key>
27
 	<key>LSMinimumSystemVersion</key>

+ 20
- 12
SerialGamepad/fooHID.m View File

20
 #define FOOHID_SEND 2
20
 #define FOOHID_SEND 2
21
 #define FOOHID_LIST 3
21
 #define FOOHID_LIST 3
22
 #define VIRTUAL_DEVICE_NAME "Virtual Serial Transmitter"
22
 #define VIRTUAL_DEVICE_NAME "Virtual Serial Transmitter"
23
+#define VIRTUAL_DEVICE_SN "SN  123456"
23
 
24
 
24
 int foohidInit();
25
 int foohidInit();
25
 void foohidClose();
26
 void foohidClose();
60
 
61
 
61
 static io_connect_t connector;
62
 static io_connect_t connector;
62
 static uint64_t deviceName = 0, deviceNameLength;
63
 static uint64_t deviceName = 0, deviceNameLength;
64
+static uint64_t deviceSN = 0, deviceSNLength;
63
 static struct gamepad_report_t gamepad;
65
 static struct gamepad_report_t gamepad;
64
 
66
 
65
 /*
67
 /*
122
         deviceName = (uint64_t)strdup(VIRTUAL_DEVICE_NAME);
124
         deviceName = (uint64_t)strdup(VIRTUAL_DEVICE_NAME);
123
         deviceNameLength = strlen((char *)deviceName);
125
         deviceNameLength = strlen((char *)deviceName);
124
     }
126
     }
127
+
128
+    if (deviceSN == 0) {
129
+        deviceSN = (uint64_t)strdup(VIRTUAL_DEVICE_SN);
130
+        deviceSNLength = strlen((char *)deviceSN);
131
+    }
125
     
132
     
126
-    uint64_t input[4];
133
+    uint64_t input[8];
127
     input[0] = deviceName;
134
     input[0] = deviceName;
128
     input[1] = deviceNameLength;
135
     input[1] = deviceNameLength;
136
+
129
     input[2] = (uint64_t)report_descriptor;
137
     input[2] = (uint64_t)report_descriptor;
130
     input[3] = sizeof(report_descriptor);
138
     input[3] = sizeof(report_descriptor);
131
-    
132
-    uint32_t output_count = 1;
133
-    uint64_t output = 0;
134
-    ret = IOConnectCallScalarMethod(connector, FOOHID_CREATE, input, 4, &output, &output_count);
139
+
140
+    input[4] = deviceSN;
141
+    input[5] = deviceSNLength;
142
+
143
+    input[6] = (uint64_t)2; // vendor ID
144
+    input[7] = (uint64_t)3; // device ID
145
+
146
+    ret = IOConnectCallScalarMethod(connector, FOOHID_CREATE, input, 8, NULL, 0);
135
     if (ret != KERN_SUCCESS) {
147
     if (ret != KERN_SUCCESS) {
136
-        NSLog(@"Unable to create virtual HID device\n");
148
+        printf("Unable to create virtual HID device\n");
137
         return 1;
149
         return 1;
138
     }
150
     }
139
     
151
     
147
     input[0] = deviceName;
159
     input[0] = deviceName;
148
     input[1] = deviceNameLength;
160
     input[1] = deviceNameLength;
149
     
161
     
150
-    uint32_t output_count = 1;
151
-    uint64_t output = 0;
152
-    kern_return_t ret = IOConnectCallScalarMethod(connector, FOOHID_DESTROY, input, 2, &output, &output_count);
162
+    kern_return_t ret = IOConnectCallScalarMethod(connector, FOOHID_DESTROY, input, 2, NULL, 0);
153
     if (ret != KERN_SUCCESS) {
163
     if (ret != KERN_SUCCESS) {
154
         NSLog(@"Unable to destroy virtual HID device\n");
164
         NSLog(@"Unable to destroy virtual HID device\n");
155
     }
165
     }
185
     input[2] = (uint64_t)&gamepad;
195
     input[2] = (uint64_t)&gamepad;
186
     input[3] = sizeof(struct gamepad_report_t);
196
     input[3] = sizeof(struct gamepad_report_t);
187
     
197
     
188
-    uint32_t output_count = 1;
189
-    uint64_t output = 0;
190
-    kern_return_t ret = IOConnectCallScalarMethod(connector, FOOHID_SEND, input, 4, &output, &output_count);
198
+    kern_return_t ret = IOConnectCallScalarMethod(connector, FOOHID_SEND, input, 4, NULL, 0);
191
     if (ret != KERN_SUCCESS) {
199
     if (ret != KERN_SUCCESS) {
192
         NSLog(@"Unable to send packet to virtual HID device\n");
200
         NSLog(@"Unable to send packet to virtual HID device\n");
193
     }
201
     }

+ 15
- 11
src/foohid.c View File

34
 #define FOOHID_SEND 2
34
 #define FOOHID_SEND 2
35
 #define FOOHID_LIST 3
35
 #define FOOHID_LIST 3
36
 #define VIRTUAL_DEVICE_NAME "Virtual Serial Transmitter"
36
 #define VIRTUAL_DEVICE_NAME "Virtual Serial Transmitter"
37
+#define VIRTUAL_DEVICE_SERIAL "SN 123456"
37
 
38
 
38
 struct gamepad_report_t {
39
 struct gamepad_report_t {
39
     int16_t leftX;
40
     int16_t leftX;
48
 static io_iterator_t iterator;
49
 static io_iterator_t iterator;
49
 static io_service_t service;
50
 static io_service_t service;
50
 static io_connect_t connect;
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
 static struct gamepad_report_t gamepad;
54
 static struct gamepad_report_t gamepad;
53
 
55
 
54
 /*
56
 /*
83
 
85
 
84
     // get a reference to the IOService
86
     // get a reference to the IOService
85
     kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault,
87
     kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault,
86
-                            IOServiceMatching("it_unbit_foohid"), &iterator);
88
+                            IOServiceMatching(FOOHID_NAME), &iterator);
87
     if (ret != KERN_SUCCESS) {
89
     if (ret != KERN_SUCCESS) {
88
         printf("Unable to access foohid IOService\n");
90
         printf("Unable to access foohid IOService\n");
89
         return 1;
91
         return 1;
111
     input[2] = (uint64_t)report_descriptor;
113
     input[2] = (uint64_t)report_descriptor;
112
     input[3] = sizeof(report_descriptor);
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
     if (ret != KERN_SUCCESS) {
123
     if (ret != KERN_SUCCESS) {
118
         printf("Unable to create virtual HID device\n");
124
         printf("Unable to create virtual HID device\n");
119
         return 1;
125
         return 1;
125
 static void foohidClose() {
131
 static void foohidClose() {
126
     printf("Destroying virtual HID device\n");
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
     if (ret != KERN_SUCCESS) {
135
     if (ret != KERN_SUCCESS) {
132
         printf("Unable to destroy virtual HID device\n");
136
         printf("Unable to destroy virtual HID device\n");
133
     }
137
     }
160
     input[2] = (uint64_t)&gamepad;
164
     input[2] = (uint64_t)&gamepad;
161
     input[3] = sizeof(struct gamepad_report_t);
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
     if (ret != KERN_SUCCESS) {
168
     if (ret != KERN_SUCCESS) {
167
         printf("Unable to send packet to virtual HID device\n");
169
         printf("Unable to send packet to virtual HID device\n");
168
     }
170
     }
196
         return 1;
198
         return 1;
197
     }
199
     }
198
 
200
 
201
+    printf("Entering main-loop...\n");
202
+
199
     while (running != 0) {
203
     while (running != 0) {
200
         if (serialHasChar(fd)) {
204
         if (serialHasChar(fd)) {
201
             unsigned char c1;
205
             unsigned char c1;

Loading…
Cancel
Save