Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 482 → Rev 483

/Riddim/evdev_handler.c
1,7 → 1,6
#include "evdev_handler.h"
#include "config.h"
 
int evdev_fd;
int evdev_out_fd;
int retval;
size_t read_bytes; /* how many bytes were read */
struct input_event ev[64]; /* the events (up to 64 at once) */
9,16 → 8,118
 
 
 
int *evdev_rel_axis=NULL;
char *evdev_button=NULL;
 
int counter;
 
int connect_evdev(char* input_evdev_name)
int evdevs_count=0;
int file_select(struct direct *entry)
{
if ((strncmp(entry->d_name, "event",5))==0)
return (TRUE);
else
return(FALSE);
}
 
 
void collect_evdev_devices()
{
 
char event_dev_path[]="/dev/input/";
struct direct **files;
evdevs_count = scandir(event_dev_path, &files, file_select, NULL);
 
printf("%d inputs found in %s\n" , evdevs_count,event_dev_path);
 
int i=0;
for (i=1;i<evdevs_count+1;++i)
{
 
printf("%s",files[i-1]->d_name);
sprintf(evdevs[i].fname,"%s%s",event_dev_path,files[i-1]->d_name);
int act_fd;
 
if ((act_fd = open(evdevs[i].fname, O_RDONLY)) < 0)
{
printf(" cant open %s for reading!",evdevs[i].name);
}
else
{
if(ioctl(act_fd , EVIOCGNAME(sizeof(evdevs[i].name)), evdevs[i].name) < 0) {
perror("evdev ioctl");
}
printf("EVDEV reports name: %s\n", evdevs[i].name);
close(act_fd);
}
 
 
/*
FILE *fp=NULL ;
 
sprintf(evdevs[i].fname,"/sys/class/input/%s/name",files[i-1]->d_name);
fp = fopen ( evdevs[i].fname, "r") ;
 
if (fp==NULL)
{
printf("cannot read %s\n",evdevs[i].fname);
// exit(1);
}
int ch=-2;
int str_pos=0;
while ( (ch!=-1) && (ch!='\n') )
{
 
ch = fgetc ( fp ) ;
if ((ch!=13)&&(ch!=10))evdevs[i].name[str_pos++]=ch;
printf("%c",ch);
}
 
fclose(fp);
evdevs[i].name[str_pos++]=0;
*/
 
}
}
 
 
void print_event_str(int id)
{
switch ( id)
{
case EV_KEY :
printf("Keys or Button\n");
break;
case EV_ABS :
printf("Absolute Axis\n");
break;
case EV_LED :
printf("LED(s)\n");
break;
case EV_REP :
printf("Repeat\n");
break;
case EV_SYN :
printf("Sync?\n");
break;
case EV_REL :
printf("Relative Axis\n");
break;
case EV_MSC :
printf("Misc\n");
break;
default:
printf("Unknown event type ( 0x%04hx)\n", id);
}
return "";
}
 
