bbcr compiling now
This commit is contained in:
parent
37c23e1b62
commit
9dfba70c89
12 changed files with 261 additions and 211 deletions
2
Makefile
2
Makefile
|
|
@ -2,7 +2,7 @@
|
|||
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
|
||||
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
|
||||
|
||||
all: $(TARGET)
|
||||
|
|
|
|||
48
dev_in.c
48
dev_in.c
|
|
@ -50,13 +50,13 @@ static int fill_message_from_iio(dev_in_iio_t *const in_evdev, in_message_t *con
|
|||
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;
|
||||
|
||||
struct input_event read_ev;
|
||||
|
||||
// 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 (!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
|
||||
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;
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (res < 0) {
|
||||
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
|
||||
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:
|
||||
|
|
@ -96,17 +96,6 @@ fill_message_from_evdev_err_completed:
|
|||
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(
|
||||
const uinput_filters_t *const in_filters,
|
||||
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;
|
||||
}
|
||||
|
||||
in_message_t current_message;
|
||||
|
||||
for (;;) {
|
||||
FD_ZERO(&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) {
|
||||
fd = libevdev_get_fd(devices[i].dev.evdev.evdev);
|
||||
} else if (devices[i].type == DEV_IN_TYPE_IIO) {
|
||||
|
||||
// TODO: implement IIO
|
||||
}
|
||||
|
||||
if (!FD_ISSET(fd, &read_fds)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int fill_msg_res = fill_message_from_device(&devices[i], ¤t_message);
|
||||
if (!fill_msg_res) {
|
||||
fprintf(stderr, "Error reading from selected input device (%zu): %d\n", i, fill_msg_res);
|
||||
continue;
|
||||
}
|
||||
if (devices[i].type == DEV_IN_TYPE_EV) {
|
||||
evdev_collected_t coll = {
|
||||
.ev_count = 0
|
||||
};
|
||||
|
||||
const ssize_t in_message_pipe_write_res = write(devs->in_message_pipe_fd, (void*)¤t_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);
|
||||
continue;
|
||||
const int fill_res = fill_message_from_evdev(&devices[i].dev.evdev, &coll);
|
||||
if (fill_res != 0) {
|
||||
fprintf(stderr, "Unable to fill input_event(s) for device %zd: %d\n", i, fill_res);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ void *dev_out_thread_func(void *ptr) {
|
|||
int current_keyboard_fd = -1;
|
||||
int current_mouse_fd = -1;
|
||||
|
||||
|
||||
// TODO: stats->gamepad.flags |= GAMEPAD_STATUS_FLAGS_PRESS_AND_REALEASE_CENTER;
|
||||
|
||||
|
||||
for (;;) {
|
||||
|
||||
|
||||
|
|
|
|||
17
input_dev.h
17
input_dev.h
|
|
@ -6,7 +6,18 @@
|
|||
#undef INCLUDE_INPUT_DEBUG
|
||||
#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 {
|
||||
input_dev_type_uinput,
|
||||
|
|
@ -29,7 +40,9 @@ typedef struct input_dev {
|
|||
iio_filters_t iio;
|
||||
} filters;
|
||||
|
||||
ev_input_filter_t ev_input_filter_fn;
|
||||
void* user_data;
|
||||
|
||||
ev_map ev_input_map_fn;
|
||||
|
||||
} input_dev_t;
|
||||
|
||||
|
|
|
|||
87
main.c
87
main.c
|
|
@ -5,76 +5,15 @@
|
|||
#include "output_dev.h"
|
||||
#include "dev_in.h"
|
||||
#include "dev_out.h"
|
||||
#include "logic.h"
|
||||
#include "rog_ally.h"
|
||||
|
||||
/*
|
||||
logic_t global_logic;
|
||||
|
||||
static output_dev_t out_gamepadd_dev = {
|
||||
.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)
|
||||
{
|
||||
if (signo == SIGINT) {
|
||||
|
|
@ -82,23 +21,23 @@ void sig_handler(int signo)
|
|||
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 ret = 0;
|
||||
|
||||
/*
|
||||
const int logic_creation_res = logic_create(&global_logic);
|
||||
if (logic_creation_res < 0) {
|
||||
fprintf(stderr, "Unable to create logic: %d", logic_creation_res);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
*/
|
||||
input_dev_t **in_devs = rog_ally_device_def();
|
||||
const size_t in_devs_sz = rog_ally_device_def_count();
|
||||
|
||||
int out_message_pipes[2];
|
||||
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.out_message_pipe_fd = out_message_pipes[0];
|
||||
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
|
||||
//dev_out_thread_data.timeout_ms = 400;
|
||||
|
|
@ -123,7 +62,7 @@ int main(int argc, char ** argv) {
|
|||
if (dev_in_thread_creation != 0) {
|
||||
fprintf(stderr, "Error creating dev_in thread: %d\n", dev_in_thread_creation);
|
||||
ret = -1;
|
||||
logic_request_termination(&global_logic);
|
||||
//logic_request_termination(&global_logic);
|
||||
goto main_err;
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +71,7 @@ int main(int argc, char ** argv) {
|
|||
if (dev_out_thread_creation != 0) {
|
||||
fprintf(stderr, "Error creating dev_out thread: %d\n", dev_out_thread_creation);
|
||||
ret = -1;
|
||||
logic_request_termination(&global_logic);
|
||||
//logic_request_termination(&global_logic);
|
||||
goto main_err;
|
||||
}
|
||||
|
||||
|
|
|
|||
45
message.h
45
message.h
|
|
@ -6,44 +6,33 @@
|
|||
#define EV_MESSAGE_FLAGS_IMU 0x00000002U
|
||||
#define EV_MESSAGE_FLAGS_MOUSE 0x00000004U
|
||||
|
||||
#define MAX_EVDEV_EVENTS_IN_MESSAGE 16
|
||||
|
||||
typedef enum in_message_gamepad_btn {
|
||||
GAMEPAD_BTN_A,
|
||||
GAMEPAD_BTN_B,
|
||||
GAMEPAD_BTN_X,
|
||||
GAMEPAD_BTN_Y,
|
||||
GAMEPAD_BTN_START,
|
||||
GAMEPAD_BTN_SELECT,
|
||||
GAMEPAD_BTN_CROSS,
|
||||
GAMEPAD_BTN_CIRCLE,
|
||||
GAMEPAD_BTN_SQUARE,
|
||||
GAMEPAD_BTN_TRIANGLE,
|
||||
GAMEPAD_BTN_OPTION,
|
||||
GAMEPAD_BTN_SHARE,
|
||||
GAMEPAD_BTN_L1,
|
||||
GAMEPAD_BTN_R1,
|
||||
GAMEPAD_BTN_L2,
|
||||
GAMEPAD_BTN_R2,
|
||||
GAMEPAD_BTN_L3,
|
||||
GAMEPAD_BTN_R3,
|
||||
} __packed in_message_gamepad_btn_t;
|
||||
} __packed in_gamepad_element_t;
|
||||
|
||||
typedef struct in_message_gamepad_btn_change {
|
||||
in_message_gamepad_btn_t button;
|
||||
typedef struct in_message_gamepad_set_element {
|
||||
in_gamepad_element_t element;
|
||||
uint8_t status;
|
||||
} __packed in_message_gamepad_btn_change_t;
|
||||
} __packed in_message_gamepad_set_element_t;
|
||||
|
||||
typedef enum in_message_gamepad_delta_type {
|
||||
GAMEPAD_DELTA_BTN,
|
||||
} __packed in_message_gamepad_delta_type_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_message_gamepad_action {
|
||||
GAMEPAD_ACTION_PRESS_AND_RELEASE_CENTER,
|
||||
} in_message_gamepad_action_t;
|
||||
|
||||
typedef enum in_in_message_type {
|
||||
IN_MSG_TYPE_BTN,
|
||||
IN_MSG_TYPE_SENSOR,
|
||||
IN_MSG_TYPE_MACRO,
|
||||
GAMEPAD_SET_ELEMENT,
|
||||
GAMEPAD_ACTION,
|
||||
} __packed in_message_type_t;
|
||||
|
||||
typedef struct in_message {
|
||||
|
|
@ -52,7 +41,9 @@ typedef struct in_message {
|
|||
union {
|
||||
//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;
|
||||
|
||||
} __packed in_message_t;
|
||||
|
|
|
|||
78
output_dev.c
78
output_dev.c
|
|
@ -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;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
79
rog_ally.c
Normal file
79
rog_ally.c
Normal 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*)¤t_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
8
rog_ally.h
Normal 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();
|
||||
|
|
@ -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);
|
||||
|
||||
void virt_dualshock_close(virt_dualshock_t *const gamepad);
|
||||
|
||||
void *virt_ds4_thread_func(void *ptr);
|
||||
|
|
|
|||
93
xbox360.c
Normal file
93
xbox360.c
Normal 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*)¤t_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
9
xbox360.h
Normal 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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue