Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 49 → Rev 50

/Riddim/README
1,7 → 1,7
# RIDDIM
# -> Remote Interactive Digital Drone Interface Mashup
#
# Author: Marcus -ligi- Büschleb
# Author: Marcus -ligi- Bueschleb
#
# Contact: ligi
# -at-
55,7 → 55,10
$> ./riddim
 
= Changelog =
 
0.5 - code cleanup
0.4 - Measure time from send command to confirm
0.3 - mode selector
0.2 - first version with possibility to fly ( based on FC0.68b commands )
0.1 - initial release with basic functions and proove of concept Code ( Scanning for Blueooth Devices / read Joy / communicate to MK / ..)
62,6 → 65,6
 
= ToDo =
 
- Measure timings
- Force Feedback from ACC Sensor Data
- Support more JoySticks -> generalize
- Support more JoySticks -> generalize
- Support more Aircraft types -> generalize
/Riddim/riddim.c
9,7 → 9,9
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
 
#include <sys/time.h>
 
 
#include <bluetooth/rfcomm.h>
 
 
26,6 → 28,29
#define BUTTON_DOWN 28
#define BUTTON_UP 27
 
 
#define AXIS_ROLL 0
#define AXIS_NICK 1
#define AXIS_GIER 5
#define AXIS_GAS 2
 
#define INVERT_ROLL -1
#define INVERT_NICK -1
#define INVERT_GIER 1
#define INVERT_GAS -1
 
 
// time struct for measuring
struct timeval time_struct1;
struct timeval time_struct2;
 
 
int act_nick=0;
int act_roll=0;
int act_gier=0;
int act_gas=0;
int act_mode=0;
 
int bt_device_count=0;
 
char names[MAX_BT_DEVICES][248];
43,19 → 68,13
 
struct js_event x52_event_struct;
 
 
int engines_on=0;
int old_engines_on=0;
 
char in_char;
 
struct
struct ExternControl_s
{
char val[4];
} MotortestParam;
 
struct
{
unsigned char Digital[2]; // (noch unbenutzt)
unsigned char RemoteTasten; //(gab es schon für das virtuelle Display)
signed char Nick;
66,9 → 85,10
unsigned char free; // (unbenutzt)
unsigned char Frame; // (Bestätigung)
unsigned char Config;
} ExternControl;
};
 
 
struct ExternControl_s ExternControl ;
 
int state=STATEID_SCANNING;
 
120,7 → 140,7
}
 
 
void connect_joy()
int connect_joy()
{
 
127,7 → 147,8
if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 )
{
printf( "Couldn't open joystick device %s\n", JOY_DEV );
return ;
printf( "try modprobe joydev\n" );
return 0;
}
 
ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis );
145,6 → 166,7
fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */
 
return 1;
}
 
 
166,24 → 188,24
 
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len)
{
unsigned int pt = 0;
unsigned char a,b,c;
unsigned char ptr = 0;
unsigned int pt = 0;
unsigned char a,b,c;
unsigned char ptr = 0;
 
TxBuffer[pt++] = '#'; // Startzeichen
TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...)
TxBuffer[pt++] = cmd; // Commando
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);
}
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);
}
 
195,18 → 217,18
// for (c=0;c<pt+2;c++)
// {
status = write(s,&TxBuffer , pt+3);
// printf("Send to MK %d \n" , TxBuffer[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);
printf(" +%d%c ",i,TxBuffer[i]);
i++;
// TxBuffer[i]='#';
status = send(s,&TxBuffer[i] , 1, 0);
printf(" +%d%c ",i,TxBuffer[i]);
i++;
}
 
status = send(s,"\r" , 1, 0);
status = send(s,"\r" , 1, 0);
*/
// status = send(s,"\r" , 1, 0);
printf("\n");
244,7 → 266,7
}
}
 
void connect_mk(char dest[18])
int connect_mk(char dest[18])
{
struct sockaddr_rc addr ;
 
259,31 → 281,40
// connect to server
status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
 
return status;
}
 
 
 
 
int r=0;
int count=0;
int r=0;
int count=0;
int connected=0;
 
