bbcr compiling now

This commit is contained in:
Denis 2023-12-07 00:02:13 +01:00
parent 37c23e1b62
commit 9dfba70c89
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
12 changed files with 261 additions and 211 deletions

View file

@ -2,7 +2,7 @@
CFLAGS= -O3 -march=znver4 -D _DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112L -std=c11 -fPIE -pedantic -Wall -flto=full # -Werror CFLAGS= -O3 -march=znver4 -D _DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112L -std=c11 -fPIE -pedantic -Wall -flto=full # -Werror
LDFLAGS=-lpthread -levdev -ludev -lconfig -lrt -lm -flto=full LDFLAGS=-lpthread -levdev -ludev -lconfig -lrt -lm -flto=full
CC=clang CC=clang
OBJECTS=main.o dev_in.o dev_out.o dev_iio.o dev_evdev.o logic.o platform.o settings.o virt_ds4.o virt_ds5.o virt_mouse_kbd.o virt_evdev.o devices_status.o OBJECTS=main.o dev_in.o dev_out.o dev_iio.o dev_evdev.o platform.o settings.o virt_ds4.o virt_ds5.o virt_mouse_kbd.o virt_evdev.o devices_status.o xbox360.o rog_ally.o
TARGET=rogue-enemy TARGET=rogue-enemy
all: $(TARGET) all: $(TARGET)

View file

@ -50,13 +50,13 @@ static int fill_message_from_iio(dev_in_iio_t *const in_evdev, in_message_t *con
return -EINVAL; return -EINVAL;
} }
static int fill_message_from_evdev(dev_in_ev_t *const in_evdev, in_message_t *const out_msg) { static int fill_message_from_evdev(dev_in_ev_t *const in_evdev, evdev_collected_t *const out_coll) {
int res = 0; int res = 0;
struct input_event read_ev; struct input_event read_ev;
// reset the events count // reset the events count
out_msg->data.event.ev_count = 0; out_coll->ev_count = 0;
// if the device does not support syn reports read just one event and return // if the device does not support syn reports read just one event and return
if (!in_evdev->has_syn_report) { if (!in_evdev->has_syn_report) {
@ -66,13 +66,13 @@ static int fill_message_from_evdev(dev_in_ev_t *const in_evdev, in_message_t *co
} }
// just copy the input event // just copy the input event
out_msg->data.event.ev[out_msg->data.event.ev_count++] = read_ev; out_coll->ev[out_coll->ev_count++] = read_ev;
goto fill_message_from_evdev_err_completed; goto fill_message_from_evdev_err_completed;
} }
// the device does support syn reports so read every event until one is found // the device does support syn reports so read every event until one is found
while (out_msg->data.event.ev_count < MAX_EVDEV_EVENTS_IN_MESSAGE) { while (out_coll->ev_count < MAX_COLLECTED_EVDEV_EVENTS) {
res = libevdev_next_event(in_evdev->evdev, LIBEVDEV_READ_FLAG_BLOCKING, &read_ev); res = libevdev_next_event(in_evdev->evdev, LIBEVDEV_READ_FLAG_BLOCKING, &read_ev);
if (res < 0) { if (res < 0) {
goto fill_message_from_evdev_err; goto fill_message_from_evdev_err;
@ -88,7 +88,7 @@ static int fill_message_from_evdev(dev_in_ev_t *const in_evdev, in_message_t *co
} }
// just copy the input event // just copy the input event
out_msg->data.event.ev[out_msg->data.event.ev_count++] = read_ev; out_coll->ev[out_coll->ev_count++] = read_ev;
} }
fill_message_from_evdev_err: fill_message_from_evdev_err:
@ -96,17 +96,6 @@ fill_message_from_evdev_err_completed:
return res; return res;
} }
static int fill_message_from_device(dev_in_t *const in_dev, in_message_t *const out_msg) {
if (in_dev->type == DEV_IN_TYPE_EV) {
return fill_message_from_evdev(&in_dev->dev.evdev, out_msg);
} else if (in_dev->type == DEV_IN_TYPE_EV) {
return fill_message_from_iio(&in_dev->dev.iio, out_msg);
}
fprintf(stderr, "Unable to recognise device type\n");
return -EINVAL;
}
int open_device( int open_device(
const uinput_filters_t *const in_filters, const uinput_filters_t *const in_filters,
dev_in_ev_t *const out_dev dev_in_ev_t *const out_dev
@ -240,8 +229,6 @@ void* dev_in_thread_func(void *ptr) {
devices[i].type = DEV_IN_TYPE_NONE; devices[i].type = DEV_IN_TYPE_NONE;
} }
in_message_t current_message;
for (;;) { for (;;) {
FD_ZERO(&read_fds); FD_ZERO(&read_fds);
FD_SET(devs->in_message_pipe_fd, &read_fds); FD_SET(devs->in_message_pipe_fd, &read_fds);
@ -299,23 +286,28 @@ void* dev_in_thread_func(void *ptr) {
if (devices[i].type == DEV_IN_TYPE_EV) { if (devices[i].type == DEV_IN_TYPE_EV) {
fd = libevdev_get_fd(devices[i].dev.evdev.evdev); fd = libevdev_get_fd(devices[i].dev.evdev.evdev);
} else if (devices[i].type == DEV_IN_TYPE_IIO) { } else if (devices[i].type == DEV_IN_TYPE_IIO) {
// TODO: implement IIO
} }
if (!FD_ISSET(fd, &read_fds)) { if (!FD_ISSET(fd, &read_fds)) {
continue; continue;
} }
const int fill_msg_res = fill_message_from_device(&devices[i], &current_message); if (devices[i].type == DEV_IN_TYPE_EV) {
if (!fill_msg_res) { evdev_collected_t coll = {
fprintf(stderr, "Error reading from selected input device (%zu): %d\n", i, fill_msg_res); .ev_count = 0
continue; };
}
const ssize_t in_message_pipe_write_res = write(devs->in_message_pipe_fd, (void*)&current_message, sizeof(in_message_t)); const int fill_res = fill_message_from_evdev(&devices[i].dev.evdev, &coll);
if (in_message_pipe_write_res != sizeof(in_message_t)) { if (fill_res != 0) {
fprintf(stderr, "Unable to write data to the in_message pipe: %zu\n", in_message_pipe_write_res); fprintf(stderr, "Unable to fill input_event(s) for device %zd: %d\n", i, fill_res);
continue; continue;
} else {
devs->input_dev_decl[i].ev_input_map_fn(&coll, devs->in_message_pipe_fd, devs->input_dev_decl[i].user_data);
}
} else if (devices[i].type == DEV_IN_TYPE_EV) {
// TODO: implement IIO
//fill_message_from_iio(&devices[i].dev.iio, out_msg);
} }
} }
} }

