|
@@ -77,6 +77,27 @@ void la_ReadControllerAxisLimit(laController* c, int i, int Min, int Max){
|
|
c->AxisLimitMins[i] = -32768*0.95;
|
|
c->AxisLimitMins[i] = -32768*0.95;
|
|
c->AxisLimitMaxes[i] = 32767*0.95;
|
|
c->AxisLimitMaxes[i] = 32767*0.95;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+int la_ControllerButtonToMap(int btn){
|
|
|
|
+ if(btn<BTN_MISC) return -1;
|
|
|
|
+ if(btn<=BTN_GEAR_UP) return btn-BTN_MISC;
|
|
|
|
+ if(btn<BTN_DPAD_UP) return -1;
|
|
|
|
+ if(btn<=BTN_DPAD_RIGHT) return BTN_GEAR_UP-BTN_MISC+1+btn-BTN_DPAD_UP;
|
|
|
|
+ if(btn<BTN_TRIGGER_HAPPY) return -1;
|
|
|
|
+ if(btn<=BTN_TRIGGER_HAPPY40) return BTN_GEAR_UP-BTN_MISC+1+BTN_DPAD_RIGHT-BTN_DPAD_UP+1+btn-BTN_TRIGGER_HAPPY;
|
|
|
|
+ return -1;
|
|
|
|
+}
|
|
|
|
+int la_ControllerButtonToIndex(laController* c,int btn){
|
|
|
|
+ int map=la_ControllerButtonToMap(btn); if(map<0) return -1; return c->ButtonsMap[map];
|
|
|
|
+}
|
|
|
|
+int la_ControllerAxisToMap(int abs){
|
|
|
|
+ if(abs<ABS_X) return -1; if(abs>ABS_MAX) return -1;
|
|
|
|
+ return abs;
|
|
|
|
+}
|
|
|
|
+int la_ControllerAxisToIndex(laController* c,int abs){
|
|
|
|
+ int map=la_ControllerAxisToMap(abs); if(map<0) return -1; return c->AxisMap[map];
|
|
|
|
+}
|
|
|
|
+
|
|
void la_InitControllers(){
|
|
void la_InitControllers(){
|
|
#ifdef __linux__
|
|
#ifdef __linux__
|
|
char path[32]="/dev/input/js";
|
|
char path[32]="/dev/input/js";
|
|
@@ -90,7 +111,7 @@ void la_InitControllers(){
|
|
if (file != -1){
|
|
if (file != -1){
|
|
// Get name
|
|
// Get name
|
|
ioctl(file, EVIOCGNAME(128), name);
|
|
ioctl(file, EVIOCGNAME(128), name);
|
|
- printf("%s ",name);
|
|
|
|
|
|
+ printf("%s\n",name);
|
|
|
|
|
|
barray_t *abs_barray = barray_init(ABS_CNT);
|
|
barray_t *abs_barray = barray_init(ABS_CNT);
|
|
ioctl(file, EVIOCGBIT(EV_ABS, ABS_CNT), barray_data(abs_barray));
|
|
ioctl(file, EVIOCGBIT(EV_ABS, ABS_CNT), barray_data(abs_barray));
|
|
@@ -104,9 +125,19 @@ void la_InitControllers(){
|
|
|
|
|
|
laController* c=la_NewController(name, fileName, file, abs_count, key_count);
|
|
laController* c=la_NewController(name, fileName, file, abs_count, key_count);
|
|
|
|
|
|
- for (unsigned int j=0; j<abs_count; j++){ struct input_absinfo axisInfo;
|
|
|
|
- if (ioctl(file, EVIOCGABS(j), &axisInfo) != -1){
|
|
|
|
- la_ReadControllerAxisLimit(c,j,axisInfo.minimum,axisInfo.maximum);
|
|
|
|
|
|
+ int nextid=0;
|
|
|
|
+ for (unsigned int j=0; j<KEY_CNT; j++){
|
|
|
|
+ if(barray_is_set(key_barray,j)){
|
|
|
|
+ int mapid=la_ControllerButtonToMap(j); if(mapid<0){ continue; }
|
|
|
|
+ c->ButtonsMap[mapid]=nextid; nextid++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ nextid=0;
|
|
|
|
+ for (unsigned int j=0; j<ABS_CNT; j++){ struct input_absinfo axisInfo;
|
|
|
|
+ if (barray_is_set(abs_barray,j) && (ioctl(file, EVIOCGABS(j), &axisInfo) != -1)){
|
|
|
|
+ int mapid=la_ControllerAxisToMap(j); if(mapid<0){ continue; }
|
|
|
|
+ la_ReadControllerAxisLimit(c,nextid,axisInfo.minimum,axisInfo.maximum);
|
|
|
|
+ c->AxisMap[mapid]=nextid; nextid++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -123,22 +154,14 @@ void la_UpdateControllerStatus(){
|
|
for(laController* c=MAIN.Controllers.pFirst;c;c=c->Item.pNext){ if(c->Error) continue;
|
|
for(laController* c=MAIN.Controllers.pFirst;c;c=c->Item.pNext){ if(c->Error) continue;
|
|
int bytes; while((bytes=read(c->fd, &event, sizeof(struct input_event)))>0){
|
|
int bytes; while((bytes=read(c->fd, &event, sizeof(struct input_event)))>0){
|
|
if(event.type == EV_KEY){
|
|
if(event.type == EV_KEY){
|
|
- printf("b %d %d", event.code, event.value);
|
|
|
|
- if(event.code>=BTN_JOYSTICK && event.code<=BTN_THUMBR){
|
|
|
|
- event.code -= BTN_JOYSTICK;
|
|
|
|
- }elif(event.code>=BTN_TRIGGER_HAPPY && event.code<=BTN_TRIGGER_HAPPY40){
|
|
|
|
- event.code=event.code-BTN_TRIGGER_HAPPY+BTN_THUMBR-BTN_JOYSTICK+1;
|
|
|
|
- }
|
|
|
|
- printf(" %d \n", event.code, event.value);
|
|
|
|
- //if(event.code>=c->NumButtons+BTN_THUMBR) continue;
|
|
|
|
- c->ButtonValues[event.code]=event.value; HasEvent=1;
|
|
|
|
|
|
+ int idx = la_ControllerButtonToIndex(c,event.code); if(idx<0) continue;
|
|
|
|
+ c->ButtonValues[idx]=event.value; HasEvent=1;
|
|
|
|
+ //printf("b %d\n", idx);
|
|
}
|
|
}
|
|
else if(event.type == EV_ABS){
|
|
else if(event.type == EV_ABS){
|
|
- if(event.code>=c->NumAxes+ABS_X) continue;
|
|
|
|
- int axis=event.code-ABS_X;
|
|
|
|
- c->AxisValues[axis]=rint(tnsLinearItp(-32768.0f,32767.0f,((real)event.value/(c->AxisMaxes[axis]-c->AxisMins[axis]))));
|
|
|
|
- HasEvent=1;
|
|
|
|
- //printf("a %d %d\n", event.code, event.value);
|
|
|
|
|
|
+ int idx = la_ControllerAxisToIndex(c,event.code); if(idx<0) continue;
|
|
|
|
+ c->AxisValues[idx]=rint(tnsLinearItp(-32768.0f,32767.0f,((real)event.value/(c->AxisMaxes[idx]-c->AxisMins[idx]))));
|
|
|
|
+ HasEvent=1; //printf("a %d %d\n", idx, event.value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(bytes<=0){ struct stat buffer; if(stat(c->Path->Ptr,&buffer)<0){ c->Error=1; HasEvent=1; } }
|
|
if(bytes<=0){ struct stat buffer; if(stat(c->Path->Ptr,&buffer)<0){ c->Error=1; HasEvent=1; } }
|
|
@@ -251,18 +274,18 @@ void la_RegisterControllerProps(){
|
|
la_AddButtonProp(pc,"t2_up","T2+","Toggle 2+", 13,0,0);
|
|
la_AddButtonProp(pc,"t2_up","T2+","Toggle 2+", 13,0,0);
|
|
la_AddButtonProp(pc,"t2_dn","T2-","Toggle 2-", 14,0,0);
|
|
la_AddButtonProp(pc,"t2_dn","T2-","Toggle 2-", 14,0,0);
|
|
la_AddButtonProp(pc,"t3_up","T3+","Toggle 3+", 15,0,0);
|
|
la_AddButtonProp(pc,"t3_up","T3+","Toggle 3+", 15,0,0);
|
|
- la_AddButtonProp(pc,"t3_dn","T3-","Toggle 3-", 31,0,0);
|
|
|
|
- la_AddButtonProp(pc,"t4_up","T4+","Toggle 4+", 32,0,0);
|
|
|
|
- la_AddButtonProp(pc,"t4_dn","T4-","Toggle 4-", 33,0,0);
|
|
|
|
- la_AddButtonProp(pc,"h3","H3","Hat 3 (Upper round hat)", 34,4,"N,E,S,W");
|
|
|
|
- la_AddButtonProp(pc,"h4","H4","Hat 4 (lower jagged hat)", 38,4,"N,E,S,W");
|
|
|
|
- la_AddButtonProp(pc,"pinky_up","P+","Pinky up", 42,0,0);
|
|
|
|
- la_AddButtonProp(pc,"pinky_dn","P-","Pinky down", 43,0,0);
|
|
|
|
- la_AddButtonProp(pc,"dial_fwd","D+","Dial forward", 44,0,0);
|
|
|
|
- la_AddButtonProp(pc,"dial_back","D-","Dial backward", 45,0,0);
|
|
|
|
- la_AddButtonProp(pc,"bball","BP","Ball push", 46,0,0);
|
|
|
|
- la_AddButtonProp(pc,"slider","SLD","Slider", 47,0,0);
|
|
|
|
- la_AddButtonProp(pc,"mode","Mode","Mode switch", 48,3,"M1,M2,S1");
|
|
|
|
|
|
+ la_AddButtonProp(pc,"t3_dn","T3-","Toggle 3-", 16,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"t4_up","T4+","Toggle 4+", 17,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"t4_dn","T4-","Toggle 4-", 18,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"h3","H3","Hat 3 (Upper round hat)", 19,4,"N,E,S,W");
|
|
|
|
+ la_AddButtonProp(pc,"h4","H4","Hat 4 (lower jagged hat)", 23,4,"N,E,S,W");
|
|
|
|
+ la_AddButtonProp(pc,"pinky_up","P+","Pinky up", 27,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"pinky_dn","P-","Pinky down", 28,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"dial_fwd","D+","Dial forward", 29,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"dial_back","D-","Dial backward", 30,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"bball","BP","Ball push", 31,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"slider","SLD","Slider", 32,0,0);
|
|
|
|
+ la_AddButtonProp(pc,"mode","Mode","Mode switch", 33,3,"M1,M2,S1");
|
|
|
|
|
|
|
|
|
|
pc=laAddPropertyContainer("la_controller_x56_stick", "X56 Stick", "X56 Stick", 0,laui_X56Stick,sizeof(laController),0,0,1);
|
|
pc=laAddPropertyContainer("la_controller_x56_stick", "X56 Stick", "X56 Stick", 0,laui_X56Stick,sizeof(laController),0,0,1);
|