int main(int argc, char**argv)
{
printf("Starting Riddim \n");
printf("\tRemote Interactive Digital Drone Interface Mashup\n");
//int tmp=2;
connect_mk("00:0B:CE:01:6B:4F");
 
 
// 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips )
if (argv[1])
{
if (connect_mk(argv[1])==-1)
{
printf("cant connect to QC at adress: %s\n",argv[1]);
return 0;
}
printf("connected to QC at adress: %s\n",argv[1]);
connected=1;
}
int i;
printf("\nInitializing X-52 input ..\n");
connect_joy();
printf(".. done");
if (!connect_joy()) return 0;
printf(".. done");//
 
 
printf("\nInitializing X-52 output ..");
 
x52_output = x52_init();
298,42 → 329,36
else
printf(" not found \n");
 
printf("Scanning for Bluetooth Devices ..\n");
write_display(1,"Bluetooth Scan");
 
// scan_bt();
printf(" done \n");
printf(" %d Devices found \n",bt_device_count);
 
 
/* for(i=0;i<bt_device_count;i++)
if (!connected)
{
printf(" %d -> %s (%s) \n",i,names[i],addrs[i]);
if (i<3) write_display(i,names[i]);
printf("Scanning for Bluetooth Devices ..\n");
write_display(1,"Bluetooth Scan");
scan_bt();
printf(" done \n");
printf(" %d Devices found \n",bt_device_count);
}
output_device_list() ;
*/
 
 
int v_old;
while( 1 )
{
// poll values from input device
int polls=0;
for (polls=0;polls<1000;polls++) // FIXME - better Polling
for (polls=0;polls<100;polls++) // FIXME - better Polling
{
read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
 
/* see what to do with the event */
switch (x52_event_struct.type & ~JS_EVENT_INIT)
{
case JS_EVENT_AXIS:
axis [ x52_event_struct.number ] = x52_event_struct.value;
break;
case JS_EVENT_BUTTON:
button [ x52_event_struct.number ] = x52_event_struct.value;
break;
}
/* see what to do with the event */
switch (x52_event_struct.type & ~JS_EVENT_INIT)
{
case JS_EVENT_AXIS:
axis [ x52_event_struct.number ] = x52_event_struct.value;
break;
case JS_EVENT_BUTTON:
button [ x52_event_struct.number ] = x52_event_struct.value;
break;
}
}
for( x=0 ; x<num_of_buttons ; ++x )
352,7 → 377,7
case STATEID_SCANNING:
 
state=STATEID_CONNECTING; //e
state=STATEID_CONNECTING;
 
ExternControl.Digital[0]=0;
ExternControl.Digital[1]=0;
368,13 → 393,12
ExternControl.Frame='t';
ExternControl.Config=1;
 
 
 
printf("sending data\n");
 
SendOutData('b', 0, &ExternControl, sizeof(ExternControl));
SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
gettimeofday(&time_struct1,NULL);
 
 
if (button_trigger[BUTTON_SELECT]==1)
{
state=STATEID_CONNECTING;
398,58 → 422,96
break;
case STATEID_CONNECTING:
// for (polls=0;polls<10;polls++) // FIXME - better Polling
 
RxBuffer[1]=0;
 
 
// ftime(&time_struct);
//printf("t:%d",time_struct.millitm);
while (RxBuffer[1]!='t')
{
{
 
r=0;
in_char='#';
r=0;
in_char='#';
 
while(in_char!='\r')
{
count=read(s,&in_char,1);
if (in_char!=0)
while(in_char!='\r')
{
RxBuffer[r++]=in_char;
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);
}
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);
 
}
RxBuffer[r++]='\0';
printf("--->%s\n",RxBuffer);
gettimeofday(&time_struct2,NULL);
 
}
printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
act_mode=button[24] | (button[25]<<1);
 
switch (act_mode)
{
case 0:
act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK);
act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL);
act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER);
act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
 
break;
 
case 1:
act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2;
act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2;
act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2;
act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
 
break;
case 2:
act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3;
act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3;
act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3;
act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
 
 
break;
 
}
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.Nick=act_nick; //(axis[1]>>8)*(-1)/2;
// printf("nick%d\n",ExternControl.Nick);
ExternControl.Roll=act_roll; //(axis[0]>>8)*(-1)/2;
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("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);
 
 
 
printf("sending data\n");
 
SendOutData('b', 0, &ExternControl, sizeof(ExternControl));
SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
gettimeofday(&time_struct1,NULL);
printf("sent data\n");
 
printf("sleeping\n");
// usleep(10000);
printf("end_sleep\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 );
472,7 → 534,7
fflush(stdout);
printf("loop fin");
}
}
 
 
/******************** Cleanup **********************/