Commit a49c83b2 authored by Jan Holthuis's avatar Jan Holthuis
Browse files

linux-dist: Make input devices configurable

parent d76e605a
...@@ -38,14 +38,6 @@ ...@@ -38,14 +38,6 @@
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#if defined(USE_EVDEV)
#ifdef TARGET_PANDORA
#define EVDEV_DEVICE "/dev/input/event4"
#else
#define EVDEV_DEVICE "/dev/event2"
#endif
#endif
#if defined(USE_JOYSTICK) #if defined(USE_JOYSTICK)
#include <linux/joystick.h> #include <linux/joystick.h>
#endif #endif
...@@ -127,10 +119,19 @@ void emit_WriteCodeCache(); ...@@ -127,10 +119,19 @@ void emit_WriteCodeCache();
static int evdev_fd = -1; static int evdev_fd = -1;
#if defined(USE_EVDEV) #if defined(USE_EVDEV)
#define EVDEV_DEVICE_STRING "/dev/input/event%d"
#ifdef TARGET_PANDORA
#define EVDEV_DEFAULT_DEVICE_ID 4
#else
#define EVDEV_DEFAULT_DEVICE_ID 0
#endif
int input_evdev_init(const char* device) int input_evdev_init(const char* device)
{ {
char name[256] = "Unknown"; char name[256] = "Unknown";
printf("evdev: Trying to open device at '%s'", device);
int fd = open(device, O_RDONLY); int fd = open(device, O_RDONLY);
if (fd >= 0) if (fd >= 0)
...@@ -237,6 +238,8 @@ static int evdev_fd = -1; ...@@ -237,6 +238,8 @@ static int evdev_fd = -1;
static int joystick_fd = -1; // Joystick file descriptor static int joystick_fd = -1; // Joystick file descriptor
#if defined(USE_JOYSTICK) #if defined(USE_JOYSTICK)
#define JOYSTICK_DEVICE_STRING "/dev/input/js%d"
#define JOYSTICK_DEFAULT_DEVICE_ID 0
#define JOYSTICK_MAP_SIZE 32 #define JOYSTICK_MAP_SIZE 32
const u32 joystick_map_btn_usb[JOYSTICK_MAP_SIZE] = { Btn_Y, Btn_B, Btn_A, Btn_X, 0, 0, 0, 0, 0, Btn_Start }; const u32 joystick_map_btn_usb[JOYSTICK_MAP_SIZE] = { Btn_Y, Btn_B, Btn_A, Btn_X, 0, 0, 0, 0, 0, Btn_Start };
...@@ -254,6 +257,8 @@ static int joystick_fd = -1; // Joystick file descriptor ...@@ -254,6 +257,8 @@ static int joystick_fd = -1; // Joystick file descriptor
int button_count = 0; int button_count = 0;
char name[128] = "Unknown"; char name[128] = "Unknown";
printf("joystick: Trying to open device at '%s'", device);
int fd = open(device, O_RDONLY); int fd = open(device, O_RDONLY);
if(fd >= 0) if(fd >= 0)
...@@ -274,7 +279,7 @@ static int joystick_fd = -1; // Joystick file descriptor ...@@ -274,7 +279,7 @@ static int joystick_fd = -1; // Joystick file descriptor
} }
else else
{ {
perror("joystick: open"); perror("joystick open");
} }
return fd; return fd;
...@@ -390,11 +395,33 @@ static int joystick_fd = -1; // Joystick file descriptor ...@@ -390,11 +395,33 @@ static int joystick_fd = -1; // Joystick file descriptor
void SetupInput() void SetupInput()
{ {
#if defined(USE_EVDEV) #if defined(USE_EVDEV)
evdev_fd = input_evdev_init(EVDEV_DEVICE); int evdev_device_id = cfgLoadInt("input", "evdev_device_id", EVDEV_DEFAULT_DEVICE_ID);
if (evdev_device_id < 0) {
puts("evdev input disabled by config.\n");
}
else
{
int evdev_device_length = snprintf(NULL, 0, EVDEV_DEVICE_STRING, evdev_device_id);
char* evdev_device = (char*)malloc(evdev_device_length + 1);
sprintf(evdev_device, EVDEV_DEVICE_STRING, evdev_device_id);
evdev_fd = input_evdev_init(evdev_device);
free(evdev_device);
}
#endif #endif
#if defined(USE_JOYSTICK) #if defined(USE_JOYSTICK)
joystick_fd = input_joystick_init("/dev/input/js0"); int joystick_device_id = cfgLoadInt("input", "joystick_device_id", JOYSTICK_DEFAULT_DEVICE_ID);
if (joystick_device_id < 0) {
puts("joystick input disabled by config.\n");
}
else
{
int joystick_device_length = snprintf(NULL, 0, JOYSTICK_DEVICE_STRING, joystick_device_id);
char* joystick_device = (char*)malloc(joystick_device_length + 1);
sprintf(joystick_device, JOYSTICK_DEVICE_STRING, joystick_device_id);
joystick_fd = input_joystick_init(joystick_device);
free(joystick_device);
}
#endif #endif
} }
...@@ -463,7 +490,7 @@ void UpdateInputState(u32 port) ...@@ -463,7 +490,7 @@ void UpdateInputState(u32 port)
break; break;
case 'k': KillTex=true; break; case 'k': KillTex=true; break;
case 'a': rt[port] = 255; break; case 'a': rt[port] = 255; break;
case 's': lt[port] = 255; break; case 's': lt[port] = 255; break;
//case 0x1b: die("death by escape key"); break; //this actually quits when i press left for some reason //case 0x1b: die("death by escape key"); break; //this actually quits when i press left for some reason
#ifdef TARGET_PANDORA #ifdef TARGET_PANDORA
...@@ -860,12 +887,12 @@ int main(int argc, wchar* argv[]) ...@@ -860,12 +887,12 @@ int main(int argc, wchar* argv[])
common_linux_setup(); common_linux_setup();
SetupInput();
settings.profile.run_counts=0; settings.profile.run_counts=0;
dc_init(argc,argv); dc_init(argc,argv);
SetupInput();
#if !defined(TARGET_EMSCRIPTEN) #if !defined(TARGET_EMSCRIPTEN)
dc_run(); dc_run();
#else #else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment