Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 116 → Rev 117

/Riddim/riddim.c
29,8 → 29,17
#define BUTTON_UP 27
 
 
#define AXIS_ROLL 0
#define AXIS_NICK 1
// #define AXIS_ROLL 0
// #define AXIS_NICK 1
// #define AXIS_GIER 5
// #define AXIS_GAS 2
 
 
 
// for x52
/*
#define AXIS_ROLL 4
#define AXIS_NICK 3
#define AXIS_GIER 5
#define AXIS_GAS 2
 
38,8 → 47,33
#define INVERT_NICK -1
#define INVERT_GIER 1
#define INVERT_GAS -1
*/
 
#define AXIS_ROLL 0
#define AXIS_NICK 1
#define AXIS_GIER 3
#define AXIS_GAS 2
 
#define INVERT_ROLL 1
#define INVERT_NICK -1
#define INVERT_GIER 1
#define INVERT_GAS -1
 
 
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>//for close() for socket
 
 
#define INPUT_NONE 0
#define INPUT_JOYDEV 1
#define INPUT_EVDEV 2
 
 
// time struct for measuring
struct timeval time_struct1;
struct timeval time_struct2;
139,11 → 173,36
close( sock );
}
 
int yalv; /* loop counter */
size_t read_bytes; /* how many bytes were read */
struct input_event ev[64]; /* the events (up to 64 at once) */
 
int evdev_fd;
int connect_evdev()
{
if ((evdev_fd = open("/dev/input/event10", O_RDONLY)) < 0) {
printf(" cant open evdev ");
return 0;
}
 
return 1;
 
 
}
 
int connect_joy()
{
axis = (int *) calloc( 100, sizeof( int ) );
button = (char *)calloc( 100, sizeof( char ) );
button_trigger = (char *) calloc( 100, sizeof( char ) );
 
// axis = (int *) calloc( num_of_axis, sizeof( int ) );
// button = (char *)calloc( num_of_buttons, sizeof( char ) );
// button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
 
if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 )
{
printf( "Couldn't open joystick device %s\n", JOY_DEV );
154,10 → 213,6
ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis );
ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons );
ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick );
axis = (int *) calloc( num_of_axis, sizeof( int ) );
button = (char *)calloc( num_of_buttons, sizeof( char ) );
button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
 
printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
, name_of_joystick
268,8 → 323,33
 
int connect_mk(char dest[18])
{
 
struct sockaddr_rc addr ;
struct sockaddr_in sa;
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = htonl(0x0);
sa.sin_port = htons(54321);
// allocate a socket
// s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
//);
 
// set the connection parameters (who to connect to)
addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = 1;
str2ba( dest, &addr.rc_bdaddr );
 
// connect to server
// status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
status = connect(s,(struct sockaddr*) &sa, sizeof(struct sockaddr_in));
 
return status;
 
/*
struct sockaddr_rc addr ;
 
// allocate a socket
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
282,7 → 362,7
status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
 
return status;
*/
}
 
 
292,6 → 372,9
int count=0;
int connected=0;
 
 
int input=INPUT_NONE;
 
int main(int argc, char**argv)
{
printf("Starting Riddim \n");
309,12 → 392,30
connected=1;
}
int i;
 
 
 
 
 
printf("\nInitializing X-52 input ..\n");
if (!connect_joy()) return 0;
printf(".. done");//
if (connect_joy())
{
printf(".. done");//
input=INPUT_JOYDEV;
}
else
printf(".. ERROR ");//
 
 
/* printf("\nInitializing evdev input ..\n");
if (connect_evdev())
{
printf(".. done");//
input=INPUT_EVDEV;
}
else
printf(".. ERROR ");//
*/
printf("\nInitializing X-52 output ..");
 
x52_output = x52_init();
340,36 → 441,85
 
 
int v_old;
int polls=0;
printf("starting loop ..\n");
 
 
 
while( 1 )
{
// poll values from input device
int polls=0;
for (polls=0;polls<100;polls++) // FIXME - better Polling
 
switch (input)
{
read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
case INPUT_NONE:
printf("input none\n");
usleep(10000);
break;
 
/* see what to do with the event */
switch (x52_event_struct.type & ~JS_EVENT_INIT)
case INPUT_EVDEV:
printf("input evdev\n");
usleep(30000);
 
 
read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64);
printf("read done\n");
if (read_bytes < (int) sizeof(struct input_event)) {
perror("evtest: short read");
exit (1);
}
 
for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++)
{
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;
// 1 -> nick
// 2 -> gas
// 4->roll
// 5-> gier
axis[ ev[yalv].code]= ev[yalv].value;
printf("nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]);
/*if ( ev[yalv].code==5)
printf("Event: time %ld.%06ld, type %d, code %d, value %d\n",
ev[yalv].time.tv_sec, ev[yalv].time.tv_usec, ev[yalv].type,
ev[yalv].code, ev[yalv].value);
*/
}
 
 
break;
case INPUT_JOYDEV:
printf("input joydev\n");
// poll values from input device
for (polls=0;polls<100;polls++) // FIXME - better Polling
{
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;
}
}
for( x=0 ; x<num_of_buttons ; ++x )
if( button[x]==0)
button_trigger[x]=0;
else
{
if (button_trigger[x]<100)button_trigger[x]++;
}
break;
}
for( x=0 ; x<num_of_buttons ; ++x )
if( button[x]==0)
button_trigger[x]=0;
else
{
if (button_trigger[x]<100)button_trigger[x]++;
}
 
 
printf("input done\n");
switch(state)
{
427,14 → 577,17
 
 
// ftime(&time_struct);
//printf("t:%d",time_struct.millitm);
while (RxBuffer[1]!='t')
printf("waiting for confirm frame\n");
RxBuffer[2]=0;
int confirm_misses=0;
 
while (RxBuffer[2]!='t')
{
 
r=0;
in_char='#';
 
while(in_char!='\r')
while(in_char!='\n')
{
count=read(s,&in_char,1);
if (in_char!=0)
445,11 → 598,19
{
RxBuffer[r++]='0';
}
// printf("count:%d r:%d %d %c \n",count , r, in_char, in_char);
// printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char);
}
RxBuffer[r++]='\0';
printf("--->%s\n",RxBuffer);
 
// new
if (button_trigger[12]>1)
{
SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
button_trigger[12]=0;
}
if (++confirm_misses>4)
SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
}
gettimeofday(&time_struct2,NULL);
 
459,11 → 620,19
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);
act_gas=((axis[AXIS_GAS]>>8)-128)*(-1);
// clip gas
if (act_gas<0) act_gas=0;
 
if (act_gas>250) act_gas=250;
 
//////// act_gas=0;
break;
 
case 1:
490,15 → 659,18
ExternControl.RemoteTasten=0;
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.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2;
ExternControl.Gier=(axis[5]>>8);
ExternControl.Gier=act_gier; // ************
ExternControl.Gas=(axis[2]>>8)*(-1)+127;
ExternControl.Gas=act_gas; // ************
// ExternControl.Gas=0; // ************
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("---+++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);
 
 
 
510,7 → 682,7
 
// printf("sleeping\n");
// usleep(10000);
// for (polls=0;polls<100;polls++) // FIXME - better Polling
// printf("end_sleep\n");
 
int v=axis[6]/655+50;