35,11 → 35,20 |
unsigned char TxBuffer[150]; |
unsigned char _TxBuffer[150]; |
|
char RxBuffer[150]; |
|
|
int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
|
struct js_event x52_event_struct; |
|
|
int engines_on=0; |
int old_engines_on=0; |
|
char in_char; |
|
struct |
{ |
char val[4]; |
53,7 → 62,7 |
signed char Roll; |
signed char Gier; |
unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
signed char Hight; //(Höhenregler) |
signed char Higt; //(Höhenregler) |
unsigned char free; // (unbenutzt) |
unsigned char Frame; // (Bestätigung) |
unsigned char Config; |
154,28 → 163,42 |
TxBuffer[i++] = '\r'; |
} |
|
void SendOutData(unsigned char cmd,unsigned char modul, int len) |
|
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
{ |
unsigned int pt = 0,ptr=0,i; |
int a,b,c; |
TxBuffer[pt++] = '#'; // Startzeichen |
TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
TxBuffer[pt++] = cmd; // Commando |
unsigned int pt = 0; |
unsigned char a,b,c; |
unsigned char ptr = 0; |
|
while(len) |
{ |
if(len) { a = _TxBuffer[ptr++]; len--;} else a = 0; |
if(len) { b = _TxBuffer[ptr++]; len--;} else b = 0; |
if(len) { c = _TxBuffer[ptr++]; len--;} else c = 0; |
TxBuffer[pt++] = '=' + (a >> 2); |
TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
TxBuffer[pt++] = '=' + ( c & 0x3f); |
} |
TxBuffer[pt++] = '#'; // Startzeichen |
TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
TxBuffer[pt++] = cmd; // Commando |
|
while(len) |
{ |
if(len) { a = snd[ptr++]; len--;} else a = 0; |
if(len) { b = snd[ptr++]; len--;} else b = 0; |
if(len) { c = snd[ptr++]; len--;} else c = 0; |
TxBuffer[pt++] = '=' + (a >> 2); |
TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
TxBuffer[pt++] = '=' + ( c & 0x3f); |
} |
|
|
|
AddCRC(pt); |
printf("Sending to MK %d \n" , pt); |
|
status = send(s,"\r" , 1, 0); |
i=0; |
while(TxBuffer[i] !='\r' && i<150) |
|
|
// for (c=0;c<pt+2;c++) |
// { |
status = write(s,&TxBuffer , pt+3); |
// printf("Send to MK %d \n" , TxBuffer[c] ); |
// } |
/*while(TxBuffer[i] !='\r' && i<150) |
{ |
// TxBuffer[i]='#'; |
status = send(s,&TxBuffer[i] , 1, 0); |
182,20 → 205,14 |
printf(" +%d%c ",i,TxBuffer[i]); |
i++; |
} |
|
|
status = send(s,"\r" , 1, 0); |
|
*/ |
// status = send(s,"\r" , 1, 0); |
printf("\n"); |
AddCRC(pt); |
printf("Sending to MK\n"); |
|
} |
|
|
int engines_on=0; |
int old_engines_on=0; |
|
|
void write_display(int line,char* text) |
{ |
if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
247,6 → 264,8 |
|
|
|
int r=0; |
int count=0; |
|
int main(int argc, char**argv) |
{ |
254,7 → 273,7 |
printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
|
//int tmp=2; |
// connect_mk("00:0B:CE:01:6B:4F"); |
connect_mk("00:0B:CE:01:6B:4F"); |
|
|
|
282,12 → 301,12 |
printf("Scanning for Bluetooth Devices ..\n"); |
write_display(1,"Bluetooth Scan"); |
|
scan_bt(); |
// scan_bt(); |
printf(" done \n"); |
printf(" %d Devices found \n",bt_device_count); |
|
|
for(i=0;i<bt_device_count;i++) |
/* for(i=0;i<bt_device_count;i++) |
{ |
printf(" %d -> %s (%s) \n",i,names[i],addrs[i]); |
if (i<3) write_display(i,names[i]); |
294,8 → 313,8 |
} |
|
output_device_list() ; |
*/ |
|
|
int v_old; |
while( 1 ) |
{ |
329,7 → 348,33 |
|
switch(state) |
{ |
|
|
case STATEID_SCANNING: |
|
state=STATEID_CONNECTING; //e |
|
ExternControl.Digital[0]=0; |
ExternControl.Digital[1]=0; |
ExternControl.RemoteTasten=0; |
ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
|
printf("nick%d\n",ExternControl.Nick); |
ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
ExternControl.Higt=0; |
ExternControl.free=0; |
ExternControl.Frame='t'; |
ExternControl.Config=1; |
|
|
|
printf("sending data\n"); |
|
SendOutData('b', 0, &ExternControl, sizeof(ExternControl)); |
|
|
if (button_trigger[BUTTON_SELECT]==1) |
{ |
state=STATEID_CONNECTING; |
351,28 → 396,66 |
output_device_list() ; |
} |
break; |
|
case STATEID_CONNECTING: |
|
// for (polls=0;polls<10;polls++) // FIXME - better Polling |
RxBuffer[1]=0; |
while (RxBuffer[1]!='t') |
{ |
|
_TxBuffer[0]=(axis[2]>>8)*(-1)+127; |
if (button[7]!=1)_TxBuffer[0] =0; |
|
_TxBuffer[1]=_TxBuffer[0]; |
_TxBuffer[2]=_TxBuffer[0]; |
_TxBuffer[3]=_TxBuffer[0]; |
|
SendOutData('t', 0, 4); |
|
|
sleep(0.05); |
r=0; |
in_char='#'; |
|
while(in_char!='\r') |
{ |
count=read(s,&in_char,1); |
if (in_char!=0) |
{ |
RxBuffer[r++]=in_char; |
} |
else |
{ |
RxBuffer[r++]='0'; |
} |
// printf("count:%d r:%d %d %c \n",count , r, in_char, in_char); |
} |
RxBuffer[r++]='\0'; |
printf("--->%s\n",RxBuffer); |
|
} |
|
ExternControl.Digital[0]=0; |
ExternControl.Digital[1]=0; |
ExternControl.RemoteTasten=0; |
ExternControl.Nick=(axis[1]>>8)*(-1); |
printf("nick%d\n",ExternControl.Nick); |
ExternControl.Roll=(axis[0]>>8)*(-1); |
ExternControl.Gier=(axis[5]>>8); |
ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
ExternControl.Higt=0; |
ExternControl.free=0; |
ExternControl.Frame='t'; |
ExternControl.Config=1; |
|
|
|
printf("sending data\n"); |
|
SendOutData('b', 0, &ExternControl, sizeof(ExternControl)); |
|
printf("sent data\n"); |
|
|
printf("sleeping\n"); |
// usleep(10000); |
|
printf("end_sleep\n"); |
|
int v=axis[6]/655+50; |
if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
v_old=v; |
|
printf("v: %d \r",v); |
printf("v: %d \n",v); |
|
|
for (i=0;i<num_of_axis;i++) |
385,9 → 468,9 |
break; |
} |
|
printf("\r"); |
printf("\n"); |
fflush(stdout); |
|
printf("loop fin"); |
|
} |
|