Commit 955c9b99 authored by Jan Holthuis's avatar Jan Holthuis
Browse files

Merge pull request #764 from reicast/holzhaus/linux-dist-indentation-fix

linux-dist: indentation fix
parents 6bfa831e b0e91185
......@@ -6,201 +6,216 @@
#if defined(USE_EVDEV)
int input_evdev_init(Controller* controller, const char* device)
{
char name[256] = "Unknown";
int input_evdev_init(Controller* controller, const char* device)
{
char name[256] = "Unknown";
printf("evdev: Trying to open device at '%s'\n", device);
printf("evdev: Trying to open device at '%s'\n", device);
int fd = open(device, O_RDONLY);
int fd = open(device, O_RDONLY);
if (fd >= 0)
{
fcntl(fd, F_SETFL, O_NONBLOCK);
if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0)
{
perror("evdev: ioctl");
return -2;
}
else
{
printf("evdev: Found '%s' at '%s'\n", name, device);
if (fd >= 0)
{
fcntl(fd, F_SETFL, O_NONBLOCK);
if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0)
{
perror("evdev: ioctl");
return -2;
}
else
{
printf("evdev: Found '%s' at '%s'\n", name, device);
controller->fd = fd;
controller->fd = fd;
#if defined(TARGET_PANDORA)
*controller.mapping = &controller_mapping_pandora;
#elif defined(TARGET_GCW0)
*controller.mapping = &controller_mapping_gcwz;
#else
if (strcmp(name, "Microsoft X-Box 360 pad") == 0 ||
strcmp(name, "Xbox 360 Wireless Receiver") == 0 ||
strcmp(name, "Xbox 360 Wireless Receiver (XBOX)") == 0)
{
controller->mapping = &controller_mapping_xpad;
}
else if (strstr(name, "Xbox Gamepad (userspace driver)") != NULL)
{
controller->mapping = &controller_mapping_xboxdrv;
}
else if (strstr(name, "keyboard") != NULL ||
strstr(name, "Keyboard") != NULL)
{
controller->mapping = &controller_mapping_keyboard;
}
else
{
controller->mapping = &controller_mapping_generic;
}
#endif
printf("evdev: Using '%s' mapping\n", controller->mapping->name);
#if defined(TARGET_PANDORA)
*controller.mapping = &controller_mapping_pandora;
#elif defined(TARGET_GCW0)
*controller.mapping = &controller_mapping_gcwz;
#else
if (strcmp(name, "Microsoft X-Box 360 pad") == 0 ||
strcmp(name, "Xbox 360 Wireless Receiver") == 0 ||
strcmp(name, "Xbox 360 Wireless Receiver (XBOX)") == 0)
{
controller->mapping = &controller_mapping_xpad;
}
else if (strstr(name, "Xbox Gamepad (userspace driver)") != NULL)
{
controller->mapping = &controller_mapping_xboxdrv;
}
else if (strstr(name, "keyboard") != NULL ||
strstr(name, "Keyboard") != NULL)
{
controller->mapping = &controller_mapping_keyboard;
}
else
{
controller->mapping = &controller_mapping_generic;
}
#endif
printf("evdev: Using '%s' mapping\n", controller->mapping->name);
return 0;
}
}
else
{
perror("evdev: open");
return -1;
}
}
return 0;
}
}
else
{
perror("evdev: open");
return -1;
}
}
bool input_evdev_handle(Controller* controller, u32 port)
{
#define SET_FLAG(field, mask, expr) field =((expr) ? (field & ~mask) : (field | mask))
if (controller->fd < 0 || controller->mapping == NULL)
{
return false;
}
bool input_evdev_handle(Controller* controller, u32 port)
{
#define SET_FLAG(field, mask, expr) field =((expr) ? (field & ~mask) : (field | mask))
if (controller->fd < 0 || controller->mapping == NULL)
{
return false;
}
input_event ie;
input_event ie;
while(read(controller->fd, &ie, sizeof(ie)) == sizeof(ie))
{
if(ie.type != EV_SYN && ie.type != EV_MSC)
{
printf("type %i key %i state %i\n", ie.type, ie.code, ie.value);
}
switch(ie.type)
{
case EV_KEY:
if (ie.code == controller->mapping->Btn_A) {
SET_FLAG(kcode[port], DC_BTN_A, ie.value);
} else if (ie.code == controller->mapping->Btn_B) {
SET_FLAG(kcode[port], DC_BTN_B, ie.value);
} else if (ie.code == controller->mapping->Btn_C) {
SET_FLAG(kcode[port], DC_BTN_C, ie.value);
} else if (ie.code == controller->mapping->Btn_D) {
SET_FLAG(kcode[port], DC_BTN_D, ie.value);
} else if (ie.code == controller->mapping->Btn_X) {
SET_FLAG(kcode[port], DC_BTN_X, ie.value);
} else if (ie.code == controller->mapping->Btn_Y) {
SET_FLAG(kcode[port], DC_BTN_Y, ie.value);
} else if (ie.code == controller->mapping->Btn_Z) {
SET_FLAG(kcode[port], DC_BTN_Z, ie.value);
} else if (ie.code == controller->mapping->Btn_Start) {
SET_FLAG(kcode[port], DC_BTN_START, ie.value);
} else if (ie.code == controller->mapping->Btn_Escape) {
die("death by escape key");
} else if (ie.code == controller->mapping->Btn_DPad_Left) {
SET_FLAG(kcode[port], DC_DPAD_LEFT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad_Right) {
SET_FLAG(kcode[port], DC_DPAD_RIGHT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad_Up) {
SET_FLAG(kcode[port], DC_DPAD_UP, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad_Down) {
SET_FLAG(kcode[port], DC_DPAD_DOWN, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad2_Left) {
SET_FLAG(kcode[port], DC_DPAD2_LEFT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad2_Right) {
SET_FLAG(kcode[port], DC_DPAD2_RIGHT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad2_Up) {
SET_FLAG(kcode[port], DC_DPAD2_UP, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad2_Down) {
SET_FLAG(kcode[port], DC_DPAD2_DOWN, ie.value);
} else if (ie.code == controller->mapping->Btn_Trigger_Left) {
lt[port] = (ie.value ? 255 : 0);
} else if (ie.code == controller->mapping->Btn_Trigger_Right) {
rt[port] = (ie.value ? 255 : 0);
}
break;
case EV_ABS:
if (ie.code == controller->mapping->Axis_DPad_X) {
switch(ie.value)
{
case -1:
SET_FLAG(kcode[port], DC_DPAD_LEFT, 1);
SET_FLAG(kcode[port], DC_DPAD_RIGHT, 0);
break;
case 0:
SET_FLAG(kcode[port], DC_DPAD_LEFT, 0);
SET_FLAG(kcode[port], DC_DPAD_RIGHT, 0);
break;
case 1:
SET_FLAG(kcode[port], DC_DPAD_LEFT, 0);
SET_FLAG(kcode[port], DC_DPAD_RIGHT, 1);
break;
}
} else if (ie.code == controller->mapping->Axis_DPad_Y) {
switch(ie.value)
{
case -1:
SET_FLAG(kcode[port], DC_DPAD_UP, 1);
SET_FLAG(kcode[port], DC_DPAD_DOWN, 0);
break;
case 0:
SET_FLAG(kcode[port], DC_DPAD_UP, 0);
SET_FLAG(kcode[port], DC_DPAD_DOWN, 0);
break;
case 1:
SET_FLAG(kcode[port], DC_DPAD_UP, 0);
SET_FLAG(kcode[port], DC_DPAD_DOWN, 1);
break;
}
} else if (ie.code == controller->mapping->Axis_DPad2_X) {
switch(ie.value)
{
case -1:
SET_FLAG(kcode[port], DC_DPAD2_LEFT, 1);
SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 0);
break;
case 0:
SET_FLAG(kcode[port], DC_DPAD2_LEFT, 0);
SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 0);
break;
case 1:
SET_FLAG(kcode[port], DC_DPAD2_LEFT, 0);
SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 1);
break;
}
} else if (ie.code == controller->mapping->Axis_DPad2_X) {
switch(ie.value)
{
case -1:
SET_FLAG(kcode[port], DC_DPAD2_UP, 1);
SET_FLAG(kcode[port], DC_DPAD2_DOWN, 0);
break;
case 0:
SET_FLAG(kcode[port], DC_DPAD2_UP, 0);
SET_FLAG(kcode[port], DC_DPAD2_DOWN, 0);
break;
case 1:
SET_FLAG(kcode[port], DC_DPAD2_UP, 0);
SET_FLAG(kcode[port], DC_DPAD2_DOWN, 1);
break;
}
} else if (ie.code == controller->mapping->Axis_Analog_X) {
printf("%d", ie.value);
joyx[port] = (s8)(ie.value/256);
} else if (ie.code == controller->mapping->Axis_Analog_Y) {
joyy[port] = (s8)(ie.value/256);
} else if (ie.code == controller->mapping->Axis_Trigger_Left) {
lt[port] = (s8)ie.value;
} else if (ie.code == controller->mapping->Axis_Trigger_Right) {
rt[port] = (s8)ie.value;
}
break;
}
}
}
#endif
\ No newline at end of file
while(read(controller->fd, &ie, sizeof(ie)) == sizeof(ie))
{
if(ie.type != EV_SYN && ie.type != EV_MSC)
{
printf("type %i key %i state %i\n", ie.type, ie.code, ie.value);
}
switch(ie.type)
{
case EV_KEY:
if (ie.code == controller->mapping->Btn_A) {
SET_FLAG(kcode[port], DC_BTN_A, ie.value);
} else if (ie.code == controller->mapping->Btn_B) {
SET_FLAG(kcode[port], DC_BTN_B, ie.value);
} else if (ie.code == controller->mapping->Btn_C) {
SET_FLAG(kcode[port], DC_BTN_C, ie.value);
} else if (ie.code == controller->mapping->Btn_D) {
SET_FLAG(kcode[port], DC_BTN_D, ie.value);
} else if (ie.code == controller->mapping->Btn_X) {
SET_FLAG(kcode[port], DC_BTN_X, ie.value);
} else if (ie.code == controller->mapping->Btn_Y) {
SET_FLAG(kcode[port], DC_BTN_Y, ie.value);
} else if (ie.code == controller->mapping->Btn_Z) {
SET_FLAG(kcode[port], DC_BTN_Z, ie.value);
} else if (ie.code == controller->mapping->Btn_Start) {
SET_FLAG(kcode[port], DC_BTN_START, ie.value);
} else if (ie.code == controller->mapping->Btn_Escape) {
die("death by escape key");
} else if (ie.code == controller->mapping->Btn_DPad_Left) {
SET_FLAG(kcode[port], DC_DPAD_LEFT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad_Right) {
SET_FLAG(kcode[port], DC_DPAD_RIGHT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad_Up) {
SET_FLAG(kcode[port], DC_DPAD_UP, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad_Down) {
SET_FLAG(kcode[port], DC_DPAD_DOWN, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad2_Left) {
SET_FLAG(kcode[port], DC_DPAD2_LEFT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad2_Right) {
SET_FLAG(kcode[port], DC_DPAD2_RIGHT, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad2_Up) {
SET_FLAG(kcode[port], DC_DPAD2_UP, ie.value);
} else if (ie.code == controller->mapping->Btn_DPad2_Down) {
SET_FLAG(kcode[port], DC_DPAD2_DOWN, ie.value);
} else if (ie.code == controller->mapping->Btn_Trigger_Left) {
lt[port] = (ie.value ? 255 : 0);
} else if (ie.code == controller->mapping->Btn_Trigger_Right) {
rt[port] = (ie.value ? 255 : 0);
}
break;
case EV_ABS:
if (ie.code == controller->mapping->Axis_DPad_X)
{
switch(ie.value)
{
case -1:
SET_FLAG(kcode[port], DC_DPAD_LEFT, 1);
SET_FLAG(kcode[port], DC_DPAD_RIGHT, 0);
break;
case 0:
SET_FLAG(kcode[port], DC_DPAD_LEFT, 0);
SET_FLAG(kcode[port], DC_DPAD_RIGHT, 0);
break;
case 1:
SET_FLAG(kcode[port], DC_DPAD_LEFT, 0);
SET_FLAG(kcode[port], DC_DPAD_RIGHT, 1);
break;
}
}
else if (ie.code == controller->mapping->Axis_DPad_Y)
{
switch(ie.value)
{
case -1:
SET_FLAG(kcode[port], DC_DPAD_UP, 1);
SET_FLAG(kcode[port], DC_DPAD_DOWN, 0);
break;
case 0:
SET_FLAG(kcode[port], DC_DPAD_UP, 0);
SET_FLAG(kcode[port], DC_DPAD_DOWN, 0);
break;
case 1:
SET_FLAG(kcode[port], DC_DPAD_UP, 0);
SET_FLAG(kcode[port], DC_DPAD_DOWN, 1);
break;
}
}
else if (ie.code == controller->mapping->Axis_DPad2_X)
{
switch(ie.value)
{
case -1:
SET_FLAG(kcode[port], DC_DPAD2_LEFT, 1);
SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 0);
break;
case 0:
SET_FLAG(kcode[port], DC_DPAD2_LEFT, 0);
SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 0);
break;
case 1:
SET_FLAG(kcode[port], DC_DPAD2_LEFT, 0);
SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 1);
break;
}
}
else if (ie.code == controller->mapping->Axis_DPad2_X)
{
switch(ie.value)
{
case -1:
SET_FLAG(kcode[port], DC_DPAD2_UP, 1);
SET_FLAG(kcode[port], DC_DPAD2_DOWN, 0);
break;
case 0:
SET_FLAG(kcode[port], DC_DPAD2_UP, 0);
SET_FLAG(kcode[port], DC_DPAD2_DOWN, 0);
break;
case 1:
SET_FLAG(kcode[port], DC_DPAD2_UP, 0);
SET_FLAG(kcode[port], DC_DPAD2_DOWN, 1);
break;
}
}
else if (ie.code == controller->mapping->Axis_Analog_X)
{
printf("%d", ie.value);
joyx[port] = (s8)(ie.value/256);
}
else if (ie.code == controller->mapping->Axis_Analog_Y)
{
joyy[port] = (s8)(ie.value/256);
}
else if (ie.code == controller->mapping->Axis_Trigger_Left)
{
lt[port] = (s8)ie.value;
}
else if (ie.code == controller->mapping->Axis_Trigger_Right)
{
rt[port] = (s8)ie.value;
}
break;
}
}
}
#endif
......@@ -5,8 +5,8 @@
struct s_controller
{
int fd;
ControllerMapping* mapping;
int fd;
ControllerMapping* mapping;
};
typedef struct s_controller Controller;
......@@ -14,12 +14,12 @@ typedef struct s_controller Controller;
#define EVDEV_DEVICE_STRING "/dev/input/event%d"
#ifdef TARGET_PANDORA
#define EVDEV_DEFAULT_DEVICE_ID_1 4
#define EVDEV_DEFAULT_DEVICE_ID_1 4
#else
#define EVDEV_DEFAULT_DEVICE_ID_1 0
#define EVDEV_DEFAULT_DEVICE_ID_1 0
#endif
#define EVDEV_DEFAULT_DEVICE_ID(port) (port == 1 ? EVDEV_DEFAULT_DEVICE_ID_1 : -1)
extern int input_evdev_init(Controller* controller, const char* device);
extern bool input_evdev_handle(Controller* controller, u32 port);
\ No newline at end of file
extern bool input_evdev_handle(Controller* controller, u32 port);
......@@ -2,190 +2,190 @@
#if defined(USE_EVDEV)
ControllerMapping controller_mapping_generic = {
"Generic Controller",
BTN_A,
BTN_B,
BTN_C,
BTN_THUMBL,
BTN_X,
BTN_Y,
BTN_Z,
BTN_START,
BTN_SELECT,
BTN_DPAD_LEFT,
BTN_DPAD_RIGHT,
BTN_DPAD_UP,
BTN_DPAD_DOWN,
-1,
-1,
-1,
-1,
BTN_TL,
BTN_TR,
ABS_HAT0X,
ABS_HAT0Y,
ABS_HAT1X,
ABS_HAT1Y,
ABS_X,
ABS_Y,
ABS_Z,
ABS_RZ,
};
ControllerMapping controller_mapping_generic = {
"Generic Controller",
BTN_A,
BTN_B,
BTN_C,
BTN_THUMBL,
BTN_X,
BTN_Y,
BTN_Z,
BTN_START,
BTN_SELECT,
BTN_DPAD_LEFT,
BTN_DPAD_RIGHT,
BTN_DPAD_UP,
BTN_DPAD_DOWN,
-1,
-1,
-1,
-1,
BTN_TL,
BTN_TR,
ABS_HAT0X,
ABS_HAT0Y,
ABS_HAT1X,
ABS_HAT1Y,
ABS_X,
ABS_Y,
ABS_Z,
ABS_RZ,
};
ControllerMapping controller_mapping_keyboard = {
"Generic Keyboard",
KEY_A,
KEY_B,
KEY_C,
KEY_D,
KEY_X,
KEY_Y,
KEY_Z,
KEY_ENTER,
KEY_ESC,
KEY_LEFT,
KEY_RIGHT,
KEY_UP,
KEY_DOWN,
-1,
-1,
-1,
-1,
KEY_LEFTCTRL,
KEY_RIGHTCTRL,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
};
ControllerMapping controller_mapping_keyboard = {
"Generic Keyboard",
KEY_A,
KEY_B,
KEY_C,
KEY_D,
KEY_X,
KEY_Y,
KEY_Z,
KEY_ENTER,
KEY_ESC,
KEY_LEFT,
KEY_RIGHT,
KEY_UP,
KEY_DOWN,
-1,
-1,
-1,
-1,
KEY_LEFTCTRL,
KEY_RIGHTCTRL,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
};
ControllerMapping controller_mapping_xpad = {
"Xbox 360 Controller (xpad driver)",
BTN_A,
BTN_B,
BTN_TL,
BTN_TR,
BTN_X,
BTN_Y,
BTN_THUMBL,
BTN_START,
BTN_SELECT,
BTN_TRIGGER_HAPPY1,
BTN_TRIGGER_HAPPY2,
BTN_TRIGGER_HAPPY3,
BTN_TRIGGER_HAPPY4,
-1,
-1,
-1,
-1,
-1,
-1,
ABS_HAT0X,
ABS_HAT0Y,
ABS_HAT1X,
ABS_HAT1Y,
ABS_X,
ABS_Y,
ABS_Z,
ABS_RZ
};
ControllerMapping controller_mapping_xpad = {
"Xbox 360 Controller (xpad driver)",
BTN_A,
BTN_B,
BTN_TL,
BTN_TR,
BTN_X,
BTN_Y,
BTN_THUMBL,
BTN_START,