Subversion Repositories Projects

Compare Revisions

Regard whitespace Rev 117 → Rev 116

/Riddim/riddim.c
29,17 → 29,8
#define BUTTON_UP 27
 
 
// #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_ROLL 0
#define AXIS_NICK 1
#define AXIS_GIER 5
#define AXIS_GAS 2
 
47,33 → 38,8
#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;
173,36 → 139,11
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 );
214,6 → 155,10
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
, num_of_axis
323,34 → 268,9
 
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);
// set the connection parameters (who to connect to)
362,7 → 282,7
status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
 
return status;
*/
}
 
 
372,9 → 292,6
int count=0;
int connected=0;
 
 
int input=INPUT_NONE;
 
int main(int argc, char**argv)
{
printf("Starting Riddim \n");
393,29 → 310,11
}
int i;
 
 
 
 
 
printf("\nInitializing X-52 input ..\n");
if (connect_joy())
{
if (!connect_joy()) return 0;
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();
441,57 → 340,10
 
 
int v_old;
int polls=0;
printf("starting loop ..\n");
 
 
 
while( 1 )
{
 
switch (input)
{
case INPUT_NONE:
printf("input none\n");
usleep(10000);
break;
 
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++)
{
// 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
int polls=0;
for (polls=0;polls<100;polls++) // FIXME - better Polling
{
read(x52_input_fd, &x52_event_struct, sizeof(struct js_event));
516,11 → 368,9
{
if (button_trigger[x]<100)button_trigger[x]++;
}
break;
}
 
printf("input done\n");
switch(state)
{
 
577,17 → 427,14
 
 
// ftime(&time_struct);
printf("waiting for confirm frame\n");
RxBuffer[2]=0;
int confirm_misses=0;
 
while (RxBuffer[2]!='t')
//printf("t:%d",time_struct.millitm);
while (RxBuffer[1]!='t')
{
 
r=0;
in_char='#';
 
while(in_char!='\n')
while(in_char!='\r')
{
count=read(s,&in_char,1);
if (in_char!=0)
598,18 → 445,10
{
RxBuffer[r++]='0';
}
// printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char);
// printf("count:%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);
620,19 → 459,11
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)-128)*(-1);
act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS);
// clip gas
if (act_gas<0) act_gas=0;
 
if (act_gas>250) act_gas=250;
 
//////// act_gas=0;
break;
 
case 1:
659,18 → 490,15
ExternControl.RemoteTasten=0;
ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2;
// printf("nick%d\n",ExternControl.Nick);
ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2;
ExternControl.Roll=act_roll; //(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);
 
 
 
682,7 → 510,7
 
// printf("sleeping\n");
// for (polls=0;polls<100;polls++) // FIXME - better Polling
// usleep(10000);
// printf("end_sleep\n");
 
int v=axis[6]/655+50;