Преглед изворни кода

Fix to work properly with foohid 0.2.1

Thomas Buck пре 7 година
родитељ
комит
ff2c9965b8
No account linked to committer's email address

BIN
SerialGamepad.xcodeproj/project.xcworkspace/xcuserdata/thomas.xcuserdatad/UserInterfaceState.xcuserstate Прегледај датотеку


+ 1
- 1
SerialGamepad/Info.plist Прегледај датотеку

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

+ 20
- 12
SerialGamepad/fooHID.m Прегледај датотеку

@@ -20,6 +20,7 @@
20 20
 #define FOOHID_SEND 2
21 21
 #define FOOHID_LIST 3
22 22
 #define VIRTUAL_DEVICE_NAME "Virtual Serial Transmitter"
23
+#define VIRTUAL_DEVICE_SN "SN  123456"
23 24
 
24 25
 int foohidInit();
25 26
 void foohidClose();
@@ -60,6 +61,7 @@ struct gamepad_report_t {
60 61
 
61 62
 static io_connect_t connector;
62 63
 static uint64_t deviceName = 0, deviceNameLength;
64
+static uint64_t deviceSN = 0, deviceSNLength;
63 65
 static struct gamepad_report_t gamepad;
64 66
 
65 67
 /*
@@ -122,18 +124,28 @@ int foohidInit() {
122 124
         deviceName = (uint64_t)strdup(VIRTUAL_DEVICE_NAME);
123 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 134
     input[0] = deviceName;
128 135
     input[1] = deviceNameLength;
136
+
129 137
     input[2] = (uint64_t)report_descriptor;
130 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 147
     if (ret != KERN_SUCCESS) {
136
-        NSLog(@"Unable to create virtual HID device\n");
148
+        printf("Unable to create virtual HID device\n");
137 149
         return 1;
138 150
     }
139 151
     
@@ -147,9 +159,7 @@ void foohidClose() {
147 159
     input[0] = deviceName;
148 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 163
     if (ret != KERN_SUCCESS) {
154 164
         NSLog(@"Unable to destroy virtual HID device\n");
155 165
     }
@@ -185,9 +195,7 @@ void foohidSend(uint16_t *data) {
185 195
     input[2] = (uint64_t)&gamepad;
186 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 199
     if (ret != KERN_SUCCESS) {
192 200
         NSLog(@"Unable to send packet to virtual HID device\n");
193 201
     }

+ 15
- 11
src/foohid.c Прегледај датотеку

@@ -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;

Loading…
Откажи
Сачувај