Browse Source

Fixed foohid, now working properly, tested with FPVFreerider Demo

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

Loading…
Cancel
Save