linux-dist/evdev: Clean up namespace a bit

This commit is contained in:
Jan Holthuis 2015-08-19 10:20:52 +02:00
parent 7018ca42c4
commit ceb2a11441
4 changed files with 60 additions and 64 deletions

View File

@ -52,12 +52,12 @@
libevdev_available = true;
}
s8 AxisData::convert(s32 value)
s8 EvdevAxisData::convert(s32 value)
{
return (((value - min) * 255) / range);
}
void AxisData::init(int fd, int code, bool inverted)
void EvdevAxisData::init(int fd, int code, bool inverted)
{
struct input_absinfo abs;
if(code < 0 || ioctl(fd, EVIOCGABS(code), &abs))
@ -85,7 +85,7 @@
}
}
void Controller::init()
void EvdevController::init()
{
this->data_x.init(this->fd, this->mapping->Axis_Analog_X, this->mapping->Axis_Analog_X_Inverted);
this->data_y.init(this->fd, this->mapping->Axis_Analog_Y, this->mapping->Axis_Analog_Y_Inverted);
@ -93,7 +93,7 @@
this->data_trigger_right.init(this->fd, this->mapping->Axis_Trigger_Right, this->mapping->Axis_Trigger_Right_Inverted);
}
std::map<std::string, ControllerMapping> loaded_mappings;
std::map<std::string, EvdevControllerMapping> loaded_mappings;
int load_keycode(ConfigFile* cfg, string section, string dc_key)
{
@ -125,12 +125,12 @@
return code;
}
ControllerMapping load_mapping(FILE* fd)
EvdevControllerMapping load_mapping(FILE* fd)
{
ConfigFile mf;
mf.parse(fd);
ControllerMapping mapping = {
EvdevControllerMapping mapping = {
mf.get("emulator", "mapping_name", "<Unknown>").c_str(),
load_keycode(&mf, "dreamcast", "btn_a"),
load_keycode(&mf, "dreamcast", "btn_b"),
@ -167,7 +167,7 @@
return mapping;
}
int input_evdev_init(Controller* controller, const char* device, const char* custom_mapping_fname = NULL)
int input_evdev_init(EvdevController* controller, const char* device, const char* custom_mapping_fname = NULL)
{
load_libevdev();
@ -260,7 +260,7 @@
}
}
bool input_evdev_handle(Controller* controller, u32 port)
bool input_evdev_handle(EvdevController* controller, u32 port)
{
#define SET_FLAG(field, mask, expr) field =((expr) ? (field & ~mask) : (field | mask))
if (controller->fd < 0 || controller->mapping == NULL)

View File

@ -1,10 +1,44 @@
#include "types.h"
#include "linux-dist/evdev_mappings.h"
#include <linux/input.h>
#pragma once
#include <linux/input.h>
#include "types.h"
struct AxisData
struct EvdevControllerMapping
{
const char* name;
const int Btn_A;
const int Btn_B;
const int Btn_C;
const int Btn_D;
const int Btn_X;
const int Btn_Y;
const int Btn_Z;
const int Btn_Start;
const int Btn_Escape;
const int Btn_DPad_Left;
const int Btn_DPad_Right;
const int Btn_DPad_Up;
const int Btn_DPad_Down;
const int Btn_DPad2_Left;
const int Btn_DPad2_Right;
const int Btn_DPad2_Up;
const int Btn_DPad2_Down;
const int Btn_Trigger_Left;
const int Btn_Trigger_Right;
const int Axis_DPad_X;
const int Axis_DPad_Y;
const int Axis_DPad2_X;
const int Axis_DPad2_Y;
const int Axis_Analog_X;
const int Axis_Analog_Y;
const int Axis_Trigger_Left;
const int Axis_Trigger_Right;
const bool Axis_Analog_X_Inverted;
const bool Axis_Analog_Y_Inverted;
const bool Axis_Trigger_Left_Inverted;
const bool Axis_Trigger_Right_Inverted;
};
struct EvdevAxisData
{
s32 range; // smaller size than 32 bit might cause integer overflows
s32 min;
@ -12,14 +46,14 @@ struct AxisData
s8 convert(int value);
};
struct Controller
struct EvdevController
{
int fd;
ControllerMapping* mapping;
AxisData data_x;
AxisData data_y;
AxisData data_trigger_left;
AxisData data_trigger_right;
EvdevControllerMapping* mapping;
EvdevAxisData data_x;
EvdevAxisData data_y;
EvdevAxisData data_trigger_left;
EvdevAxisData data_trigger_right;
void init();
};
@ -36,8 +70,8 @@ struct Controller
#define EVDEV_DEFAULT_DEVICE_ID(port) (port == 1 ? EVDEV_DEFAULT_DEVICE_ID_1 : -1)
extern int input_evdev_init(Controller* controller, const char* device, const char* mapping_fname);
extern bool input_evdev_handle(Controller* controller, u32 port);
extern int input_evdev_init(EvdevController* controller, const char* device, const char* mapping_fname);
extern bool input_evdev_handle(EvdevController* controller, u32 port);

View File

@ -1,38 +0,0 @@
#pragma once
struct s_evdev_controller_mapping
{
const char* name;
const int Btn_A;
const int Btn_B;
const int Btn_C;
const int Btn_D;
const int Btn_X;
const int Btn_Y;
const int Btn_Z;
const int Btn_Start;
const int Btn_Escape;
const int Btn_DPad_Left;
const int Btn_DPad_Right;
const int Btn_DPad_Up;
const int Btn_DPad_Down;
const int Btn_DPad2_Left;
const int Btn_DPad2_Right;
const int Btn_DPad2_Up;
const int Btn_DPad2_Down;
const int Btn_Trigger_Left;
const int Btn_Trigger_Right;
const int Axis_DPad_X;
const int Axis_DPad_Y;
const int Axis_DPad2_X;
const int Axis_DPad2_Y;
const int Axis_Analog_X;
const int Axis_Analog_Y;
const int Axis_Trigger_Left;
const int Axis_Trigger_Right;
const bool Axis_Analog_X_Inverted;
const bool Axis_Analog_Y_Inverted;
const bool Axis_Trigger_Left_Inverted;
const bool Axis_Trigger_Right_Inverted;
};
typedef struct s_evdev_controller_mapping ControllerMapping;

View File

@ -79,7 +79,7 @@ void emit_WriteCodeCache();
#if defined(USE_EVDEV)
/* evdev input */
static Controller controllers[4] = {
static EvdevController evdev_controllers[4] = {
{ -1, NULL },
{ -1, NULL },
{ -1, NULL },
@ -134,7 +134,7 @@ void SetupInput()
const char* mapping = (cfgExists("input", evdev_config_key) == 2 ? cfgLoadStr("input", evdev_config_key, "").c_str() : NULL);
free(evdev_config_key);
input_evdev_init(&controllers[port], evdev_device, mapping);
input_evdev_init(&evdev_controllers[port], evdev_device, mapping);
free(evdev_device);
}
@ -172,7 +172,7 @@ void UpdateInputState(u32 port)
#endif
#if defined(USE_EVDEV)
input_evdev_handle(&controllers[port], port);
input_evdev_handle(&evdev_controllers[port], port);
#endif
}
@ -213,9 +213,9 @@ void dc_run();
if (joystick_fd >= 0) { close(joystick_fd); }
for (int port = 0; port < 4 ; port++)
{
if (controllers[port]->fd >= 0)
if (evdev_controllers[port]->fd >= 0)
{
close(controllers[port]->fd);
close(evdev_controllers[port]->fd);
}
}