Browse Source

Fixed foohid, now working properly, tested with FPVFreerider Demo

Thomas Buck 8 years ago
parent
commit
13dc1b68b0
1 changed files with 24 additions and 3 deletions
  1. 24
    3
      src/foohid.c

+ 24
- 3
src/foohid.c View File

77
 };
77
 };
78
 
78
 
79
 static int foohidInit() {
79
 static int foohidInit() {
80
+    printf("Searching for foohid Kernel extension...\n");
81
+
80
     // get a reference to the IOService
82
     // get a reference to the IOService
81
     kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault,
83
     kern_return_t ret = IOServiceGetMatchingServices(kIOMasterPortDefault,
82
                             IOServiceMatching("it_unbit_foohid"), &iterator);
84
                             IOServiceMatching("it_unbit_foohid"), &iterator);
99
         return 1;
101
         return 1;
100
     }
102
     }
101
 
103
 
104
+    printf("Creating virtual HID device...\n");
105
+
102
     input[0] = (uint64_t)strdup(VIRTUAL_DEVICE_NAME);
106
     input[0] = (uint64_t)strdup(VIRTUAL_DEVICE_NAME);
103
     input[1] = strlen((char*)input[0]);
107
     input[1] = strlen((char*)input[0]);
104
 
108
 
117
 }
121
 }
118
 
122
 
119
 static void foohidClose() {
123
 static void foohidClose() {
124
+    printf("Destroying virtual HID device\n");
125
+
120
     uint32_t output_count = 1;
126
     uint32_t output_count = 1;
121
     uint64_t output = 0;
127
     uint64_t output = 0;
122
     kern_return_t ret = IOConnectCallScalarMethod(connect, FOOHID_DESTROY, input, 2, &output, &output_count);
128
     kern_return_t ret = IOConnectCallScalarMethod(connect, FOOHID_DESTROY, input, 2, &output, &output_count);
126
 }
132
 }
127
 
133
 
128
 static void foohidSend(uint16_t *data) {
134
 static void foohidSend(uint16_t *data) {
129
-    input[2] = (uint64_t)&gamepad;
130
-    input[3] = sizeof(struct gamepad_report_t);
131
-
132
     for (int i = 0; i < CHANNELS; i++) {
135
     for (int i = 0; i < CHANNELS; i++) {
133
         if (data[i] > CHANNELMAXIMUM) {
136
         if (data[i] > CHANNELMAXIMUM) {
134
             data[i] = CHANNELMAXIMUM;
137
             data[i] = CHANNELMAXIMUM;
142
     gamepad.aux1 = data[4] - 511;
145
     gamepad.aux1 = data[4] - 511;
143
     gamepad.aux2 = data[5] - 511;
146
     gamepad.aux2 = data[5] - 511;
144
 
147
 
148
+    /*
149
+    printf("Sending data packet:\n");
150
+    printf("Left X: %d\n", gamepad.leftX);
151
+    printf("Left Y: %d\n", gamepad.leftY);
152
+    printf("Right X: %d\n", gamepad.rightX);
153
+    printf("Right Y: %d\n", gamepad.rightY);
154
+    printf("Aux 1: %d\n", gamepad.aux1);
155
+    printf("Aux 2: %d\n", gamepad.aux2);
156
+    */
157
+
158
+    input[2] = (uint64_t)&gamepad;
159
+    input[3] = sizeof(struct gamepad_report_t);
160
+
145
     uint32_t output_count = 1;
161
     uint32_t output_count = 1;
146
     uint64_t output = 0;
162
     uint64_t output = 0;
147
     kern_return_t ret = IOConnectCallScalarMethod(connect, FOOHID_SEND, input, 4, &output, &output_count);
163
     kern_return_t ret = IOConnectCallScalarMethod(connect, FOOHID_SEND, input, 4, &output, &output_count);
152
 
168
 
153
 static void signalHandler(int signo) {
169
 static void signalHandler(int signo) {
154
     running = 0;
170
     running = 0;
171
+    printf("\n");
155
 }
172
 }
156
 
173
 
157
 int main(int argc, char* argv[]) {
174
 int main(int argc, char* argv[]) {
160
         return 1;
177
         return 1;
161
     }
178
     }
162
 
179
 
180
+    printf("Opening serial port...\n");
181
+
163
     int fd = serialOpen(argv[1], BAUDRATE);
182
     int fd = serialOpen(argv[1], BAUDRATE);
164
     if (fd == -1) {
183
     if (fd == -1) {
165
         return 1;
184
         return 1;
221
                         for (int i = 0; i < (CHANNELS + 1); i++) {
240
                         for (int i = 0; i < (CHANNELS + 1); i++) {
222
                             buff[i] = data[2 * i] << 8;
241
                             buff[i] = data[2 * i] << 8;
223
                             buff[i] |= data[(2 * i) + 1];
242
                             buff[i] |= data[(2 * i) + 1];
243
+                            buff[i] -= 1000;
224
                         }
244
                         }
225
 
245
 
226
                         foohidSend(buff);
246
                         foohidSend(buff);
230
         }
250
         }
231
     }
251
     }
232
 
252
 
253
+    printf("Closing serial port...\n");
233
     serialClose(fd);
254
     serialClose(fd);
234
     foohidClose();
255
     foohidClose();
235
 
256
 

Loading…
Cancel
Save