Rev 486 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 486 | Rev 488 | ||
---|---|---|---|
1 | /************************************************** |
1 | /************************************************** |
2 | * |
2 | * |
3 | * |
3 | * |
4 | * Riddim |
4 | * Riddim |
5 | * Remote Interactive Digital Drone Interface Mashup |
5 | * Remote Interactive Digital Drone Interface Mashup |
6 | * |
6 | * |
7 | * 2007-2008 Marcus -LiGi- Bueschleb |
7 | * 2007-2008 Marcus -LiGi- Bueschleb |
8 | * |
8 | * |
9 | * |
9 | * |
10 | **************************************************/ |
10 | **************************************************/ |
11 | 11 | ||
12 | #include "riddim.h" |
12 | #include "riddim.h" |
13 | 13 | ||
14 | 14 | ||
15 | int state=STATEID_SCANNING; |
15 | int state=STATEID_SCANNING; |
16 | 16 | ||
17 | 17 | ||
18 | struct js_event x52_event_struct; |
18 | struct js_event x52_event_struct; |
19 | 19 | ||
20 | int engines_on=0; |
20 | int engines_on=0; |
21 | int old_engines_on=0; |
21 | int old_engines_on=0; |
22 | 22 | ||
23 | int *axis; |
23 | int *axis; |
24 | char *button; |
24 | char *button; |
25 | 25 | ||
26 | struct x52 *x52_output; |
26 | struct x52 *x52_output; |
27 | 27 | ||
28 | int selected_bt_device=0; |
28 | int selected_bt_device=0; |
29 | 29 | ||
30 | void write_display(int line,char* text) |
30 | void write_display(int line,char* text) |
31 | { |
31 | { |
32 | if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
32 | if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
33 | } |
33 | } |
34 | 34 | ||
35 | void clear_display() |
35 | void clear_display() |
36 | { |
36 | { |
37 | write_display(0,""); |
37 | write_display(0,""); |
38 | write_display(1,""); |
38 | write_display(1,""); |
39 | write_display(2,""); |
39 | write_display(2,""); |
40 | } |
40 | } |
41 | 41 | ||
42 | 42 | ||
43 | void output_device_list() |
43 | void output_device_list() |
44 | { |
44 | { |
45 | int i; |
45 | int i; |
46 | char disp_txt[20]; |
46 | char disp_txt[20]; |
47 | for(i=0;i<bt_device_count;i++) |
47 | for(i=0;i<bt_device_count;i++) |
48 | { |
48 | { |
49 | if (i<3) |
49 | if (i<3) |
50 | { |
50 | { |
51 | 51 | ||
52 | if (selected_bt_device==i) |
52 | if (selected_bt_device==i) |
53 | sprintf(disp_txt,"#%s",names[i]); |
53 | sprintf(disp_txt,"#%s",names[i]); |
54 | else |
54 | else |
55 | sprintf(disp_txt," %s",names[i]); |
55 | sprintf(disp_txt," %s",names[i]); |
56 | write_display(i,disp_txt); |
56 | write_display(i,disp_txt); |
57 | } |
57 | } |
58 | } |
58 | } |
59 | } |
59 | } |
60 | 60 | ||
61 | 61 | ||
62 | void print_device_list() |
62 | void print_device_list() |
63 | { |
63 | { |
64 | int i; |
64 | int i; |
65 | for(i=0;i<bt_device_count;i++) |
65 | for(i=0;i<bt_device_count;i++) |
66 | printf("device%i->%s\n",i,names[i]); |
66 | printf("device%i->%s\n",i,names[i]); |
67 | } |
67 | } |
68 | 68 | ||
69 | 69 | ||
70 | 70 | ||
71 | int count=0; |
71 | int count=0; |
72 | int connected=0; |
72 | int connected=0; |
73 | 73 | ||
74 | 74 | ||
75 | int input=INPUT_NONE; |
75 | int input=INPUT_NONE; |
76 | 76 | ||
77 | 77 | ||
78 | 78 | ||
79 | int main(int argc, char**argv) |
79 | int main(int argc, char**argv) |
80 | { |
80 | { |
81 | 81 | ||
82 | printf("Starting Riddim %d.%d \n",RIDDIM_VERSION_MAJOR,RIDDIM_VERSION_MINOR ); |
82 | printf("Starting Riddim %d.%d \n",RIDDIM_VERSION_MAJOR,RIDDIM_VERSION_MINOR ); |
83 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
83 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
84 | printf("\nusage:\n"); |
84 | printf("\nusage:\n"); |
85 | printf("\t riddim [config_file]\n\n"); |
85 | printf("\t riddim [config_file]\n\n"); |
86 | 86 | ||
87 | 87 | ||
88 | 88 | ||
89 | 89 | ||
90 | 90 | ||
91 | // bt_host_init(); |
91 | // bt_host_init(); |
92 | 92 | ||
93 | if (argv[1]) |
93 | if (argv[1]) |
94 | parse_config(argv[1]); |
94 | parse_config(argv[1]); |
95 | else |
95 | else |
96 | parse_config("/etc/riddim.conf"); |
96 | parse_config("/etc/riddim.conf"); |
97 | 97 | ||
98 | 98 | ||
99 | collect_evdev_devices(); |
99 | collect_evdev_devices(); |
100 | parse_config_input_sections(); |
100 | parse_config_input_sections(); |
101 | // exit(0); |
101 | // exit(0); |
102 | 102 | ||
103 | printf("input %s:\n",input_evdev_name); |
103 | printf("input %s:\n",input_evdev_name); |
104 | /* |
104 | /* |
105 | if (bluetooth_mac) |
105 | if (bluetooth_mac) |
106 | { |
106 | { |
107 | 107 | ||
108 | printf("Connecting via Bluetooth to %s\n",bluetooth_mac); |
108 | printf("Connecting via Bluetooth to %s\n",bluetooth_mac); |
109 | if (connect_mk_bluetooth(bluetooth_mac));; |
109 | if (connect_mk_bluetooth(bluetooth_mac));; |
110 | connected=TRUE; |
110 | connected=TRUE; |
111 | } |
111 | } |
112 | */ |
112 | */ |
113 | 113 | ||
114 | if (mk_tty) |
114 | if (mk_tty) |
115 | { |
115 | { |
116 | printf("connecting to mk via tty: %s\n",mk_tty); |
116 | printf("connecting to mk via tty: %s\n",mk_tty); |
117 | if (!connect_mk_tty(mk_tty)) |
117 | if (!connect_mk_tty(mk_tty)) |
118 | printf("cant connect !!"); |
118 | printf("cant connect !!"); |
119 | else |
119 | else |
120 | { |
120 | { |
121 | printf("connected !-)"); |
121 | printf("connected !-)"); |
122 | connected=TRUE; |
122 | connected=TRUE; |
123 | } |
123 | } |
124 | } |
124 | } |
125 | 125 | ||
126 | if (mk_socket_port) |
126 | if (mk_socket_port) |
127 | { |
127 | { |
128 | printf("connecting to mk via local port: %i\n",mk_socket_port); |
128 | printf("connecting to mk via local port: %i\n",mk_socket_port); |
129 | 129 | ||
130 | if (connect_mk_localhost_socket(mk_socket_port)==-1) |
130 | if (connect_mk_localhost_socket(mk_socket_port)==-1) |
131 | printf("cant connect !!"); |
131 | printf("cant connect !!"); |
132 | else |
132 | else |
133 | { |
133 | { |
134 | printf("connected !-)"); |
134 | printf("connected !-)"); |
135 | connected=TRUE; |
135 | connected=TRUE; |
136 | } |
136 | } |
137 | } |
137 | } |
138 | 138 | ||
139 | // todo reenable bluetooth connection |
139 | // todo reenable bluetooth connection |
140 | 140 | ||
141 | connect_evdev(); |
141 | connect_evdev(); |
142 | 142 | ||
143 | /* |
143 | /* |
144 | if ((input_evdev_name)) |
144 | if ((input_evdev_name)) |
145 | { |
145 | { |
146 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
146 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
147 | |
147 | |
148 | if (connect_evdev(input_evdev_name)) |
148 | if (connect_evdev(input_evdev_name)) |
149 | { |
149 | { |
150 | printf(".. done");// |
150 | printf(".. done");// |
151 | input=INPUT_EVDEV; |
151 | input=INPUT_EVDEV; |
152 | } |
152 | } |
153 | else |
153 | else |
154 | printf(".. ERROR ");// |
154 | printf(".. ERROR ");// |
155 | } |
155 | } |
156 | */ |
156 | */ |
157 | if (input_joydev_name) |
157 | if (input_joydev_name) |
158 | { |
158 | { |
159 | printf("\nInitializing joystick input from %s ..\n",input_joydev_name); |
159 | printf("\nInitializing joystick input from %s ..\n",input_joydev_name); |
160 | if (connect_joy()) |
160 | if (connect_joy()) |
161 | { |
161 | { |
162 | printf(".. done");// |
162 | printf(".. done");// |
163 | input=INPUT_JOYDEV; |
163 | input=INPUT_JOYDEV; |
164 | } |
164 | } |
165 | else |
165 | else |
166 | printf(".. ERROR ");// |
166 | printf(".. ERROR ");// |
167 | } |
167 | } |
168 | 168 | ||
169 | 169 | ||
170 | printf("\nInitializing X-52 output .."); |
170 | printf("\nInitializing X-52 output .."); |
171 | 171 | ||
172 | x52_output = x52_init(); |
172 | x52_output = x52_init(); |
173 | 173 | ||
174 | clear_display(); |
174 | clear_display(); |
175 | 175 | ||
176 | write_display(0, "RIDDIM active"); |
176 | write_display(0, "RIDDIM active"); |
177 | 177 | ||
178 | if (x52_output) x52_setbri(x52_output, 1,128); |
178 | if (x52_output) x52_setbri(x52_output, 1,128); |
179 | if (x52_output) |
179 | if (x52_output) |
180 | printf(" done \n"); |
180 | printf(" done \n"); |
181 | else |
181 | else |
182 | printf(" not found \n"); |
182 | printf(" not found \n"); |
183 | 183 | ||
184 | /* |
184 | /* |
185 | if (!connected) |
185 | if (!connected) |
186 | { |
186 | { |
187 | printf("Scanning for Bluetooth Devices ..\n"); |
187 | printf("Scanning for Bluetooth Devices ..\n"); |
188 | write_display(1,"Bluetooth Scan"); |
188 | write_display(1,"Bluetooth Scan"); |
189 | scan_bt(); |
189 | scan_bt(); |
190 | printf(" done \n"); |
190 | printf(" done \n"); |
191 | printf(" %d Devices found \n",bt_device_count); |
191 | printf(" %d Devices found \n",bt_device_count); |
192 | print_device_list() ; |
192 | print_device_list() ; |
193 | } |
193 | } |
194 | */ |
194 | */ |
195 | 195 | ||
196 | // int v_old; |
196 | // int v_old; |
197 | int polls=0; |
197 | int polls=0; |
198 | 198 | ||
199 | 199 | ||
200 | if (exit_after_init) |
200 | if (exit_after_init) |
201 | exit(0); |
201 | exit(0); |
202 | printf("starting loop ..\n"); |
202 | printf("starting loop ..\n"); |
203 | 203 | ||
204 | 204 | ||
205 | 205 | ||
206 | int complete_misses=0; |
206 | int complete_misses=0; |
207 | int complete_matches=0; |
207 | int complete_matches=0; |
208 | 208 | ||
209 | 209 | ||
210 | int confirm_misses; |
210 | int confirm_misses; |
211 | 211 | ||
212 | 212 | ||
213 | 213 | ||
214 | // init_evdevstatus_led(); |
214 | // init_evdevstatus_led(); |
215 | 215 | ||
216 | while( TRUE ) |
216 | while( TRUE ) |
217 | { |
217 | { |
218 | 218 | ||
219 | // blink_evdev_led(); |
219 | // blink_evdev_led(); |
220 | // bt_host_tick(mk_socket); |
220 | // bt_host_tick(mk_socket); |
221 | usleep(loop_delay); |
221 | usleep(loop_delay); |
222 | 222 | ||
223 | 223 | ||
224 | 224 | ||
225 | poll_evdev(); |
225 | poll_evdev(); |
226 | 226 | ||
227 | switch (input) |
227 | switch (input) |
228 | { |
228 | { |
229 | 229 | ||
230 | 230 | ||
231 | case INPUT_NONE: |
231 | case INPUT_NONE: |
232 | printf("processing input none\n"); |
232 | printf("processing input none\n"); |
233 | break; |
233 | break; |
234 | 234 | ||
235 | case INPUT_EVDEV: |
235 | case INPUT_EVDEV: |
236 | printf("processing input evdev\n"); |
236 | printf("processing input evdev\n"); |
237 | 237 | ||
238 | 238 | ||
239 | break; |
239 | break; |
240 | 240 | ||
241 | case INPUT_JOYDEV: |
241 | case INPUT_JOYDEV: |
242 | printf("processing input joydev\n"); |
242 | printf("processing input joydev\n"); |
243 | // poll values from input device |
243 | // poll values from input device |
244 | 244 | ||
245 | for (polls=0;polls<100;polls++) // FIXME - better Polling |
245 | for (polls=0;polls<100;polls++) // FIXME - better Polling |
246 | { |
246 | { |
247 | read(joy_input_fd, &x52_event_struct, sizeof(struct js_event)); |
247 | read(joy_input_fd, &x52_event_struct, sizeof(struct js_event)); |
248 | 248 | ||
249 | 249 | ||
250 | /* see what to do with the event */ |
250 | /* see what to do with the event */ |
251 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
251 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
252 | { |
252 | { |
253 | case JS_EVENT_AXIS: |
253 | case JS_EVENT_AXIS: |
254 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
254 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
255 | break; |
255 | break; |
256 | case JS_EVENT_BUTTON: |
256 | case JS_EVENT_BUTTON: |
257 | button [ x52_event_struct.number ] = x52_event_struct.value; |
257 | button [ x52_event_struct.number ] = x52_event_struct.value; |
258 | break; |
258 | break; |
259 | } |
259 | } |
260 | } |
260 | } |
261 | int x; |
261 | int x; |
262 | for( x=0 ; x<num_of_buttons ; ++x ) |
262 | for( x=0 ; x<num_of_buttons ; ++x ) |
263 | if( button[x]==0) |
263 | if( button[x]==0) |
264 | button_trigger[x]=0; |
264 | button_trigger[x]=0; |
265 | else |
265 | else |
266 | { |
266 | { |
267 | if (button_trigger[x]<100)button_trigger[x]++; |
267 | if (button_trigger[x]<100)button_trigger[x]++; |
268 | } |
268 | } |
269 | break; |
269 | break; |
270 | } // switch (input) |
270 | } // switch (input) |
271 | 271 | ||
272 | printf("input done\n"); |
272 | printf("input done\n"); |
273 | 273 | ||
274 | switch(state) |
274 | switch(state) |
275 | { |
275 | { |
276 | case STATEID_SCANNING: |
276 | case STATEID_SCANNING: |
277 | 277 | ||
278 | state=STATEID_CONNECTING; |
278 | state=STATEID_CONNECTING; |
279 | /* |
279 | /* |
280 | ExternControl.Digital[0]=0; |
280 | ExternControl.Digital[0]=0; |
281 | ExternControl.Digital[1]=0; |
281 | ExternControl.Digital[1]=0; |
282 | ExternControl.RemoteTasten=0; |
282 | ExternControl.RemoteTasten=0; |
283 | ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
283 | ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
284 | 284 | ||
285 | printf("nick%d\n",ExternControl.Nick); |
285 | printf("nick%d\n",ExternControl.Nick); |
286 | ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
286 | ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
287 | ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
287 | ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
288 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
288 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
289 | ExternControl.Higt=0; |
289 | ExternControl.Higt=0; |
290 | ExternControl.free=0; |
290 | ExternControl.free=0; |
291 | ExternControl.Frame='t'; |
291 | ExternControl.Frame='t'; |
292 | ExternControl.Config=1; |
292 | ExternControl.Config=1; |
293 | 293 | ||
294 | printf("sending data\n"); |
294 | printf("sending data\n"); |
295 | 295 | ||
296 | |
296 | |
297 | if (connected)SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
297 | if (connected)SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
298 | gettimeofday(&time_struct1,NULL); |
298 | gettimeofday(&time_struct1,NULL); |
299 | 299 | ||
300 | if (button_trigger[BUTTON_SELECT]==1) |
300 | if (button_trigger[BUTTON_SELECT]==1) |
301 | { |
301 | { |
302 | state=STATEID_CONNECTING; |
302 | state=STATEID_CONNECTING; |
303 | clear_display(); |
303 | clear_display(); |
304 | write_display(0,"connecting to"); |
304 | write_display(0,"connecting to"); |
305 | write_display(1,names[selected_bt_device]); |
305 | write_display(1,names[selected_bt_device]); |
306 | //connect_mk(addrs[selected_bt_device]); |
306 | //connect_mk(addrs[selected_bt_device]); |
307 | write_display(0,"connected to"); |
307 | write_display(0,"connected to"); |
308 | } |
308 | } |
309 | |
309 | |
310 | if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1) |
310 | if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1) |
311 | { |
311 | { |
312 | printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]); |
312 | printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]); |
313 | if (button_trigger[BUTTON_DOWN]==1) |
313 | if (button_trigger[BUTTON_DOWN]==1) |
314 | if (selected_bt_device>0) selected_bt_device--; |
314 | if (selected_bt_device>0) selected_bt_device--; |
315 | if (button_trigger[BUTTON_UP]==1) |
315 | if (button_trigger[BUTTON_UP]==1) |
316 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
316 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
317 | |
317 | |
318 | 318 | ||
319 | } |
319 | } |
320 | */ |
320 | */ |
321 | break; |
321 | break; |
322 | 322 | ||
323 | case STATEID_CONNECTING: |
323 | case STATEID_CONNECTING: |
324 | 324 | ||
- | 325 | ||
- | 326 | ||
- | 327 | ||
325 | 328 | ||
326 | confirm_misses=0; |
329 | confirm_misses=0; |
327 | 330 | ||
328 | RxBuffer[2]=0; |
331 | RxBuffer[2]=0; |
329 | if (connected) |
332 | if (connected) |
- | 333 | { |
|
- | 334 | read_from_mk(); |
|
- | 335 | if (RxBuffer[2]=='B') |
|
- | 336 | complete_misses++; |
|
330 | while (RxBuffer[2]!='B') |
337 | /*while (RxBuffer[2]!='B') |
331 | { |
338 | { |
332 | 339 | ||
333 | RxBuffer[1]=0; |
340 | RxBuffer[1]=0; |
334 | read_from_mk(); |
341 | read_from_mk(); |
335 | // bt_host_send(RxBuffer,rx_last_length); |
342 | // bt_host_send(RxBuffer,rx_last_length); |
336 | printf("sending to host: %s",PrintableRxBuffer); |
343 | printf("sending to host: %s",PrintableRxBuffer); |
337 | 344 | ||
338 | 345 | ||
339 | // ftime(&time_struct); |
346 | // ftime(&time_struct); |
340 | 347 | ||
341 | printf("waiting for confirm frame ( confirmed:%d misses:%d %c)\n",complete_matches,complete_misses,RxBuffer[2]); |
348 | printf("waiting for confirm frame ( confirmed:%d misses:%d %c)\n",complete_matches,complete_misses,RxBuffer[2]); |
342 | // RxBuffer[2]=0; |
349 | // RxBuffer[2]=0; |
343 | 350 | ||
344 | // r=0; |
351 | // r=0; |
345 | 352 | ||
346 | // new |
353 | // new |
347 | /* |
354 | |
348 | if (button_trigger[12]>1) |
355 | //if (button_trigger[12]>1) |
349 | { |
356 | // { |
350 | SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
357 | // SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
351 | button_trigger[12]=0; |
358 | // button_trigger[12]=0; |
352 | } |
- | |
353 | */ |
359 | // } |
- | 360 | |
|
354 | ExternControl.Frame='t'; |
361 | ExternControl.Frame='t'; |
355 | if (++confirm_misses>4) |
362 | if (++confirm_misses>4) |
356 | { |
363 | { |
357 | complete_misses++; |
364 | complete_misses++; |
358 | printf("sending again\n"); |
365 | printf("sending again\n"); |
359 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
366 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
360 | } |
367 | } |
- | 368 | */ |
|
361 | } |
369 | } |
362 | else |
370 | else |
363 | printf("not connected to mk\n"); |
371 | printf("not connected to mk\n"); |
364 | 372 | ||
365 | gettimeofday(&time_struct2,NULL); |
373 | gettimeofday(&time_struct2,NULL); |
366 | 374 | ||
367 | printf("last trip: %d\n",(int)(time_struct2.tv_usec-time_struct1.tv_usec)); |
375 | printf("last trip: %d\n",(int)(time_struct2.tv_usec-time_struct1.tv_usec)); |
368 | // act_mode=button[24] | (button[25]<<1); |
376 | // act_mode=button[24] | (button[25]<<1); |
369 | 377 | ||
370 | 378 | ||
371 | 379 | ||
372 | // Step converting axis data to nick/roll/gier/gas/.. |
380 | // Step converting axis data to nick/roll/gier/gas/.. |
373 | 381 | ||
374 | // act_nick=(evdev_rel_axis[rel_axis_nick]-128)*nick_mul; |
382 | // act_nick=(evdev_rel_axis[rel_axis_nick]-128)*nick_mul; |
375 | 383 | ||
376 | 384 | ||
377 | 385 | ||
378 | 386 | ||
379 | /* Mix input values */ |
387 | /* Mix input values */ |
380 | 388 | ||
381 | act_gas=0; |
389 | act_gas=0; |
382 | act_nick=0; |
390 | act_nick=0; |
383 | act_roll=0; |
391 | act_roll=0; |
384 | act_gier=0; |
392 | act_gier=0; |
385 | 393 | ||
386 | int act_input=0; |
394 | int act_input=0; |
387 | for (act_input=0;act_input<input_count;act_input++) |
395 | for (act_input=0;act_input<input_count;act_input++) |
388 | { |
396 | { |
389 | //process buttons |
397 | //process buttons |
390 | if (inputs[act_input].nick_up_btn!=-1) |
398 | if (inputs[act_input].nick_up_btn!=-1) |
391 | { |
399 | { |
392 | if (inputs[act_input].evdev_button[inputs[act_input].nick_up_btn]!=0) |
400 | if (inputs[act_input].evdev_button[inputs[act_input].nick_up_btn]!=0) |
393 | act_nick=100; |
401 | act_nick=100; |
394 | 402 | ||
395 | } |
403 | } |
396 | 404 | ||
397 | if (inputs[act_input].nick_down_btn!=-1) |
405 | if (inputs[act_input].nick_down_btn!=-1) |
398 | { |
406 | { |
399 | if (inputs[act_input].evdev_button[inputs[act_input].nick_down_btn]!=0) |
407 | if (inputs[act_input].evdev_button[inputs[act_input].nick_down_btn]!=0) |
400 | act_nick=-100; |
408 | act_nick=-100; |
401 | 409 | ||
402 | } |
410 | } |
403 | 411 | ||
404 | if (inputs[act_input].roll_left_btn!=-1) |
412 | if (inputs[act_input].roll_left_btn!=-1) |
405 | { |
413 | { |
406 | if (inputs[act_input].evdev_button[inputs[act_input].roll_left_btn]!=0) |
414 | if (inputs[act_input].evdev_button[inputs[act_input].roll_left_btn]!=0) |
407 | act_roll=100; |
415 | act_roll=100; |
408 | 416 | ||
409 | } |
417 | } |
410 | 418 | ||
411 | if (inputs[act_input].roll_right_btn!=-1) |
419 | if (inputs[act_input].roll_right_btn!=-1) |
412 | { |
420 | { |
413 | if (inputs[act_input].evdev_button[inputs[act_input].roll_right_btn]!=0) |
421 | if (inputs[act_input].evdev_button[inputs[act_input].roll_right_btn]!=0) |
414 | act_roll=-100; |
422 | act_roll=-100; |
415 | 423 | ||
416 | } |
424 | } |
417 | 425 | ||
418 | // process axis |
426 | // process axis |
419 | 427 | ||
420 | if (inputs[act_input].rel_axis_nick!=-1) |
428 | if (inputs[act_input].rel_axis_nick!=-1) |
421 | act_nick=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_nick]*inputs[act_input].nick_mul; |
429 | act_nick=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_nick]*inputs[act_input].nick_mul; |
422 | 430 | ||
423 | if (inputs[act_input].rel_axis_roll!=-1) |
431 | if (inputs[act_input].rel_axis_roll!=-1) |
424 | act_roll=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_roll]*inputs[act_input].roll_mul; |
432 | act_roll=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_roll]*inputs[act_input].roll_mul; |
425 | 433 | ||
426 | 434 | ||
427 | if (inputs[act_input].rel_axis_gier!=-1) |
435 | if (inputs[act_input].rel_axis_gier!=-1) |
428 | act_gier=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_gier]*inputs[act_input].gier_mul; |
436 | act_gier=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_gier]*inputs[act_input].gier_mul; |
429 | 437 | ||
430 | 438 | ||
431 | if (inputs[act_input].rel_axis_gas!=-1) |
439 | if (inputs[act_input].rel_axis_gas!=-1) |
432 | act_gas=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_gas]*inputs[act_input].gas_mul; |
440 | act_gas=inputs[act_input].evdev_rel_axis[inputs[act_input].rel_axis_gas]*inputs[act_input].gas_mul; |
433 | 441 | ||
434 | 442 | ||
435 | 443 | ||
436 | } |
444 | } |
437 | 445 | ||
438 | switch(input) |
446 | switch(input) |
439 | { |
447 | { |
440 | case INPUT_EVDEV: |
448 | case INPUT_EVDEV: |
441 | /* |
449 | /* |
442 | act_nick=(evdev_rel_axis[rel_axis_nick]-nick_add)*nick_mul; |
450 | act_nick=(evdev_rel_axis[rel_axis_nick]-nick_add)*nick_mul; |
443 | act_roll=(evdev_rel_axis[rel_axis_roll]-nick_add)*roll_mul; |
451 | act_roll=(evdev_rel_axis[rel_axis_roll]-nick_add)*roll_mul; |
444 | act_gier=(evdev_rel_axis[rel_axis_gier]-nick_add)*gier_mul; |
452 | act_gier=(evdev_rel_axis[rel_axis_gier]-nick_add)*gier_mul; |
445 | act_gas=(evdev_rel_axis[rel_axis_gas]-nick_add)*gas_mul; |
453 | act_gas=(evdev_rel_axis[rel_axis_gas]-nick_add)*gas_mul; |
446 | */ |
454 | */ |
447 | 455 | ||
448 | break; |
456 | break; |
449 | 457 | ||
450 | case INPUT_JOYDEV: |
458 | case INPUT_JOYDEV: |
451 | act_nick=(axis[rel_axis_nick])*nick_mul; |
459 | act_nick=(axis[rel_axis_nick])*nick_mul; |
452 | act_roll=(axis[rel_axis_roll])*roll_mul; |
460 | act_roll=(axis[rel_axis_roll])*roll_mul; |
453 | act_gier=(axis[rel_axis_gier])*gier_mul; |
461 | act_gier=(axis[rel_axis_gier])*gier_mul; |
454 | act_gas=(axis[rel_axis_gas]*-1+33000)*gas_mul; |
462 | act_gas=(axis[rel_axis_gas]*-1+33000)*gas_mul; |
455 | 463 | ||
456 | break; |
464 | break; |
457 | } |
465 | } |
458 | 466 | ||
459 | // act values clipping to usefull vals |
467 | // act values clipping to usefull vals |
460 | // act_gas=0; |
468 | // act_gas=0; |
461 | 469 | ||
462 | // act_gas=255; |
470 | // act_gas=255; |
463 | 471 | ||
464 | 472 | ||
465 | /* |
473 | /* |
466 | switch (act_mode) |
474 | switch (act_mode) |
467 | { |
475 | { |
468 | case 0: |
476 | case 0: |
469 | 477 | ||
470 | 478 | ||
471 | act_nick=(axis[AXIS_NICK])*(INVERT_NICK); |
479 | act_nick=(axis[AXIS_NICK])*(INVERT_NICK); |
472 | act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL); |
480 | act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL); |
473 | act_gier=(axis[AXIS_GIER])*(INVERT_GIER); |
481 | act_gier=(axis[AXIS_GIER])*(INVERT_GIER); |
474 | act_gas=((axis[AXIS_GAS])-128)*(-1); |
482 | act_gas=((axis[AXIS_GAS])-128)*(-1); |
475 | |
483 | |
476 | // clip gas |
484 | // clip gas |
477 | if (act_gas<0) act_gas=0; |
485 | if (act_gas<0) act_gas=0; |
478 | 486 | ||
479 | if (act_gas>250) act_gas=250; |
487 | if (act_gas>250) act_gas=250; |
480 | 488 | ||
481 | //////// act_gas=0; |
489 | //////// act_gas=0; |
482 | break; |
490 | break; |
483 | 491 | ||
484 | case 1: |
492 | case 1: |
485 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
493 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
486 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
494 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
487 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
495 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
488 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
496 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
489 | 497 | ||
490 | break; |
498 | break; |
491 | |
499 | |
492 | case 2: |
500 | case 2: |
493 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
501 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
494 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
502 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
495 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
503 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
496 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
504 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
497 | 505 | ||
498 | 506 | ||
499 | break; |
507 | break; |
500 | 508 | ||
501 | } |
509 | } |
502 | */ |
510 | */ |
503 | ExternControl.Digital[0]=0; |
511 | ExternControl.Digital[0]=0; |
504 | ExternControl.Digital[1]=0; |
512 | ExternControl.Digital[1]=0; |
505 | ExternControl.RemoteTasten=0; |
513 | ExternControl.RemoteTasten=0; |
506 | ExternControl.Higt=0; |
514 | ExternControl.Higt=0; |
507 | ExternControl.free=0; |
515 | ExternControl.free=0; |
508 | ExternControl.Frame='t'; |
516 | ExternControl.Frame='t'; |
509 | ExternControl.Config=1; |
517 | ExternControl.Config=1; |
510 | 518 | ||
511 | 519 | ||
512 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
520 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
513 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
521 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
514 | ExternControl.Gier=act_gier; // ************ |
522 | ExternControl.Gier=act_gier; // ************ |
515 | ExternControl.Gas=act_gas; // ************ |
523 | ExternControl.Gas=act_gas; // ************ |
516 | ExternControl.Gas=255; // ************ |
524 | ExternControl.Gas=255; // ************ |
517 | 525 | ||
518 | 526 | ||
519 | 527 | ||
520 | printf("act_mode %d , act_nick %d , act_roll %d , act_gier %d , act_gas %d",act_mode , act_nick , act_roll , act_gier , act_gas); |
528 | printf("act_mode %d , act_nick %d , act_roll %d , act_gier %d , act_gas %d",act_mode , act_nick , act_roll , act_gier , act_gas); |
521 | 529 | ||
522 | if (connected) |
530 | if (connected) |
523 | { |
531 | { |
524 | complete_matches++; |
532 | complete_matches++; |
525 | printf("sending data\n"); |
533 | printf("sending data\n"); |
526 | 534 | ||
527 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
535 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
528 | gettimeofday(&time_struct1,NULL); |
536 | gettimeofday(&time_struct1,NULL); |
529 | printf("sent data\n"); |
537 | printf("sent data\n"); |
530 | } |
538 | } |
531 | 539 | ||
532 | // printf("sleeping\n"); |
540 | // printf("sleeping\n"); |
533 | // for (polls=0;polls<100;polls++) // FIXME - better Polling |
541 | // for (polls=0;polls<100;polls++) // FIXME - better Polling |
534 | // printf("end_sleep\n"); |
542 | // printf("end_sleep\n"); |
535 | 543 | ||
536 | // int v=axis[6]/655+50; |
544 | // int v=axis[6]/655+50; |
537 | // if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
545 | // if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
538 | // v_old=v; |
546 | // v_old=v; |
539 | 547 | ||
540 | // printf("v: %d \n",v); |
548 | // printf("v: %d \n",v); |
541 | 549 | ||
542 | 550 | ||
543 | /* |
551 | /* |
544 | for (i=0;i<num_of_axis;i++) |
552 | for (i=0;i<num_of_axis;i++) |
545 | printf("A%d: %d ", i,axis[i]>>8 ); |
553 | printf("A%d: %d ", i,axis[i]>>8 ); |
546 | |
554 | |
547 | for( x=0 ; x<num_of_buttons ; ++x ) |
555 | for( x=0 ; x<num_of_buttons ; ++x ) |
548 | |
556 | |
549 | printf("B%d: %d ", x, button[x] ); |
557 | printf("B%d: %d ", x, button[x] ); |
550 | */ |
558 | */ |
551 | 559 | ||
552 | break; |
560 | break; |
553 | } |
561 | } |
554 | 562 | ||
555 | printf("\n"); |
563 | printf("\n"); |
556 | fflush(stdout); |
564 | fflush(stdout); |
557 | printf("loop fin ( confirmed:%d misses:%d | debug_sets:%d )\n",complete_matches,complete_misses,debug_sets); |
565 | printf("loop fin ( confirmed:%d misses:%d | debug_sets:%d )\n",complete_matches,complete_misses,debug_sets); |
558 | printf("------------------------------------------------------------------------\n"); |
566 | printf("------------------------------------------------------------------------\n"); |
559 | 567 | ||
560 | } |
568 | } |
561 | 569 | ||
562 | 570 | ||
563 | /******************** Cleanup **********************/ |
571 | /******************** Cleanup **********************/ |
564 | close(joy_input_fd); |
572 | close(joy_input_fd); |
565 | close(mk_socket); |
573 | close(mk_socket); |
566 | 574 | ||
567 | if (x52_output) x52_close(x52_output); |
575 | if (x52_output) x52_close(x52_output); |
568 | return 0; |
576 | return 0; |
569 | } |
577 | } |
570 | 578 |