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