-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.cpp
39 lines (36 loc) · 1.04 KB
/
controller.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "config.hpp"
//#include "controller.hpp"
void deinit_con(){
close(fd);
puts("safity exit");
}
void setupcon(){
fd = open("/dev/input/js0",O_RDONLY);
errnum=errno;
if(fd<0){
printf("can not open file \n error=%d \n %s \n",errnum,strerror(errnum));
}else{
printf("open file\n");
}
atexit(deinit_con);
}
unsigned char getcon(){
read(fd,&joysta,sizeof(joysta));
switch(joysta.type & 0x7f){
case JS_EVENT_BUTTON:
if(joysta.value){
reccon[8]=reccon[8] | (1 << joysta.number);
}else{
reccon[8]=reccon[8] & (!(1 << joysta.number));
}
return joysta.number+10;
break;
case JS_EVENT_AXIS:
if((reccon[joysta.number]>highest && joysta.value<highest) || (reccon[joysta.number]<lowest && joysta.value>lowest) || (reccon[joysta.number]<highest && joysta.value>highest) || (reccon[joysta.number]>lowest && joysta.value<lowest)){
reccon[joysta.number]=joysta.value;
//printf("axis_%d\n",joysta.number);
return joysta.number;
}
}
return 0;//TODO for fixing error but unknown reason.
}