int connect_evdev()
{
evdev_rel_axis = (int *) calloc( 100, sizeof( int ) );
evdev_button = (char *)calloc( 100, sizeof( char ) );
 
 
struct input_devinfo {
uint16_t bustype;
uint16_t vendor;
27,82 → 128,51
};
struct input_devinfo device_info;
 
if ((evdev_out_fd = open(input_evdev_name, O_WRONLY)) < 0)
int i;
for ( i =0 ; i< input_count;i++)
{
printf(" cant open %s for writing\n",input_evdev_name);
}
inputs[i].evdev_rel_axis = (int *) calloc( 100, sizeof( int ) );
inputs[i].evdev_button = (char *)calloc( 500, sizeof( char ) );
 
if ((evdev_fd = open(input_evdev_name, O_RDONLY)) < 0)
{
printf(" cant open %s for reading!",input_evdev_name);
return 0;
}
if ((inputs[i].evdev_out_fd = open(inputs[i].fname, O_WRONLY)) < 0)
{
printf(" cant open %s for writing\n",inputs[i].fname);
}
 
if ((inputs[i].evdev_in_fd = open(inputs[i].fname, O_RDONLY)) < 0)
{
printf(" cant open %s for reading!",inputs[i].fname);
return 0;
}
ioctl(evdev_fd,EVIOCGID,&device_info);
ioctl(inputs[i].evdev_in_fd ,EVIOCGID,&device_info);
printf("vendor 0x%04hx product 0x%04hx version 0x%04hx \n",
device_info.vendor, device_info.product,
device_info.version);
printf("vendor 0x%04hx product 0x%04hx version 0x%04hx \n",
device_info.vendor, device_info.product,
device_info.version);
 
 
char name[256]= "Unknown";
 
if(ioctl(evdev_fd, EVIOCGNAME(sizeof(name)), name) < 0) {
perror("evdev ioctl");
}
 
printf("EVDEV reports name: %s\n", name);
 
/* this macro is used to tell if "bit" is set in "array"
* it selects a byte from the array, and does a boolean AND
* operation with a byte that only has the relevant bit set.
* eg. to check for the 12th bit, we do (array[1] & 1<<4)
*/
 
 
uint8_t evtype_bitmask[EV_MAX/8 + 1];
 
if(ioctl(evdev_fd, EVIOCGBIT(0, sizeof(evtype_bitmask)), evtype_bitmask) < 0)
perror("evdev ioctl");
 
printf("Supported event types:\n");
 
int i;
for (i = 0; i < EV_MAX; i++) {
if (test_bit(i, evtype_bitmask)) {
/* this means that the bit is set in the event types list */
printf(" Event type 0x%02x ", i);
switch ( i)
{
case EV_KEY :
printf(" (Keys or Buttons)\n");
break;
case EV_ABS :
printf(" (Absolute Axes)\n");
break;
case EV_LED :
printf(" (LEDs)\n");
break;
case EV_REP :
printf(" (Repeat)\n");
break;
case EV_SYN :
printf(" (Sync?)\n");
break;
case EV_REL :
printf(" (Relative Axis)\n");
break;
case EV_MSC :
printf(" (Misc)\n");
break;
default:
printf(" (Unknown event type: 0x%04hx)\n", i);
}}}
 
uint8_t evtype_bitmask[EV_MAX/8 + 1];
if(ioctl(inputs[i].evdev_in_fd , EVIOCGBIT(0, sizeof(evtype_bitmask)), evtype_bitmask) < 0)
perror("evdev ioctl");
printf("Supported event types:\n");
int i;
for (i = 0; i < EV_MAX; i++) {
if (test_bit(i, evtype_bitmask)) {
/* this means that the bit is set in the event types list */
printf(" Event type 0x%02x ", i);
print_event_str(i);
}}
}
return 1;
}
 
/*
int init_evdevstatus_led()
{
led_event.type=EV_LED;
120,7 → 190,7
{
if (led_event.value)
led_event.value = 0;
else
else
led_event.value = 1 ;
retval = write(evdev_out_fd, &led_event, sizeof(struct input_event));
127,54 → 197,59
}
return 1;
}
*/
 
int poll_evdev()
{
 
struct timeval tv;
 
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(evdev_fd,&rfds);
 
tv.tv_sec = 0;
tv.tv_usec = 5;
retval = select(evdev_fd+1, &rfds, NULL, NULL, &tv);
if (retval==-1)
printf("error in select!!!!!!!!\n");
else if (retval)
printf("polling evdev\n");
int i;
for ( i =0 ; i< input_count;i++)
{
read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64);
struct timeval tv = {0,5};
if (read_bytes < (int) sizeof(struct input_event)) {
perror("evtest: short read");
exit (1);
}
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(inputs[i].evdev_in_fd,&rfds);
 
for (counter = 0; counter < (int) (read_bytes / sizeof(struct input_event)); counter++)
retval = select(inputs[i].evdev_in_fd+1, &rfds, NULL, NULL, &tv);
if (retval==-1)
printf("error in select!!!!!!!!\n");
else if (retval)
{
read_bytes = read(inputs[i].evdev_in_fd, ev, sizeof(struct input_event) * 64);
if (read_bytes < (int) sizeof(struct input_event)) {
perror("evtest: short read");
exit (1);
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 < (int) (read_bytes / sizeof(struct input_event)); counter++)
{
//print_event_str(ev[counter].type);
// printf(" code:%d val:%d \n",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) inputs[i].evdev_rel_axis[ ev[counter].code]= ev[counter].value;
if (ev[counter].type==EV_KEY) inputs[i].evdev_button[ ev[counter].code]= ev[counter].value;
}
for (counter=0;counter<20;counter++)
printf("A%d %d -" , counter, inputs[i].evdev_rel_axis[counter] );
printf("\n");
for (counter=0;counter<10;counter++)
printf("B%d %d -" , counter, inputs[i].evdev_button[counter] );
// printf("input read done: nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]);
}
for (counter=0;counter<20;counter++)
printf("A%d %d -" , counter, evdev_rel_axis[counter] );
printf("\n");
for (counter=0;counter<10;counter++)
printf("B%d %d -" , counter, evdev_button[counter] );
// printf("input read done: nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]);
else
printf("no data from evdev data from evdev: \n");
}
else
printf("no data from evdev data from evdev: \n");
return 1;
}