Browse Source

Small fixes in cli apps

Thomas Buck 9 years ago
parent
commit
44ca0bbc98
3 changed files with 35 additions and 42 deletions
  1. 4
    5
      Makefile
  2. 15
    5
      src/foohid.c
  3. 16
    32
      src/protocol.c

+ 4
- 5
Makefile View File

@@ -7,12 +7,11 @@
7 7
 
8 8
 CFLAGS ?= -Wall -pedantic -std=c11
9 9
 
10
-ifneq ("$(wildcard /Library/Extensions/foohid.kext/Contents/Info.plist)","")
11 10
 all: bin/protocol bin/foohid
12
-else
13
-all: bin/protocol
14
-	@echo "Could not find foohid.kext installed in /Library/Extensions!"
15
-endif
11
+
12
+install: all
13
+	cp bin/protocol ~/bin/protocol
14
+	cp bin/foohid ~/bin/foohid
16 15
 
17 16
 bin/protocol: src/serial.o src/protocol.o
18 17
 	@mkdir -p bin

+ 15
- 5
src/foohid.c View File

@@ -25,6 +25,7 @@
25 25
 #define CHECKSUMBYTES 2
26 26
 #define PAYLOADBYTES (PACKETSIZE - HEADERBYTES - CHECKSUMBYTES)
27 27
 #define CHANNELS 6
28
+#define TESTCHANNEL 2
28 29
 #define CHANNELMAXIMUM 1022
29 30
 
30 31
 #define FOOHID_NAME "it_unbit_foohid"
@@ -139,10 +140,10 @@ static void foohidSend(uint16_t *data) {
139 140
         }
140 141
     }
141 142
 
142
-    gamepad.leftX = data[0] - 511;
143
-    gamepad.leftY = data[1] - 511;
144
-    gamepad.rightX = data[2] - 511;
145
-    gamepad.rightY = data[3] - 511;
143
+    gamepad.leftX = data[3] - 511;
144
+    gamepad.leftY = data[2] - 511;
145
+    gamepad.rightX = data[0] - 511;
146
+    gamepad.rightY = data[1] - 511;
146 147
     gamepad.aux1 = data[4] - 511;
147 148
     gamepad.aux2 = data[5] - 511;
148 149
 
@@ -241,7 +242,16 @@ int main(int argc, char* argv[]) {
241 242
                         for (int i = 0; i < (CHANNELS + 1); i++) {
242 243
                             buff[i] = data[2 * i] << 8;
243 244
                             buff[i] |= data[(2 * i) + 1];
244
-                            buff[i] -= 1000;
245
+
246
+                            if (i < CHANNELS) {
247
+                                buff[i] -= 1000;
248
+                            }
249
+                        }
250
+
251
+                        // Check Test Channel Value
252
+                        if (buff[CHANNELS] != buff[TESTCHANNEL]) {
253
+                            printf("Wrong test channel value: %d != %d\n",
254
+                                   buff[CHANNELS], buff[TESTCHANNEL]);
245 255
                         }
246 256
 
247 257
                         foohidSend(buff);

+ 16
- 32
src/protocol.c View File

@@ -22,15 +22,9 @@
22 22
 #define CHECKSUMBYTES 2
23 23
 #define PAYLOADBYTES (PACKETSIZE - HEADERBYTES - CHECKSUMBYTES)
24 24
 #define CHANNELS 6
25
-
26
-/*
27 25
 #define TESTCHANNEL 2
28
-#define TESTCHANNELVALUE 2044
29
-*/
30 26
 
31 27
 static int running = 1;
32
-static int firstPrint = 0;
33
-static int extraLine = 0;
34 28
 
35 29
 static void signalHandler(int signo) {
36 30
     running = 0;
@@ -42,6 +36,8 @@ int main(int argc, char* argv[]) {
42 36
         return 1;
43 37
     }
44 38
 
39
+    printf("Opening serial port...\n");
40
+
45 41
     int fd = serialOpen(argv[1], BAUDRATE);
46 42
     if (fd == -1) {
47 43
         return 1;
@@ -90,45 +86,32 @@ int main(int argc, char* argv[]) {
90 86
                     }
91 87
 
92 88
                     if (checksum != ((checksumData[0] << 8) | checksumData[1])) {
93
-                        printf("Wrong checksum: %d != %d                    \n",
89
+                        printf("Wrong checksum: %d != %d\n",
94 90
                                checksum, ((checksumData[0] << 8) | checksumData[1]));
95
-                        extraLine++;
96
-                        if (extraLine > 1) {
97
-                            extraLine--;
98
-                            printf("\r\033[1A");
99
-                        }
100 91
                     } else {
101 92
                         // Decode channel values
102 93
                         uint16_t buff[CHANNELS + 1];
103 94
                         for (int i = 0; i < (CHANNELS + 1); i++) {
104 95
                             buff[i] = data[2 * i] << 8;
105 96
                             buff[i] |= data[(2 * i) + 1];
106
-                        }
107 97
 
108
-                        /*
109
-                        // Check Test Channel Value (?)
110
-                        if (buff[CHANNELS] != (TESTCHANNELVALUE - buff[TESTCHANNEL])) {
111
-                            printf("Wrong test channel value: %d != %d (%d - %d)\n",
112
-                                   buff[CHANNELS], TESTCHANNELVALUE - buff[TESTCHANNEL],
113
-                                   TESTCHANNELVALUE, buff[TESTCHANNEL]);
98
+                            if (i < CHANNELS) {
99
+                                buff[i] -= 1000;
100
+                            }
101
+                        }
114 102
 
115
-                            printf("Correct would be: %d\n",
116
-                                   buff[TESTCHANNEL] + buff[CHANNELS]);
103
+                        // Check Test Channel Value
104
+                        if (buff[CHANNELS] != buff[TESTCHANNEL]) {
105
+                            printf("Wrong test channel value: %d != %d\n",
106
+                                   buff[CHANNELS], buff[TESTCHANNEL]);
117 107
                         }
118
-                        */
119
-
120
-                        if (firstPrint == 0) {
121
-                            firstPrint = 1;
122
-                        } else {
123
-                            int num = CHANNELS + extraLine;
124
-                            extraLine = 0;
125
-                            for (int i = 0; i < num; i++) {
126
-                                printf("\r\033[1A");
127
-                            }
108
+
109
+                        for (int i = 0; i < CHANNELS; i++) {
110
+                            printf("CH%d: %d\n", i + 1, buff[i]);
128 111
                         }
129 112
 
130 113
                         for (int i = 0; i < CHANNELS; i++) {
131
-                            printf("CH%d: %d                    \n", i + 1, buff[i] - 1000);
114
+                            printf("\r\033[1A");
132 115
                         }
133 116
                     }
134 117
                 }
@@ -138,6 +121,7 @@ int main(int argc, char* argv[]) {
138 121
         usleep(1000);
139 122
     }
140 123
 
124
+    printf("Closing serial port...                    \n");
141 125
     serialClose(fd);
142 126
 
143 127
     return 0;

Loading…
Cancel
Save