Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 139 → Rev 140

/Riddim/config/riddim.conf
0,0 → 1,21
# Riddim Config File
 
input_evdev = "/dev/input/event14"
mk_socket_port = 5432
#1
#loop_delay=20000
 
loop_delay=90000
 
 
#loop_delay=50000
#loop_delay=500000
 
# to check how the system was inited
exit_after_init=false
#exit_after_init=true
 
#bluetooth_mac="00:0B:CE:01:2E:00"
gas_mul=0.3
rel_axis_gas=2
nick_mul=-0.3
/Riddim/config/riddim_av8r.conf
0,0 → 1,27
# Riddim Config File
 
input_evdev = "/dev/input/event10"
mk_socket_port = 5432
#1
#1
#loop_delay=20000
 
#working loop_delay=90000
loop_delay=600000
 
 
#loop_delay=50000
#loop_delay=500000
 
# to check how the system was inited
#exit_after_init=false
exit_after_init=true
 
#bluetooth_mac="00:0B:CE:01:2E:00"
gas_mul=0.003
rel_axis_gas=2
nick_mul=-0.003
roll_mul=0.003
gier_mul=0.003
 
rel_axis_gier=3
/Riddim/config/riddim_logitech.conf
0,0 → 1,33
# Riddim Config File
 
input_evdev = "/dev/input/event10"
mk_socket_port = 54321
#1
#loop_delay=20000
 
loop_delay=90000
 
 
#loop_delay=50000
#loop_delay=500000
 
# to check how the system was inited
exit_after_init=false
#exit_after_init=true
 
#bluetooth_mac="00:0B:CE:01:2E:00"
gas_mul=0.3
#rel_axis_gas=2
nick_mul=-0.3
 
 
rel_axis_roll=2
rel_axis_nick=5
rel_axis_gas=1
rel_axis_gier=0
 
gas_mul=-0.8
# a2->roll
# a5 -> nick
# a0 -> gas
# a1 -> gier
/Riddim/config/riddim_spacemouse.conf
0,0 → 1,21
 
# Riddim Config File
 
input_evdev = "/dev/input/event10"
mk_socket_port = 54321
#loop_delay=20000
 
loop_delay=90000
 
 
#loop_delay=50000
#loop_delay=500000
 
# to check how the system was inited
exit_after_init=false
#exit_after_init=true
 
#bluetooth_mac="00:0B:CE:01:2E:00"
gas_mul=0.3
rel_axis_gas=2
nick_mul=-0.3
/Riddim/config/test.conf
0,0 → 1,24
# Riddim Config File
 
#input_evdev = "/dev/input/event14"
input_joydev = "/dev/input/js0"
 
 
mk_socket_port = 5432
#1
#loop_delay=20000
 
loop_delay=90000
 
 
#loop_delay=50000
#loop_delay=500000
 
# to check how the system was inited
 
exit_after_init=true
 
#bluetooth_mac="00:0B:CE:01:2E:00"
gas_mul=0.3
rel_axis_gas=2
nick_mul=-0.3
/Riddim/config.c
2,6 → 2,7
 
char *input_evdev_name;
char *input_joydev_name;
 
char *bluetooth_mac;
 
16,6 → 17,12
double gas_mul=0.3f;
 
 
double nick_add=0.3f;
double roll_add=0.3f;
double gier_add=0.3f;
double gas_add=0.3f;
 
 
int rel_axis_nick=1;
int rel_axis_roll=0;
int rel_axis_gier=5;
35,6 → 42,7
 
CFG_SIMPLE_BOOL("exit_after_init", &exit_after_init),
CFG_SIMPLE_STR("input_evdev", &input_evdev_name),
CFG_SIMPLE_STR("input_joydev", &input_joydev_name),
CFG_SIMPLE_INT("loop_delay", &loop_delay),
CFG_SIMPLE_INT("mk_socket_port", &mk_socket_port),
42,11 → 50,19
CFG_SIMPLE_FLOAT("roll_mul", &roll_mul),
CFG_SIMPLE_FLOAT("gier_mul", &gier_mul),
CFG_SIMPLE_FLOAT("gas_mul", &gas_mul),
 
CFG_SIMPLE_FLOAT("nick_add", &nick_add),
CFG_SIMPLE_FLOAT("roll_add", &roll_add),
CFG_SIMPLE_FLOAT("gier_add", &gier_add),
CFG_SIMPLE_FLOAT("gas_add", &gas_add),
CFG_SIMPLE_INT("rel_axis_nick", &rel_axis_nick),
CFG_SIMPLE_INT("rel_axis_roll", &rel_axis_roll),
CFG_SIMPLE_INT("rel_axis_gier", &rel_axis_gier),
CFG_SIMPLE_INT("rel_axis_gas", &rel_axis_gas),
 
 
 
CFG_END()
};
/Riddim/config.h
5,17 → 5,20
 
// values from config
extern char *input_evdev_name;
extern char *input_joydev_name;
extern char *bluetooth_mac;
extern int mk_socket_port;
extern int loop_delay;
 
 
 
