Rev 48 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 48 | Rev 50 | ||
---|---|---|---|
Line 7... | Line 7... | ||
7 | #include <sys/socket.h> |
7 | #include <sys/socket.h> |
8 | #include <bluetooth/bluetooth.h> |
8 | #include <bluetooth/bluetooth.h> |
9 | #include <bluetooth/hci.h> |
9 | #include <bluetooth/hci.h> |
10 | #include <bluetooth/hci_lib.h> |
10 | #include <bluetooth/hci_lib.h> |
Line -... | Line 11... | ||
- | 11 | ||
- | 12 | #include <sys/time.h> |
|
Line 11... | Line 13... | ||
11 | 13 | ||
Line 12... | Line 14... | ||
12 | 14 | ||
Line 24... | Line 26... | ||
24 | 26 | ||
25 | #define BUTTON_SELECT 26 |
27 | #define BUTTON_SELECT 26 |
26 | #define BUTTON_DOWN 28 |
28 | #define BUTTON_DOWN 28 |
Line -... | Line 29... | ||
- | 29 | #define BUTTON_UP 27 |
|
- | 30 | ||
- | 31 | ||
- | 32 | #define AXIS_ROLL 0 |
|
- | 33 | #define AXIS_NICK 1 |
|
- | 34 | #define AXIS_GIER 5 |
|
- | 35 | #define AXIS_GAS 2 |
|
- | 36 | ||
- | 37 | #define INVERT_ROLL -1 |
|
- | 38 | #define INVERT_NICK -1 |
|
- | 39 | #define INVERT_GIER 1 |
|
- | 40 | #define INVERT_GAS -1 |
|
- | 41 | ||
- | 42 | ||
- | 43 | // time struct for measuring |
|
- | 44 | struct timeval time_struct1; |
|
- | 45 | struct timeval time_struct2; |
|
- | 46 | ||
- | 47 | ||
- | 48 | int act_nick=0; |
|
- | 49 | int act_roll=0; |
|
- | 50 | int act_gier=0; |
|
- | 51 | int act_gas=0; |
|
27 | #define BUTTON_UP 27 |
52 | int act_mode=0; |
Line 28... | Line 53... | ||
28 | 53 | ||
29 | int bt_device_count=0; |
54 | int bt_device_count=0; |
Line 41... | Line 66... | ||
41 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
66 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
42 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
67 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
Line 43... | Line 68... | ||
43 | 68 | ||
Line 44... | Line -... | ||
44 | struct js_event x52_event_struct; |
- | |
45 | 69 | struct js_event x52_event_struct; |
|
46 | 70 | ||
Line 47... | Line 71... | ||
47 | int engines_on=0; |
71 | int engines_on=0; |
Line 48... | Line -... | ||
48 | int old_engines_on=0; |
- | |
49 | - | ||
50 | char in_char; |
- | |
51 | 72 | int old_engines_on=0; |
|
52 | struct |
- | |
53 | { |
- | |
54 | char val[4]; |
73 | |
55 | } MotortestParam; |
74 | char in_char; |
56 | 75 | ||
57 | struct |
76 | struct ExternControl_s |
58 | { |
77 | { |
Line 64... | Line 83... | ||
64 | unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
83 | unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
65 | signed char Higt; //(Höhenregler) |
84 | signed char Higt; //(Höhenregler) |
66 | unsigned char free; // (unbenutzt) |
85 | unsigned char free; // (unbenutzt) |
67 | unsigned char Frame; // (Bestätigung) |
86 | unsigned char Frame; // (Bestätigung) |
68 | unsigned char Config; |
87 | unsigned char Config; |
69 | } ExternControl; |
88 | }; |
Line -... | Line 89... | ||
- | 89 | ||
Line 70... | Line 90... | ||
70 | 90 | ||
Line 71... | Line 91... | ||
71 | 91 | struct ExternControl_s ExternControl ; |
|
Line 118... | Line 138... | ||
118 | free( ii ); |
138 | free( ii ); |
119 | close( sock ); |
139 | close( sock ); |
120 | } |
140 | } |
Line 121... | Line 141... | ||
121 | 141 | ||
122 | 142 | ||
Line 123... | Line 143... | ||
123 | void connect_joy() |
143 | int connect_joy() |
124 | { |
144 | { |
125 | 145 | ||
- | 146 | ||
126 | 147 | if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
|
127 | if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
148 | { |
Line 128... | Line 149... | ||
128 | { |
149 | printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
129 | printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
150 | printf( "try modprobe joydev\n" ); |
130 | return ; |
151 | return 0; |
Line 143... | Line 164... | ||
143 | , num_of_axis |
164 | , num_of_axis |
144 | , num_of_buttons ); |
165 | , num_of_buttons ); |
Line 145... | Line 166... | ||
145 | 166 | ||
Line -... | Line 167... | ||
- | 167 | fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */ |
|
146 | fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */ |
168 | |
Line 164... | Line 186... | ||
164 | } |
186 | } |
Line 165... | Line 187... | ||
165 | 187 | ||
166 | 188 | ||
167 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
189 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
168 | { |
190 | { |
169 | unsigned int pt = 0; |
191 | unsigned int pt = 0; |
170 | unsigned char a,b,c; |
192 | unsigned char a,b,c; |
171 | unsigned char ptr = 0; |
193 | unsigned char ptr = 0; |
172 | 194 | ||
173 | TxBuffer[pt++] = '#'; // Startzeichen |
195 | TxBuffer[pt++] = '#'; // Startzeichen |
174 | TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
196 | TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
175 | TxBuffer[pt++] = cmd; // Commando |
197 | TxBuffer[pt++] = cmd; // Commando |
176 | 198 | ||
177 | while(len) |
199 | while(len) |
178 | { |
200 | { |
179 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
201 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
180 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
202 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
181 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
203 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
182 | TxBuffer[pt++] = '=' + (a >> 2); |
204 | TxBuffer[pt++] = '=' + (a >> 2); |
183 | TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
205 | TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
184 | TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
206 | TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
Line 185... | Line 207... | ||
185 | TxBuffer[pt++] = '=' + ( c & 0x3f); |
207 | TxBuffer[pt++] = '=' + ( c & 0x3f); |
186 | } |
208 | } |
Line 193... | Line 215... | ||
193 | status = send(s,"\r" , 1, 0); |
215 | status = send(s,"\r" , 1, 0); |
Line 194... | Line 216... | ||
194 | 216 | ||
195 | 217 | ||
196 | // for (c=0;c<pt+2;c++) |
218 | // for (c=0;c<pt+2;c++) |
197 | // { |
219 | // { |
198 | status = write(s,&TxBuffer , pt+3); |
220 | status = write(s,&TxBuffer , pt+3); |
199 | // printf("Send to MK %d \n" , TxBuffer[c] ); |
221 | // printf("Send to MK %d \n" , TxBuffer[c] ); |
200 | // } |
222 | // } |
201 | /*while(TxBuffer[i] !='\r' && i<150) |
223 | /*while(TxBuffer[i] !='\r' && i<150) |
202 | { |
224 | { |
203 | // TxBuffer[i]='#'; |
225 | // TxBuffer[i]='#'; |
204 | status = send(s,&TxBuffer[i] , 1, 0); |
226 | status = send(s,&TxBuffer[i] , 1, 0); |
205 | printf(" +%d%c ",i,TxBuffer[i]); |
227 | printf(" +%d%c ",i,TxBuffer[i]); |
Line 206... | Line 228... | ||
206 | i++; |
228 | i++; |
207 | } |
229 | } |
208 | 230 | ||
209 | status = send(s,"\r" , 1, 0); |
231 | status = send(s,"\r" , 1, 0); |
210 | */ |
232 | */ |
Line 242... | Line 264... | ||
242 | write_display(i,disp_txt); |
264 | write_display(i,disp_txt); |
243 | } |
265 | } |
244 | } |
266 | } |
245 | } |
267 | } |
Line 246... | Line 268... | ||
246 | 268 | ||
247 | void connect_mk(char dest[18]) |
269 | int connect_mk(char dest[18]) |
248 | { |
270 | { |
Line 249... | Line 271... | ||
249 | struct sockaddr_rc addr ; |
271 | struct sockaddr_rc addr ; |
250 | 272 | ||
Line 257... | Line 279... | ||
257 | str2ba( dest, &addr.rc_bdaddr ); |
279 | str2ba( dest, &addr.rc_bdaddr ); |
Line 258... | Line 280... | ||
258 | 280 | ||
259 | // connect to server |
281 | // connect to server |
Line -... | Line 282... | ||
- | 282 | status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); |
|
- | 283 | ||
260 | status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); |
284 | return status; |
Line 261... | Line 285... | ||
261 | 285 | ||
262 | } |
286 | } |
- | 287 | ||
Line 263... | Line 288... | ||
263 | 288 | ||
264 | 289 | ||
265 | 290 | ||
266 | 291 | int r=0; |
|
267 | int r=0; |
292 | int count=0; |
- | 293 | int connected=0; |
|
268 | int count=0; |
294 | |
- | 295 | int main(int argc, char**argv) |
|
269 | 296 | { |
|
270 | int main(int argc, char**argv) |
297 | printf("Starting Riddim \n"); |
- | 298 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
|
271 | { |
299 | |
272 | printf("Starting Riddim \n"); |
300 | // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips ) |
- | 301 | if (argv[1]) |
|
- | 302 | { |
|
273 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
303 | if (connect_mk(argv[1])==-1) |
274 | 304 | { |
|
Line 275... | Line 305... | ||
275 | //int tmp=2; |
305 | printf("cant connect to QC at adress: %s\n",argv[1]); |
276 | connect_mk("00:0B:CE:01:6B:4F"); |
306 | return 0; |
277 | 307 | } |
|
- | 308 | printf("connected to QC at adress: %s\n",argv[1]); |
|
Line 278... | Line 309... | ||
278 | 309 | connected=1; |
|
Line 279... | Line 310... | ||
279 | 310 | } |
|
Line 296... | Line 327... | ||
296 | if (x52_output) |
327 | if (x52_output) |
297 | printf(" done \n"); |
328 | printf(" done \n"); |
298 | else |
329 | else |
299 | printf(" not found \n"); |
330 | printf(" not found \n"); |
Line 300... | Line -... | ||
300 | - | ||
301 | printf("Scanning for Bluetooth Devices ..\n"); |
- | |
302 | write_display(1,"Bluetooth Scan"); |
- | |
303 | 331 | ||
304 | // scan_bt(); |
- | |
305 | printf(" done \n"); |
- | |
306 | printf(" %d Devices found \n",bt_device_count); |
- | |
307 | - | ||
308 | - | ||
309 | /* for(i=0;i<bt_device_count;i++) |
332 | if (!connected) |
310 | { |
333 | { |
311 | printf(" %d -> %s (%s) \n",i,names[i],addrs[i]); |
334 | printf("Scanning for Bluetooth Devices ..\n"); |
- | 335 | write_display(1,"Bluetooth Scan"); |
|
- | 336 | scan_bt(); |
|
- | 337 | printf(" done \n"); |
|
312 | if (i<3) write_display(i,names[i]); |
338 | printf(" %d Devices found \n",bt_device_count); |
313 | } |
339 | } |
314 | |
- | |
315 | output_device_list() ; |
- | |
Line 316... | Line 340... | ||
316 | */ |
340 | |
317 | 341 | ||
318 | int v_old; |
342 | int v_old; |
- | 343 | while( 1 ) |
|
319 | while( 1 ) |
344 | { |
320 | { |
345 | // poll values from input device |
321 | int polls=0; |
346 | int polls=0; |
322 | for (polls=0;polls<1000;polls++) // FIXME - better Polling |
347 | for (polls=0;polls<100;polls++) // FIXME - better Polling |
Line 323... | Line 348... | ||
323 | { |
348 | { |
324 | read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
349 | read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
325 | 350 | ||
326 | 351 | ||
327 | /* see what to do with the event */ |
352 | /* see what to do with the event */ |
328 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
353 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
329 | { |
354 | { |
330 | case JS_EVENT_AXIS: |
355 | case JS_EVENT_AXIS: |
331 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
356 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
332 | break; |
357 | break; |
333 | case JS_EVENT_BUTTON: |
358 | case JS_EVENT_BUTTON: |
Line 334... | Line 359... | ||
334 | button [ x52_event_struct.number ] = x52_event_struct.value; |
359 | button [ x52_event_struct.number ] = x52_event_struct.value; |
335 | break; |
360 | break; |
336 | } |
361 | } |
Line 350... | Line 375... | ||
350 | { |
375 | { |
Line 351... | Line 376... | ||
351 | 376 | ||
Line 352... | Line 377... | ||
352 | 377 | ||
Line 353... | Line 378... | ||
353 | case STATEID_SCANNING: |
378 | case STATEID_SCANNING: |
354 | 379 | ||
355 | state=STATEID_CONNECTING; //e |
380 | state=STATEID_CONNECTING; |
356 | 381 | ||
Line 366... | Line 391... | ||
366 | ExternControl.Higt=0; |
391 | ExternControl.Higt=0; |
367 | ExternControl.free=0; |
392 | ExternControl.free=0; |
368 | ExternControl.Frame='t'; |
393 | ExternControl.Frame='t'; |
369 | ExternControl.Config=1; |
394 | ExternControl.Config=1; |
Line 370... | Line -... | ||
370 | - | ||
371 | - | ||
372 | 395 | ||
Line 373... | Line -... | ||
373 | printf("sending data\n"); |
- | |
374 | 396 | printf("sending data\n"); |
|
- | 397 | ||
- | 398 | ||
Line 375... | Line 399... | ||
375 | SendOutData('b', 0, &ExternControl, sizeof(ExternControl)); |
399 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
376 | 400 | gettimeofday(&time_struct1,NULL); |
|
377 | 401 | ||
378 | if (button_trigger[BUTTON_SELECT]==1) |
402 | if (button_trigger[BUTTON_SELECT]==1) |
Line 396... | Line 420... | ||
396 | output_device_list() ; |
420 | output_device_list() ; |
397 | } |
421 | } |
398 | break; |
422 | break; |
Line 399... | Line 423... | ||
399 | 423 | ||
400 | case STATEID_CONNECTING: |
- | |
- | 424 | case STATEID_CONNECTING: |
|
401 | // for (polls=0;polls<10;polls++) // FIXME - better Polling |
425 | |
402 | RxBuffer[1]=0; |
- | |
403 | while (RxBuffer[1]!='t') |
- | |
Line 404... | Line -... | ||
404 | { |
- | |
405 | - | ||
Line -... | Line 426... | ||
- | 426 | RxBuffer[1]=0; |
|
- | 427 | ||
406 | r=0; |
428 | |
407 | in_char='#'; |
429 | // ftime(&time_struct); |
- | 430 | //printf("t:%d",time_struct.millitm); |
|
408 | 431 | while (RxBuffer[1]!='t') |
|
409 | while(in_char!='\r') |
432 | { |
410 | { |
433 | |
411 | count=read(s,&in_char,1); |
434 | r=0; |
412 | if (in_char!=0) |
- | |
413 | { |
- | |
414 | RxBuffer[r++]=in_char; |
435 | in_char='#'; |
- | 436 | ||
- | 437 | while(in_char!='\r') |
|
- | 438 | { |
|
- | 439 | count=read(s,&in_char,1); |
|
- | 440 | if (in_char!=0) |
|
- | 441 | { |
|
- | 442 | RxBuffer[r++]=in_char; |
|
415 | } |
443 | } |
- | 444 | else |
|
- | 445 | { |
|
416 | else |
446 | RxBuffer[r++]='0'; |
- | 447 | } |
|
417 | { |
448 | // printf("count:%d r:%d %d %c \n",count , r, in_char, in_char); |
- | 449 | } |
|
418 | RxBuffer[r++]='0'; |
450 | RxBuffer[r++]='\0'; |
- | 451 | printf("--->%s\n",RxBuffer); |
|
- | 452 | ||
- | 453 | } |
|
- | 454 | gettimeofday(&time_struct2,NULL); |
|
- | 455 | ||
419 | } |
456 | printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec)); |
- | 457 | act_mode=button[24] | (button[25]<<1); |
|
- | 458 | ||
- | 459 | switch (act_mode) |
|
- | 460 | { |
|
- | 461 | case 0: |
|
- | 462 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK); |
|
- | 463 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL); |
|
- | 464 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER); |
|
- | 465 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
|
- | 466 | ||
- | 467 | break; |
|
- | 468 | ||
- | 469 | case 1: |
|
- | 470 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
|
- | 471 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
|
- | 472 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
|
- | 473 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
|
- | 474 | ||
- | 475 | break; |
|
- | 476 | ||
- | 477 | case 2: |
|
420 | // printf("count:%d r:%d %d %c \n",count , r, in_char, in_char); |
478 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
Line 421... | Line -... | ||
421 | } |
- | |
Line -... | Line 479... | ||
- | 479 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
|
- | 480 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
|
- | 481 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
|
- | 482 | ||
422 | RxBuffer[r++]='\0'; |
483 | |
423 | printf("--->%s\n",RxBuffer); |
484 | break; |
424 | 485 | ||
425 | } |
486 | } |
426 | 487 | ||
427 | ExternControl.Digital[0]=0; |
488 | ExternControl.Digital[0]=0; |
428 | ExternControl.Digital[1]=0; |
489 | ExternControl.Digital[1]=0; |
429 | ExternControl.RemoteTasten=0; |
490 | ExternControl.RemoteTasten=0; |
430 | ExternControl.Nick=(axis[1]>>8)*(-1); |
491 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
431 | printf("nick%d\n",ExternControl.Nick); |
492 | // printf("nick%d\n",ExternControl.Nick); |
432 | ExternControl.Roll=(axis[0]>>8)*(-1); |
493 | ExternControl.Roll=act_roll; //(axis[0]>>8)*(-1)/2; |
- | 494 | ExternControl.Gier=(axis[5]>>8); |
|
433 | ExternControl.Gier=(axis[5]>>8); |
495 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
- | 496 | ExternControl.Higt=0; |
|
Line 434... | Line 497... | ||
434 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
497 | ExternControl.free=0; |
Line 435... | Line 498... | ||
435 | ExternControl.Higt=0; |
498 | ExternControl.Frame='t'; |
436 | ExternControl.free=0; |
- | |
- | 499 | ||
437 | ExternControl.Frame='t'; |
500 | ExternControl.Config=1; |
Line 438... | Line 501... | ||
438 | ExternControl.Config=1; |
501 | 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); |
439 | 502 | ||
440 | - | ||
441 | 503 | ||
Line 442... | Line 504... | ||
442 | printf("sending data\n"); |
504 | |
443 | 505 | printf("sending data\n"); |
|
444 | SendOutData('b', 0, &ExternControl, sizeof(ExternControl)); |
506 | |
Line 470... | Line 532... | ||
470 | 532 | ||
471 | printf("\n"); |
533 | printf("\n"); |
472 | fflush(stdout); |
534 | fflush(stdout); |
Line 473... | Line 535... | ||
473 | printf("loop fin"); |
535 | printf("loop fin"); |
Line 474... | Line 536... | ||
474 | 536 | ||
475 | } |
537 | } |
476 | 538 |