View file

@ -9,6 +9,10 @@ void *dev_out_thread_func(void *ptr) {
int current_keyboard_fd = -1; int current_keyboard_fd = -1;
int current_mouse_fd = -1; int current_mouse_fd = -1;
// TODO: stats->gamepad.flags |= GAMEPAD_STATUS_FLAGS_PRESS_AND_REALEASE_CENTER;
for (;;) { for (;;) {

View file

@ -6,7 +6,18 @@
#undef INCLUDE_INPUT_DEBUG #undef INCLUDE_INPUT_DEBUG
#undef IGNORE_INPUT_SCAN #undef IGNORE_INPUT_SCAN
typedef uint32_t (*ev_input_filter_t)(struct input_event*, size_t*, uint32_t*, uint32_t*); #define MAX_COLLECTED_EVDEV_EVENTS 16
typedef struct evdev_collected {
struct input_event ev[MAX_COLLECTED_EVDEV_EVENTS];
size_t ev_count;
} evdev_collected_t;
/**
* A function with this signature grapbs input_event data and sends to the pipe messages
* constructed from that data.
*/
typedef void (*ev_map)(const evdev_collected_t *const e, int in_messages_pipe_fd, void* user_data);
typedef enum input_dev_type { typedef enum input_dev_type {
input_dev_type_uinput, input_dev_type_uinput,
@ -29,7 +40,9 @@ typedef struct input_dev {
iio_filters_t iio; iio_filters_t iio;
} filters; } filters;
ev_input_filter_t ev_input_filter_fn; void* user_data;
ev_map ev_input_map_fn;
} input_dev_t; } input_dev_t;

87
main.c
View file

@ -5,76 +5,15 @@
#include "output_dev.h" #include "output_dev.h"
#include "dev_in.h" #include "dev_in.h"
#include "dev_out.h" #include "dev_out.h"
#include "logic.h" #include "rog_ally.h"
/*
logic_t global_logic; logic_t global_logic;
static output_dev_t out_gamepadd_dev = { static output_dev_t out_gamepadd_dev = {
.logic = &global_logic, .logic = &global_logic,
}; };
static input_dev_t in_iio_dev = {
.dev_type = input_dev_type_iio,
.filters = {
.iio = {
.name = "bmi323",
}
},
//.logic = &global_logic,
//.input_filter_fn = input_filter_imu_identity,
};
static input_dev_t in_asus_kb_1_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
//.logic = &global_logic,
//.ev_input_filter_fn = input_filter_asus_kb,
};
static input_dev_t in_asus_kb_2_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
//.logic = &global_logic,
//.ev_input_filter_fn = input_filter_asus_kb,
};
static input_dev_t in_asus_kb_3_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
//.logic = &global_logic,
//.ev_input_filter_fn = input_filter_asus_kb,
};
static uinput_filters_t in_xbox_filters = {
.name = "Microsoft X-Box 360 pad",
};
static input_dev_t in_xbox_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
.ev = {
.name = "Microsoft X-Box 360 pad"
}
},
//.logic = &global_logic,
//.ev_input_filter_fn = input_filter_asus_kb,
};
dev_in_data_t dev_in_thread_data;
dev_out_data_t dev_out_thread_data;
void sig_handler(int signo) void sig_handler(int signo)
{ {
if (signo == SIGINT) { if (signo == SIGINT) {
@ -82,23 +21,23 @@ void sig_handler(int signo)
printf("Received SIGINT\n"); printf("Received SIGINT\n");
} }
} }
*/
dev_in_data_t dev_in_thread_data;
dev_out_data_t dev_out_thread_data;
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
int ret = 0; int ret = 0;
/*
const int logic_creation_res = logic_create(&global_logic); const int logic_creation_res = logic_create(&global_logic);
if (logic_creation_res < 0) { if (logic_creation_res < 0) {
fprintf(stderr, "Unable to create logic: %d", logic_creation_res); fprintf(stderr, "Unable to create logic: %d", logic_creation_res);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
*/
input_dev_t *in_devs[] = { input_dev_t **in_devs = rog_ally_device_def();
&in_xbox_dev, const size_t in_devs_sz = rog_ally_device_def_count();
&in_iio_dev,
&in_asus_kb_1_dev,
&in_asus_kb_2_dev,
&in_asus_kb_3_dev,
};
int out_message_pipes[2]; int out_message_pipes[2];
pipe(out_message_pipes); pipe(out_message_pipes);
@ -111,7 +50,7 @@ int main(int argc, char ** argv) {
dev_in_thread_data.in_message_pipe_fd = in_message_pipes[1]; dev_in_thread_data.in_message_pipe_fd = in_message_pipes[1];
dev_in_thread_data.out_message_pipe_fd = out_message_pipes[0]; dev_in_thread_data.out_message_pipe_fd = out_message_pipes[0];
dev_in_thread_data.input_dev_decl = *in_devs; dev_in_thread_data.input_dev_decl = *in_devs;
dev_in_thread_data.input_dev_cnt = sizeof(in_devs) / sizeof(input_dev_t *); dev_in_thread_data.input_dev_cnt = in_devs_sz;
// populate the output device thread data // populate the output device thread data
//dev_out_thread_data.timeout_ms = 400; //dev_out_thread_data.timeout_ms = 400;
@ -123,7 +62,7 @@ int main(int argc, char ** argv) {
if (dev_in_thread_creation != 0) { if (dev_in_thread_creation != 0) {
fprintf(stderr, "Error creating dev_in thread: %d\n", dev_in_thread_creation); fprintf(stderr, "Error creating dev_in thread: %d\n", dev_in_thread_creation);
ret = -1; ret = -1;
logic_request_termination(&global_logic); //logic_request_termination(&global_logic);
goto main_err; goto main_err;
} }
@ -132,7 +71,7 @@ int main(int argc, char ** argv) {
if (dev_out_thread_creation != 0) { if (dev_out_thread_creation != 0) {
fprintf(stderr, "Error creating dev_out thread: %d\n", dev_out_thread_creation); fprintf(stderr, "Error creating dev_out thread: %d\n", dev_out_thread_creation);
ret = -1; ret = -1;
logic_request_termination(&global_logic); //logic_request_termination(&global_logic);
goto main_err; goto main_err;
} }

View file

@ -6,44 +6,33 @@
#define EV_MESSAGE_FLAGS_IMU 0x00000002U #define EV_MESSAGE_FLAGS_IMU 0x00000002U
#define EV_MESSAGE_FLAGS_MOUSE 0x00000004U #define EV_MESSAGE_FLAGS_MOUSE 0x00000004U
#define MAX_EVDEV_EVENTS_IN_MESSAGE 16
typedef enum in_message_gamepad_btn { typedef enum in_message_gamepad_btn {
GAMEPAD_BTN_A, GAMEPAD_BTN_CROSS,
GAMEPAD_BTN_B, GAMEPAD_BTN_CIRCLE,
GAMEPAD_BTN_X, GAMEPAD_BTN_SQUARE,
GAMEPAD_BTN_Y, GAMEPAD_BTN_TRIANGLE,
GAMEPAD_BTN_START, GAMEPAD_BTN_OPTION,
GAMEPAD_BTN_SELECT, GAMEPAD_BTN_SHARE,
GAMEPAD_BTN_L1, GAMEPAD_BTN_L1,
GAMEPAD_BTN_R1, GAMEPAD_BTN_R1,
GAMEPAD_BTN_L2, GAMEPAD_BTN_L2,
GAMEPAD_BTN_R2, GAMEPAD_BTN_R2,
GAMEPAD_BTN_L3, GAMEPAD_BTN_L3,
GAMEPAD_BTN_R3, GAMEPAD_BTN_R3,
} __packed in_message_gamepad_btn_t; } __packed in_gamepad_element_t;
typedef struct in_message_gamepad_btn_change { typedef struct in_message_gamepad_set_element {
in_message_gamepad_btn_t button; in_gamepad_element_t element;
uint8_t status; uint8_t status;
} __packed in_message_gamepad_btn_change_t; } __packed in_message_gamepad_set_element_t;
typedef enum in_message_gamepad_delta_type { typedef enum in_message_gamepad_action {
GAMEPAD_DELTA_BTN, GAMEPAD_ACTION_PRESS_AND_RELEASE_CENTER,
} __packed in_message_gamepad_delta_type_t; } in_message_gamepad_action_t;
typedef struct in_message_gamepad_delta {
in_message_gamepad_delta_type_t type;
union {
in_message_gamepad_btn_change_t btn;
} data;
} __packed in_message_gamepad_delta_t;
typedef enum in_in_message_type { typedef enum in_in_message_type {
IN_MSG_TYPE_BTN, GAMEPAD_SET_ELEMENT,
IN_MSG_TYPE_SENSOR, GAMEPAD_ACTION,
IN_MSG_TYPE_MACRO,
} __packed in_message_type_t; } __packed in_message_type_t;
typedef struct in_message { typedef struct in_message {
@ -52,7 +41,9 @@ typedef struct in_message {
union { union {
//imu_in_message_t imu; //imu_in_message_t imu;
in_message_gamepad_delta_t gamepad_delta; in_message_gamepad_action_t action;
in_message_gamepad_set_element_t gamepad_set;
} data; } data;
} __packed in_message_t; } __packed in_message_t;

View file

@ -135,83 +135,7 @@ static void update_gs_from_ev(devices_status_t *const stats, in_message_t *const
stats->gamepad.r4 = msg->data.event.ev[1].value; stats->gamepad.r4 = msg->data.event.ev[1].value;
} }
for (uint32_t i = 0; i < msg->data.event.ev_count; ++i) {
if (msg->data.event.ev[i].type == EV_KEY) {
if (msg->data.event.ev[i].code == BTN_EAST) {
if (settings->nintendo_layout) {
stats->gamepad.cross = msg->data.event.ev[i].value;
} else {
stats->gamepad.circle = msg->data.event.ev[i].value;
}
} else if (msg->data.event.ev[i].code == BTN_NORTH) {
if (settings->nintendo_layout) {
stats->gamepad.triangle = msg->data.event.ev[i].value;
} else {
stats->gamepad.square = msg->data.event.ev[i].value;
}
} else if (msg->data.event.ev[i].code == BTN_SOUTH) {
if (settings->nintendo_layout) {
stats->gamepad.circle = msg->data.event.ev[i].value;
} else {
stats->gamepad.cross = msg->data.event.ev[i].value;
}
} else if (msg->data.event.ev[i].code == BTN_WEST) {
if (settings->nintendo_layout) {
stats->gamepad.square = msg->data.event.ev[i].value;
} else {
stats->gamepad.triangle = msg->data.event.ev[i].value;
}
} else if (msg->data.event.ev[i].code == BTN_SELECT) {
stats->gamepad.option = msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == BTN_START) {
stats->gamepad.share = msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == BTN_TR) {
stats->gamepad.r1 = msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == BTN_TL) {
stats->gamepad.l1 = msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == BTN_THUMBR) {
stats->gamepad.r3 = msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == BTN_THUMBL) {
stats->gamepad.l3 = msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == BTN_MODE) {
stats->gamepad.flags |= GAMEPAD_STATUS_FLAGS_PRESS_AND_REALEASE_CENTER;
}
} else if (msg->data.event.ev[i].type == EV_ABS) {
if (msg->data.event.ev[i].code == ABS_X) {
stats->gamepad.joystick_positions[0][0] = (int32_t)msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == ABS_Y) {
stats->gamepad.joystick_positions[0][1] = (int32_t)msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == ABS_RX) {
stats->gamepad.joystick_positions[1][0] = (int32_t)msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == ABS_RY) {
stats->gamepad.joystick_positions[1][1] = (int32_t)msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == ABS_Z) {
stats->gamepad.l2_trigger = (int32_t)msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == ABS_RZ) {
stats->gamepad.r2_trigger = (int32_t)msg->data.event.ev[i].value;
} else if (msg->data.event.ev[i].code == ABS_HAT0X) {
const int v = msg->data.event.ev[i].value;
stats->gamepad.dpad &= 0xF0;
if (v == 0) {
stats->gamepad.dpad |= 0x00;
} else if (v == 1) {
stats->gamepad.dpad |= 0x01;
} else if (v == -1) {
stats->gamepad.dpad |= 0x02;
}
} else if (msg->data.event.ev[i].code == ABS_HAT0Y) {
const int v = msg->data.event.ev[i].value;
stats->gamepad.dpad &= 0x0F;
if (v == 0) {
stats->gamepad.dpad |= 0x00;
} else if (v == 1) {
stats->gamepad.dpad |= 0x20;
} else if (v == -1) {
stats->gamepad.dpad |= 0x10;
}
}
}
}
} }
static void update_gs_from_imu(devices_status_t *const stats, in_message_t *const msg, controller_settings_t *const settings) { static void update_gs_from_imu(devices_status_t *const stats, in_message_t *const msg, controller_settings_t *const settings) {

79
rog_ally.c Normal file
View file

@ -0,0 +1,79 @@
#include "rog_ally.h"
void asus_kbd_ev_map(const evdev_collected_t *const e, int in_messages_pipe_fd, void* user_data) {
in_message_t current_message;
const ssize_t in_message_pipe_write_res = write(in_messages_pipe_fd, (void*)&current_message, sizeof(in_message_t));
if (in_message_pipe_write_res != sizeof(in_message_t)) {
fprintf(stderr, "Unable to write data to the in_message pipe: %zu\n", in_message_pipe_write_res);
}
}
static input_dev_t in_iio_dev = {
.dev_type = input_dev_type_iio,
.filters = {
.iio = {
.name = "bmi323",
}
},
//.logic = &global_logic,
//.input_filter_fn = input_filter_imu_identity,
};
static input_dev_t in_asus_kb_1_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
.ev_input_map_fn = asus_kbd_ev_map,
};
static input_dev_t in_asus_kb_2_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
.ev_input_map_fn = asus_kbd_ev_map,
};
static input_dev_t in_asus_kb_3_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
.ev = {
.name = "Asus Keyboard"
}
},
.ev_input_map_fn = asus_kbd_ev_map,
};
static input_dev_t in_xbox_dev = {
.dev_type = input_dev_type_uinput,
.filters = {
.ev = {
.name = "Microsoft X-Box 360 pad"
}
},
.ev_input_map_fn = xbox360_ev_map,
};
input_dev_t *in_devs[] = {
&in_xbox_dev,
&in_iio_dev,
&in_asus_kb_1_dev,
&in_asus_kb_2_dev,
&in_asus_kb_3_dev,
};
size_t rog_ally_device_def_count() {
return sizeof(in_devs) / sizeof(input_dev_t*);
}
input_dev_t **rog_ally_device_def() {
return in_devs;
}

8
rog_ally.h Normal file
View file

@ -0,0 +1,8 @@
#pragma once
#include "input_dev.h"
#include "xbox360.h"
size_t rog_ally_device_def_count();
input_dev_t **rog_ally_device_def();

View file

@ -27,5 +27,3 @@ void virt_dualshock_compose(virt_dualshock_t *const gamepad, gamepad_status_t *c
int virt_dualshock_send(virt_dualshock_t *const gamepad, uint8_t *const out_buf); int virt_dualshock_send(virt_dualshock_t *const gamepad, uint8_t *const out_buf);
void virt_dualshock_close(virt_dualshock_t *const gamepad); void virt_dualshock_close(virt_dualshock_t *const gamepad);
void *virt_ds4_thread_func(void *ptr);

93
xbox360.c Normal file
View file

@ -0,0 +1,93 @@
#include "xbox360.h"
#include "message.h"
void xbox360_ev_map(const evdev_collected_t *const coll, int in_messages_pipe_fd, void* user_data) {
const xbox360_settings_t *const settings = (xbox360_settings_t*)user_data;
in_message_t current_message;
ssize_t last_write_res = 0;
for (uint32_t i = 0; i < coll->ev_count; ++i) {
last_write_res = sizeof(in_message_t);
if (coll->ev[i].type == EV_KEY) {
current_message.type = GAMEPAD_SET_ELEMENT;
if (coll->ev[i].code == BTN_EAST) {
current_message.data.gamepad_set.element = (settings->nintendo_layout) ? GAMEPAD_BTN_CROSS : GAMEPAD_BTN_CIRCLE;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_NORTH) {
current_message.data.gamepad_set.element = (settings->nintendo_layout) ? GAMEPAD_BTN_TRIANGLE : GAMEPAD_BTN_SQUARE;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_SOUTH) {
current_message.data.gamepad_set.element = (settings->nintendo_layout) ? GAMEPAD_BTN_CIRCLE : GAMEPAD_BTN_CROSS;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_WEST) {
current_message.data.gamepad_set.element = (settings->nintendo_layout) ? GAMEPAD_BTN_SQUARE : GAMEPAD_BTN_TRIANGLE;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_SELECT) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_OPTION;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_START) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_SHARE;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_TR) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_R1;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_TL) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_L1;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_THUMBR) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_R3;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_THUMBL) {
current_message.data.gamepad_set.element = GAMEPAD_BTN_L3;
current_message.data.gamepad_set.status = coll->ev[i].value;
} else if (coll->ev[i].code == BTN_MODE) {
current_message.type = GAMEPAD_ACTION;
current_message.data.action = GAMEPAD_ACTION_PRESS_AND_RELEASE_CENTER;
}
// send the button event over the pipe
last_write_res = write(in_messages_pipe_fd, (void*)&current_message, sizeof(in_message_t));
} /*else if (coll->ev[i].type == EV_ABS) {
if (coll->ev[i].code == ABS_X) {
stats->gamepad.joystick_positions[0][0] = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_Y) {
stats->gamepad.joystick_positions[0][1] = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_RX) {
stats->gamepad.joystick_positions[1][0] = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_RY) {
stats->gamepad.joystick_positions[1][1] = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_Z) {
stats->gamepad.l2_trigger = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_RZ) {
stats->gamepad.r2_trigger = (int32_t)coll->ev[i].value;
} else if (coll->ev[i].code == ABS_HAT0X) {
const int v = coll->ev[i].value;
stats->gamepad.dpad &= 0xF0;
if (v == 0) {
stats->gamepad.dpad |= 0x00;
} else if (v == 1) {
stats->gamepad.dpad |= 0x01;
} else if (v == -1) {
stats->gamepad.dpad |= 0x02;
}
} else if (coll->ev[i].code == ABS_HAT0Y) {
const int v = coll->ev[i].value;
stats->gamepad.dpad &= 0x0F;
if (v == 0) {
stats->gamepad.dpad |= 0x00;
} else if (v == 1) {
stats->gamepad.dpad |= 0x20;
} else if (v == -1) {
stats->gamepad.dpad |= 0x10;
}
}
} */
if (last_write_res != sizeof(in_message_t)) {
fprintf(stderr, "Unable to write data to the in_message pipe: %zd\n", last_write_res);
}
}
}

9
xbox360.h Normal file
View file

@ -0,0 +1,9 @@
#pragma once
#include "input_dev.h"
typedef struct xbox360_settings {
bool nintendo_layout;
} xbox360_settings_t;
void xbox360_ev_map(const evdev_collected_t *const e, int in_messages_pipe_fd, void* user_data);