extern double nick_mul;
extern double roll_mul;
extern double gier_mul;
extern double gas_mul;
 
extern double nick_add;
extern double roll_add;
extern double gier_add;
extern double gas_add;
 
extern int rel_axis_nick;
extern int rel_axis_roll;
/Riddim/evdev_handler.c
157,12 → 157,15
{
printf("%d type:%d code:%d val:%d \n",counter,ev[counter].type,ev[counter].code,ev[counter].value);
 
// if (ev[counter].type==EV_REL) evdev_rel_axis[ ev[counter].code]= ev[counter].value;
// for logitech problem
if (ev[counter].type==EV_REL) evdev_rel_axis[ ev[counter].code]= ev[counter].value;
if (ev[counter].type==EV_KEY) evdev_button[ ev[counter].code-256]= ev[counter].value;
}
for (counter=0;counter<10;counter++)
for (counter=0;counter<20;counter++)
printf("A%d %d -" , counter, evdev_rel_axis[counter] );
printf("\n");
/Riddim/fc.c
4,7 → 4,7
unsigned char TxBuffer[150];
unsigned char _TxBuffer[150];
 
char RxBuffer[150];
unsigned char RxBuffer[150];
char PrintableRxBuffer[150];
 
 
83,12 → 83,38
 
int rx_last_length;
 
 
void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max)
{
unsigned char a,b,c,d;
unsigned char ptr = 0;
unsigned char x,y,z;
while(len)
{
a = RxBuffer[ptrIn++] - '=';
b = RxBuffer[ptrIn++] - '=';
c = RxBuffer[ptrIn++] - '=';
d = RxBuffer[ptrIn++] - '=';
if(ptrIn > max - 2) break;
 
x = (a << 2) | (b >> 4);
y = ((b & 0x0f) << 4) | (c >> 2);
z = ((c & 0x03) << 6) | d;
 
if(len--) ptrOut[ptr++] = x; else break;
if(len--) ptrOut[ptr++] = y; else break;
if(len--) ptrOut[ptr++] = z; else break;
}
 
}
 
int read_from_mk()
{
char in_char='#';
int count=0;
int r=0;
int i=0;
 
printf("starting read\n");
while(in_char!='\n')
{
112,8 → 138,11
printf("done --->%s\n",PrintableRxBuffer);
 
if (RxBuffer[2]=='D')
debug_sets++;
 
{
debug_sets++;
Decode64((unsigned char *) &DebugOut,sizeof(DebugOut),3,rx_last_length);
printf("decoded FC Debug data height:%d\n",DebugOut.Analog[5]);
}
return 1;
}
 
/Riddim/fc.h
5,6 → 5,7
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <inttypes.h>
#include "bluetooth_handler.h"
#include "statistics.h"
 
22,6 → 23,17
unsigned char Config;
};
 
struct str_DebugOut
{
unsigned char Digital[2];
//# signed int
 
uint16_t Analog[32]; // Debugwert//
};
 
struct str_DebugOut DebugOut;
 
 
struct ExternControl_s ExternControl;
 
extern int mk_socket;
33,6 → 45,6
void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len);
int read_from_mk();
 
extern char RxBuffer[150];
extern unsigned char RxBuffer[150];
extern char PrintableRxBuffer[150];
extern int rx_last_length;
/Riddim/joy_handler.c
1,4 → 1,6
#include "joy_handler.h"
 
 
int connect_joy()
{
12,6 → 14,40
// button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) );
 
if( ( joy_input_fd = open( input_joydev_name, O_RDONLY ) ) < 0 )
{
printf( "can't open %s !\nHint: try modprobe joydev\n",input_joydev_name );
return 0;
}
 
ioctl( joy_input_fd, JSIOCGAXES, &num_of_axis );
ioctl( joy_input_fd, JSIOCGBUTTONS, &num_of_buttons );
ioctl( joy_input_fd, JSIOCGNAME(80), &name_of_joystick );
 
printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
, name_of_joystick
, num_of_axis
, num_of_buttons );
fcntl( joy_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */
 
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 );
28,7 → 64,8
, num_of_axis
, num_of_buttons );
fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */
fcntl( x52_input_fd, F_SETFL, O_NONBLOCK );
 
return 1;
}
*/
/Riddim/joy_handler.h
1,0 → 0,0
#if !defined(JOYDEV_HANDLER_H)
#define JOYDEV_HANDLER_H
 
#include <linux/joystick.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "config.h"
 
extern int *axis;
extern char *button;
 
 
 
int joy_input_fd;
int num_of_axis,num_of_buttons;
 
char *button_trigger;
char name_of_joystick[80];
 
 
int connect_joy();
 
#endif
/Riddim/riddim.c
12,20 → 12,9
#include "riddim.h"
 
 
 
int state=STATEID_SCANNING;
 
 
 
 
 
 
 
 
 
int x52_input_fd, num_of_axis=0, num_of_buttons=0;
char *button_trigger=NULL, name_of_joystick[80];
 
struct js_event x52_event_struct;
 
int engines_on=0;
34,16 → 23,10
int *axis;
char *button;
 
 
 
