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