Rev 47 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 47 | Rev 48 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | 33 | ||
34 | int s, status; |
34 | int s, status; |
35 | unsigned char TxBuffer[150]; |
35 | unsigned char TxBuffer[150]; |
Line -... | Line 36... | ||
- | 36 | unsigned char _TxBuffer[150]; |
|
- | 37 | ||
- | 38 | char RxBuffer[150]; |
|
36 | unsigned char _TxBuffer[150]; |
39 | |
37 | 40 | ||
Line 38... | Line 41... | ||
38 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
41 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
Line -... | Line 42... | ||
- | 42 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
|
- | 43 | ||
- | 44 | struct js_event x52_event_struct; |
|
- | 45 | ||
- | 46 | ||
- | 47 | int engines_on=0; |
|
39 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
48 | int old_engines_on=0; |
40 | 49 | ||
41 | struct js_event x52_event_struct; |
50 | char in_char; |
42 | 51 | ||
Line 51... | Line 60... | ||
51 | unsigned char RemoteTasten; //(gab es schon für das virtuelle Display) |
60 | unsigned char RemoteTasten; //(gab es schon für das virtuelle Display) |
52 | signed char Nick; |
61 | signed char Nick; |
53 | signed char Roll; |
62 | signed char Roll; |
54 | signed char Gier; |
63 | signed char Gier; |
55 | unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
64 | unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
56 | signed char Hight; //(Höhenregler) |
65 | signed char Higt; //(Höhenregler) |
57 | unsigned char free; // (unbenutzt) |
66 | unsigned char free; // (unbenutzt) |
58 | unsigned char Frame; // (Bestätigung) |
67 | unsigned char Frame; // (Bestätigung) |
59 | unsigned char Config; |
68 | unsigned char Config; |
60 | } ExternControl; |
69 | } ExternControl; |
Line 152... | Line 161... | ||
152 | TxBuffer[i++] = '=' + tmpCRC / 64; |
161 | TxBuffer[i++] = '=' + tmpCRC / 64; |
153 | TxBuffer[i++] = '=' + tmpCRC % 64; |
162 | TxBuffer[i++] = '=' + tmpCRC % 64; |
154 | TxBuffer[i++] = '\r'; |
163 | TxBuffer[i++] = '\r'; |
155 | } |
164 | } |
Line 156... | Line -... | ||
156 | - | ||
157 | void SendOutData(unsigned char cmd,unsigned char modul, int len) |
- | |
158 | { |
- | |
159 | unsigned int pt = 0,ptr=0,i; |
- | |
160 | int a,b,c; |
- | |
161 | TxBuffer[pt++] = '#'; // Startzeichen |
- | |
162 | TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
- | |
Line -... | Line 165... | ||
- | 165 | ||
- | 166 | ||
- | 167 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
|
- | 168 | { |
|
- | 169 | unsigned int pt = 0; |
|
- | 170 | unsigned char a,b,c; |
|
- | 171 | unsigned char ptr = 0; |
|
- | 172 | ||
- | 173 | TxBuffer[pt++] = '#'; // Startzeichen |
|
- | 174 | TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
|
163 | TxBuffer[pt++] = cmd; // Commando |
175 | TxBuffer[pt++] = cmd; // Commando |
164 | 176 | ||
165 | while(len) |
177 | while(len) |
166 | { |
178 | { |
167 | if(len) { a = _TxBuffer[ptr++]; len--;} else a = 0; |
179 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
168 | if(len) { b = _TxBuffer[ptr++]; len--;} else b = 0; |
180 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
169 | if(len) { c = _TxBuffer[ptr++]; len--;} else c = 0; |
181 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
170 | TxBuffer[pt++] = '=' + (a >> 2); |
182 | TxBuffer[pt++] = '=' + (a >> 2); |
171 | TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
183 | TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
172 | TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
184 | TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
Line -... | Line 185... | ||
- | 185 | TxBuffer[pt++] = '=' + ( c & 0x3f); |
|
- | 186 | } |
|
- | 187 | ||
- | 188 | ||
- | 189 | ||
173 | TxBuffer[pt++] = '=' + ( c & 0x3f); |
190 | AddCRC(pt); |
- | 191 | printf("Sending to MK %d \n" , pt); |
|
- | 192 | ||
- | 193 | status = send(s,"\r" , 1, 0); |
|
174 | } |
194 | |
- | 195 | ||
- | 196 | // for (c=0;c<pt+2;c++) |
|
- | 197 | // { |
|
175 | 198 | status = write(s,&TxBuffer , pt+3); |
|
176 | status = send(s,"\r" , 1, 0); |
199 | // printf("Send to MK %d \n" , TxBuffer[c] ); |
177 | i=0; |
200 | // } |
178 | while(TxBuffer[i] !='\r' && i<150) |
201 | /*while(TxBuffer[i] !='\r' && i<150) |
179 | { |
202 | { |
180 | // TxBuffer[i]='#'; |
203 | // TxBuffer[i]='#'; |
181 | status = send(s,&TxBuffer[i] , 1, 0); |
204 | status = send(s,&TxBuffer[i] , 1, 0); |
182 | printf(" +%d%c ",i,TxBuffer[i]); |
205 | printf(" +%d%c ",i,TxBuffer[i]); |
183 | i++; |
206 | i++; |
184 | } |
207 | } |
- | 208 | ||
185 | 209 | status = send(s,"\r" , 1, 0); |
|
186 | status = send(s,"\r" , 1, 0); |
- | |
187 | - | ||
188 | printf("\n"); |
- | |
189 | AddCRC(pt); |
210 | */ |
Line 190... | Line -... | ||
190 | printf("Sending to MK\n"); |
- | |
191 | - | ||
192 | } |
- | |
193 | - | ||
194 | 211 | // status = send(s,"\r" , 1, 0); |
|
195 | int engines_on=0; |
212 | printf("\n"); |
196 | int old_engines_on=0; |
213 | } |
197 | 214 | ||
Line 245... | Line 262... | ||
245 | } |
262 | } |
Line -... | Line 263... | ||
- | 263 | ||
- | 264 | ||
Line 246... | Line 265... | ||
246 | 265 | ||
247 | 266 | ||
248 | 267 | int r=0; |
|
249 | 268 | int count=0; |
|
Line 250... | Line 269... | ||
250 | 269 | ||
251 | int main(int argc, char**argv) |
270 | int main(int argc, char**argv) |
Line 252... | Line 271... | ||
252 | { |
271 | { |
Line 280... | Line 299... | ||
280 | printf(" not found \n"); |
299 | printf(" not found \n"); |
Line 281... | Line 300... | ||
281 | 300 | ||
282 | printf("Scanning for Bluetooth Devices ..\n"); |
301 | printf("Scanning for Bluetooth Devices ..\n"); |
Line 283... | Line 302... | ||
283 | write_display(1,"Bluetooth Scan"); |
302 | write_display(1,"Bluetooth Scan"); |
284 | 303 | ||
285 | scan_bt(); |
304 | // scan_bt(); |
Line 286... | Line 305... | ||
286 | printf(" done \n"); |
305 | printf(" done \n"); |
287 | printf(" %d Devices found \n",bt_device_count); |
306 | printf(" %d Devices found \n",bt_device_count); |
288 | 307 | ||
289 | 308 | ||
290 | for(i=0;i<bt_device_count;i++) |
309 | /* for(i=0;i<bt_device_count;i++) |
Line 291... | Line 310... | ||
291 | { |
310 | { |
292 | printf(" %d -> %s (%s) \n",i,names[i],addrs[i]); |
311 | printf(" %d -> %s (%s) \n",i,names[i],addrs[i]); |
Line 293... | Line 312... | ||
293 | if (i<3) write_display(i,names[i]); |
312 | if (i<3) write_display(i,names[i]); |
294 | } |
313 | } |
295 | 314 | |
|
296 | output_device_list() ; |
315 | output_device_list() ; |
Line 327... | Line 346... | ||
327 | 346 | ||
328 | 347 | ||
- | 348 | ||
- | 349 | switch(state) |
|
329 | 350 | { |
|
- | 351 | ||
- | 352 | ||
- | 353 | case STATEID_SCANNING: |
|
- | 354 | ||
- | 355 | state=STATEID_CONNECTING; //e |
|
- | 356 | ||
- | 357 | ExternControl.Digital[0]=0; |
|
- | 358 | ExternControl.Digital[1]=0; |
|
- | 359 | ExternControl.RemoteTasten=0; |
|
- | 360 | ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
|
- | 361 | ||
- | 362 | printf("nick%d\n",ExternControl.Nick); |
|
- | 363 | ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
|
- | 364 | ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
|
- | 365 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
|
- | 366 | ExternControl.Higt=0; |
|
- | 367 | ExternControl.free=0; |
|
- | 368 | ExternControl.Frame='t'; |
|
- | 369 | ExternControl.Config=1; |
|
- | 370 | ||
- | 371 | ||
- | 372 | ||
- | 373 | printf("sending data\n"); |
|
- | 374 | ||
330 | switch(state) |
375 | SendOutData('b', 0, &ExternControl, sizeof(ExternControl)); |
331 | { |
376 | |
332 | case STATEID_SCANNING: |
377 | |
333 | if (button_trigger[BUTTON_SELECT]==1) |
378 | if (button_trigger[BUTTON_SELECT]==1) |
334 | { |
379 | { |
Line 349... | Line 394... | ||
349 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
394 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
Line 350... | Line 395... | ||
350 | 395 | ||
351 | output_device_list() ; |
396 | output_device_list() ; |
352 | } |
397 | } |
- | 398 | break; |
|
353 | break; |
399 | |
- | 400 | case STATEID_CONNECTING: |
|
- | 401 | // for (polls=0;polls<10;polls++) // FIXME - better Polling |
|
- | 402 | RxBuffer[1]=0; |
|
- | 403 | while (RxBuffer[1]!='t') |
|
- | 404 | { |
|
- | 405 | ||
- | 406 | r=0; |
|
- | 407 | in_char='#'; |
|
- | 408 | ||
- | 409 | while(in_char!='\r') |
|
- | 410 | { |
|
- | 411 | count=read(s,&in_char,1); |
|
- | 412 | if (in_char!=0) |
|
- | 413 | { |
|
- | 414 | RxBuffer[r++]=in_char; |
|
- | 415 | } |
|
- | 416 | else |
|
- | 417 | { |
|
- | 418 | RxBuffer[r++]='0'; |
|
- | 419 | } |
|
- | 420 | // printf("count:%d r:%d %d %c \n",count , r, in_char, in_char); |
|
- | 421 | } |
|
- | 422 | RxBuffer[r++]='\0'; |
|
- | 423 | printf("--->%s\n",RxBuffer); |
|
- | 424 | ||
- | 425 | } |
|
- | 426 | ||
- | 427 | ExternControl.Digital[0]=0; |
|
- | 428 | ExternControl.Digital[1]=0; |
|
- | 429 | ExternControl.RemoteTasten=0; |
|
- | 430 | ExternControl.Nick=(axis[1]>>8)*(-1); |
|
- | 431 | printf("nick%d\n",ExternControl.Nick); |
|
- | 432 | ExternControl.Roll=(axis[0]>>8)*(-1); |
|
- | 433 | ExternControl.Gier=(axis[5]>>8); |
|
- | 434 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
|
- | 435 | ExternControl.Higt=0; |
|
- | 436 | ExternControl.free=0; |
|
- | 437 | ExternControl.Frame='t'; |
|
354 | case STATEID_CONNECTING: |
438 | ExternControl.Config=1; |
Line 355... | Line -... | ||
355 | - | ||
356 | - | ||
357 | _TxBuffer[0]=(axis[2]>>8)*(-1)+127; |
- | |
358 | if (button[7]!=1)_TxBuffer[0] =0; |
- | |
359 | - | ||
360 | _TxBuffer[1]=_TxBuffer[0]; |
- | |
361 | _TxBuffer[2]=_TxBuffer[0]; |
- | |
362 | _TxBuffer[3]=_TxBuffer[0]; |
- | |
363 | - | ||
364 | SendOutData('t', 0, 4); |
- | |
365 | - | ||
Line -... | Line 439... | ||
- | 439 | ||
Line -... | Line 440... | ||
- | 440 | ||
- | 441 | ||
- | 442 | printf("sending data\n"); |
|
- | 443 | ||
- | 444 | SendOutData('b', 0, &ExternControl, sizeof(ExternControl)); |
|
- | 445 | ||
- | 446 | printf("sent data\n"); |
|
- | 447 | ||
- | 448 | ||
Line 366... | Line 449... | ||
366 | 449 | printf("sleeping\n"); |
|
367 | sleep(0.05); |
450 | // usleep(10000); |
368 | 451 | ||
Line 369... | Line 452... | ||
369 | 452 | printf("end_sleep\n"); |
|
Line 370... | Line 453... | ||
370 | 453 | ||
371 | int v=axis[6]/655+50; |
454 | int v=axis[6]/655+50; |
Line 383... | Line 466... | ||
383 | printf("B%d: %d ", x, button[x] ); |
466 | printf("B%d: %d ", x, button[x] ); |
Line 384... | Line 467... | ||
384 | 467 | ||
385 | break; |
468 | break; |
Line 386... | Line 469... | ||
386 | } |
469 | } |
387 | 470 | ||
388 | printf("\r"); |
- | |
- | 471 | printf("\n"); |
|
Line 389... | Line 472... | ||
389 | fflush(stdout); |
472 | fflush(stdout); |
Line 390... | Line 473... | ||
390 | 473 | printf("loop fin"); |