struct x52 *x52_output;
 
int selected_bt_device=0;
 
//int evdev_fd;
//int evdev_out_fd;
 
 
void write_display(int line,char* text)
{
if (x52_output) x52_settext(x52_output, line , text, strlen(text));
135,20 → 118,8
 
// todo reenable bluetooth connection
 
/*
printf("\nInitializing X-52 input ..\n");
if (connect_joy())
if ((input_evdev_name))
{
printf(".. done");//
input=INPUT_JOYDEV;
}
else
printf(".. ERROR ");//
*/
 
if (input_evdev_name)
{
printf("\nInitializing evdev input (%s) ..\n",input_evdev_name);
if (connect_evdev(input_evdev_name))
160,6 → 131,19
printf(".. ERROR ");//
}
 
if (input_joydev_name)
{
printf("\nInitializing joystick input from %s ..\n",input_joydev_name);
if (connect_joy())
{
printf(".. done");//
input=INPUT_JOYDEV;
}
else
printf(".. ERROR ");//
}
 
 
printf("\nInitializing X-52 output ..");
 
x52_output = x52_init();
217,24 → 201,22
 
case INPUT_NONE:
printf("starting input none\n");
printf("processing input none\n");
break;
 
case INPUT_EVDEV:
printf("input evdev\n");
 
printf("processing input evdev\n");
poll_evdev();
break;
 
case INPUT_JOYDEV:
printf("input joydev\n");
printf("processing 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));
read(joy_input_fd, &x52_event_struct, sizeof(struct js_event));
/* see what to do with the event */
257,14 → 239,12
if (button_trigger[x]<100)button_trigger[x]++;
}
break;
}
} // switch (input)
 
printf("input done\n");
switch(state)
{
 
case STATEID_SCANNING:
state=STATEID_CONNECTING;
316,8 → 296,8
 
confirm_misses=0;
printf("connected:%d",connected);
RxBuffer[1]=0;
 
RxBuffer[1]=0;
if (connected)
 
 
335,8 → 315,6
printf("waiting for confirm frame ( confirmed:%d misses:%d )\n",complete_matches,complete_misses);
RxBuffer[2]=0;
 
 
 
// r=0;
 
// new
360,7 → 338,7
 
gettimeofday(&time_struct2,NULL);
 
printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec));
printf("last trip: %d\n",(int)(time_struct2.tv_usec-time_struct1.tv_usec));
// act_mode=button[24] | (button[25]<<1);
 
 
367,13 → 345,38
 
// Step converting axis data to nick/roll/gier/gas/..
 
act_nick=evdev_rel_axis[rel_axis_nick]*nick_mul;
act_roll=evdev_rel_axis[rel_axis_roll]*roll_mul;
act_gier=evdev_rel_axis[rel_axis_gier]*gier_mul;
act_gas=evdev_rel_axis[rel_axis_gas]*gas_mul;
act_gas=255;
// act_nick=(evdev_rel_axis[rel_axis_nick]-128)*nick_mul;
 
 
 
 
switch(input)
{
case INPUT_EVDEV:
 
act_nick=(evdev_rel_axis[rel_axis_nick]-nick_add)*nick_mul;
act_roll=(evdev_rel_axis[rel_axis_roll]-nick_add)*roll_mul;
act_gier=(evdev_rel_axis[rel_axis_gier]-nick_add)*gier_mul;
act_gas=(evdev_rel_axis[rel_axis_gas]-nick_add)*gas_mul;
 
break;
 
case INPUT_JOYDEV:
act_nick=(axis[rel_axis_nick])*nick_mul;
act_roll=(axis[rel_axis_roll])*roll_mul;
act_gier=(axis[rel_axis_gier])*gier_mul;
act_gas=(axis[rel_axis_gas]*-1+33000)*gas_mul;
break;
}
 
// act values clipping to usefull vals
// act_gas=0;
 
// act_gas=255;
 
 
/*
switch (act_mode)
{
426,12 → 429,13
ExternControl.Gier=act_gier; // ************
ExternControl.Gas=act_gas; // ************
complete_matches++;
 
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);
 
if (connected)
{
complete_matches++;
printf("sending data\n");
SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl));
465,12 → 469,13
printf("\n");
fflush(stdout);
printf("loop fin ( confirmed:%d misses:%d | debug_sets:%d )\n",complete_matches,complete_misses,debug_sets);
printf("------------------------------------------------------------------------\n");
}
 
 
/******************** Cleanup **********************/
close(x52_input_fd);
close(joy_input_fd);
close(mk_socket);
 
if (x52_output) x52_close(x52_output);
/Riddim/riddim.h
21,8 → 21,11
// for understanding the FC
#include "fc.h"
#include "bluetooth_handler.h"
 
#include "evdev_handler.h"
 
#include "joy_handler.h"
 
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
57,11 → 60,11
#define FALSE 0
#define TRUE 1
 
#define JOY_DEV "/dev/input/js0"
 
 
 
 
 
#define STATEID_SCANNING 0
#define STATEID_CONNECTING 1