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
 
7
 
8
 CFLAGS ?= -Wall -pedantic -std=c11
8
 CFLAGS ?= -Wall -pedantic -std=c11
9
 
9
 
10
-ifneq ("$(wildcard /Library/Extensions/foohid.kext/Contents/Info.plist)","")
11
 all: bin/protocol bin/foohid
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
 bin/protocol: src/serial.o src/protocol.o
16
 bin/protocol: src/serial.o src/protocol.o
18
 	@mkdir -p bin
17
 	@mkdir -p bin

+ 15
- 5
src/foohid.c View File

25
 #define CHECKSUMBYTES 2
25
 #define CHECKSUMBYTES 2
26
 #define PAYLOADBYTES (PACKETSIZE - HEADERBYTES - CHECKSUMBYTES)
26
 #define PAYLOADBYTES (PACKETSIZE - HEADERBYTES - CHECKSUMBYTES)
27
 #define CHANNELS 6
27
 #define CHANNELS 6
28
+#define TESTCHANNEL 2
28
 #define CHANNELMAXIMUM 1022
29
 #define CHANNELMAXIMUM 1022
29
 
30
 
30
 #define FOOHID_NAME "it_unbit_foohid"
31
 #define FOOHID_NAME "it_unbit_foohid"
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
     gamepad.aux1 = data[4] - 511;
147
     gamepad.aux1 = data[4] - 511;
147
     gamepad.aux2 = data[5] - 511;
148
     gamepad.aux2 = data[5] - 511;
148
 
149
 
241
                         for (int i = 0; i < (CHANNELS + 1); i++) {
242
                         for (int i = 0; i < (CHANNELS + 1); i++) {
242
                             buff[i] = data[2 * i] << 8;
243
                             buff[i] = data[2 * i] << 8;
243
                             buff[i] |= data[(2 * i) + 1];
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
                         foohidSend(buff);
257
                         foohidSend(buff);

+ 16
- 32
src/protocol.c View File

22
 #define CHECKSUMBYTES 2
22
 #define CHECKSUMBYTES 2
23
 #define PAYLOADBYTES (PACKETSIZE - HEADERBYTES - CHECKSUMBYTES)
23
 #define PAYLOADBYTES (PACKETSIZE - HEADERBYTES - CHECKSUMBYTES)
24
 #define CHANNELS 6
24
 #define CHANNELS 6
25
-
26
-/*
27
 #define TESTCHANNEL 2
25
 #define TESTCHANNEL 2
28
-#define TESTCHANNELVALUE 2044
29
-*/
30
 
26
 
31
 static int running = 1;
27
 static int running = 1;
32
-static int firstPrint = 0;
33
-static int extraLine = 0;
34
 
28
 
35
 static void signalHandler(int signo) {
29
 static void signalHandler(int signo) {
36
     running = 0;
30
     running = 0;
42
         return 1;
36
         return 1;
43
     }
37
     }
44
 
38
 
39
+    printf("Opening serial port...\n");
40
+
45
     int fd = serialOpen(argv[1], BAUDRATE);
41
     int fd = serialOpen(argv[1], BAUDRATE);
46
     if (fd == -1) {
42
     if (fd == -1) {
47
         return 1;
43
         return 1;
90
                     }
86
                     }
91
 
87
 
92
                     if (checksum != ((checksumData[0] << 8) | checksumData[1])) {
88
                     if (checksum != ((checksumData[0] << 8) | checksumData[1])) {
93
-                        printf("Wrong checksum: %d != %d                    \n",
89
+                        printf("Wrong checksum: %d != %d\n",
94
                                checksum, ((checksumData[0] << 8) | checksumData[1]));
90
                                checksum, ((checksumData[0] << 8) | checksumData[1]));
95
-                        extraLine++;
96
-                        if (extraLine > 1) {
97
-                            extraLine--;
98
-                            printf("\r\033[1A");
99
-                        }
100
                     } else {
91
                     } else {
101
                         // Decode channel values
92
                         // Decode channel values
102
                         uint16_t buff[CHANNELS + 1];
93
                         uint16_t buff[CHANNELS + 1];
103
                         for (int i = 0; i < (CHANNELS + 1); i++) {
94
                         for (int i = 0; i < (CHANNELS + 1); i++) {
104
                             buff[i] = data[2 * i] << 8;
95
                             buff[i] = data[2 * i] << 8;
105
                             buff[i] |= data[(2 * i) + 1];
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
                         for (int i = 0; i < CHANNELS; i++) {
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
         usleep(1000);
121
         usleep(1000);
139
     }
122
     }
140
 
123
 
124
+    printf("Closing serial port...                    \n");
141
     serialClose(fd);
125
     serialClose(fd);
142
 
126
 
143
     return 0;
127
     return 0;

Loading…
Cancel
Save