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