allow disabling touchbar + use timestamp from the bmi323
This commit is contained in:
parent
bb4ff25130
commit
358fba86d6
15 changed files with 77 additions and 67 deletions
41
allynone.c
41
allynone.c
|
|
@ -15,6 +15,26 @@ static const char* configuration_file = "/etc/ROGueENEMY/config.cfg";
|
|||
int main(int argc, char ** argv) {
|
||||
int ret = 0;
|
||||
|
||||
// fill in configuration from file: automatic fallback to default
|
||||
dev_in_settings_t in_settings = {
|
||||
.enable_qam = true,
|
||||
.ff_gain = 0xFFFF,
|
||||
.rumble_on_mode_switch = true,
|
||||
.m1m2_mode = 0,
|
||||
.touchbar = true,
|
||||
};
|
||||
|
||||
load_in_config(&in_settings, configuration_file);
|
||||
|
||||
dev_out_settings_t out_settings = {
|
||||
.default_gamepad = 0,
|
||||
.nintendo_layout = false,
|
||||
.gamepad_leds_control = true,
|
||||
.gamepad_rumble_control = true,
|
||||
};
|
||||
|
||||
load_out_config(&out_settings, configuration_file);
|
||||
|
||||
input_dev_composite_t* in_devs = NULL;
|
||||
|
||||
int dmi_name_fd = open("/sys/class/dmi/id/board_name", O_RDONLY | O_NONBLOCK);
|
||||
|
|
@ -28,7 +48,7 @@ int main(int argc, char ** argv) {
|
|||
read(dmi_name_fd, bname, sizeof(bname));
|
||||
if (strstr(bname, "RC71L") != NULL) {
|
||||
printf("Running in an Asus ROG Ally device\n");
|
||||
in_devs = rog_ally_device_def();
|
||||
in_devs = rog_ally_device_def(&in_settings);
|
||||
} else if (strstr(bname, "LNVNB161216")) {
|
||||
printf("Running in an Lenovo Legion Go device\n");
|
||||
in_devs = legion_go_device_def();
|
||||
|
|
@ -85,17 +105,9 @@ int main(int argc, char ** argv) {
|
|||
}
|
||||
}
|
||||
},
|
||||
.settings = {
|
||||
.enable_qam = true,
|
||||
.ff_gain = 0xFFFF,
|
||||
.rumble_on_mode_switch = true,
|
||||
.m1m2_mode = 0,
|
||||
}
|
||||
.settings = in_settings,
|
||||
};
|
||||
|
||||
// fill in configuration from file: automatic fallback to default
|
||||
load_in_config(&dev_in_thread_data.settings, configuration_file);
|
||||
|
||||
// populate the output device thread data
|
||||
dev_out_data_t dev_out_thread_data = {
|
||||
.flags = 0x00000000U,
|
||||
|
|
@ -108,16 +120,9 @@ int main(int argc, char ** argv) {
|
|||
}
|
||||
}
|
||||
},
|
||||
.settings = {
|
||||
.default_gamepad = 0,
|
||||
.nintendo_layout = false,
|
||||
.gamepad_leds_control = true,
|
||||
.gamepad_rumble_control = true,
|
||||
}
|
||||
.settings = out_settings,
|
||||
};
|
||||
|
||||
load_out_config(&dev_out_thread_data.settings, configuration_file);
|
||||
|
||||
pthread_t dev_in_thread;
|
||||
dev_in_thread_creation = pthread_create(&dev_in_thread, NULL, dev_in_thread_func, (void*)(&dev_in_thread_data));
|
||||
if (dev_in_thread_creation != 0) {
|
||||
|
|
|
|||
23
dev_in.c
23
dev_in.c
|
|
@ -84,14 +84,6 @@ static int map_message_from_iio(dev_in_iio_t *const in_iio, in_message_t *const
|
|||
|
||||
uint8_t data[32];
|
||||
|
||||
/*
|
||||
struct timeval read_time;
|
||||
gettimeofday(&read_time, NULL);
|
||||
*/
|
||||
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
res = read(dev_iio_get_buffer_fd(in_iio->iiodev), &data[0], sizeof(data));
|
||||
if (res == -1) {
|
||||
res = errno;
|
||||
|
|
@ -106,27 +98,18 @@ static int map_message_from_iio(dev_in_iio_t *const in_iio, in_message_t *const
|
|||
}
|
||||
|
||||
uint16_t *const scan_elements = (uint16_t*)&data[0];
|
||||
int64_t *const timestamp = (int64_t*)&data[16]; // either that or (int64_t*)&data[12]
|
||||
|
||||
messages[0].type = GAMEPAD_SET_ELEMENT;
|
||||
messages[0].data.gamepad_set.element = GAMEPAD_ACCELEROMETER;
|
||||
messages[1].data.gamepad_set.status.accel.sample_time.tv_sec = now.tv_sec;
|
||||
messages[1].data.gamepad_set.status.accel.sample_time.tv_usec = now.tv_nsec / 1000;
|
||||
//messages[0].data.gamepad_set.status.accel.sample_time = read_time;
|
||||
//messages[0].data.gamepad_set.status.accel.x = scan_elements[0];
|
||||
//messages[0].data.gamepad_set.status.accel.y = scan_elements[1];
|
||||
//messages[0].data.gamepad_set.status.accel.z = scan_elements[2];
|
||||
messages[1].data.gamepad_set.status.accel.sample_timestamp_ns = *timestamp;
|
||||
messages[0].data.gamepad_set.status.accel.x = scan_elements[0];
|
||||
messages[0].data.gamepad_set.status.accel.y = (uint16_t)(-1) * scan_elements[2];
|
||||
messages[0].data.gamepad_set.status.accel.z = scan_elements[1];
|
||||
|
||||
messages[1].type = GAMEPAD_SET_ELEMENT;
|
||||
messages[1].data.gamepad_set.element = GAMEPAD_GYROSCOPE;
|
||||
messages[1].data.gamepad_set.status.gyro.sample_time.tv_sec = now.tv_sec;
|
||||
messages[1].data.gamepad_set.status.gyro.sample_time.tv_usec = now.tv_nsec / 1000;
|
||||
//messages[0].data.gamepad_set.status.gyro.sample_time = read_time;
|
||||
//messages[1].data.gamepad_set.status.gyro.x = scan_elements[3];
|
||||
//messages[1].data.gamepad_set.status.gyro.y = scan_elements[4];
|
||||
//messages[1].data.gamepad_set.status.gyro.z = scan_elements[5];
|
||||
messages[1].data.gamepad_set.status.gyro.sample_timestamp_ns = *timestamp;
|
||||
messages[1].data.gamepad_set.status.gyro.x = scan_elements[3];
|
||||
messages[1].data.gamepad_set.status.gyro.y = (uint16_t)(-1) * scan_elements[5];
|
||||
messages[1].data.gamepad_set.status.gyro.z = scan_elements[4];
|
||||
|
|
|
|||
|
|
@ -179,14 +179,14 @@ static void handle_incoming_message_gamepad_set(
|
|||
break;
|
||||
}
|
||||
case GAMEPAD_GYROSCOPE: {
|
||||
inout_gamepad->last_gyro_motion_time = msg_payload->status.gyro.sample_time;
|
||||
inout_gamepad->last_gyro_motion_timestamp_ns = msg_payload->status.gyro.sample_timestamp_ns;
|
||||
inout_gamepad->raw_gyro[0] = msg_payload->status.gyro.x;
|
||||
inout_gamepad->raw_gyro[1] = msg_payload->status.gyro.y;
|
||||
inout_gamepad->raw_gyro[2] = msg_payload->status.gyro.z;
|
||||
break;
|
||||
}
|
||||
case GAMEPAD_ACCELEROMETER: {
|
||||
inout_gamepad->last_accel_motion_time = msg_payload->status.accel.sample_time;
|
||||
inout_gamepad->last_accel_motion_timestamp_ns = msg_payload->status.accel.sample_timestamp_ns;
|
||||
inout_gamepad->raw_accel[0] = msg_payload->status.accel.x;
|
||||
inout_gamepad->raw_accel[1] = msg_payload->status.accel.y;
|
||||
inout_gamepad->raw_accel[2] = msg_payload->status.accel.z;
|
||||
|
|
|
|||
|
|
@ -47,11 +47,11 @@ typedef struct gamepad_status {
|
|||
uint8_t touchpad_press;
|
||||
|
||||
int16_t touchpad_touch_num; // touchpad is inactive when this is -1
|
||||
int16_t touchpad_x;
|
||||
int16_t touchpad_y;
|
||||
int16_t touchpad_x; // 0 to 1920
|
||||
int16_t touchpad_y; // 0 to 1080
|
||||
|
||||
struct timeval last_gyro_motion_time;
|
||||
struct timeval last_accel_motion_time;
|
||||
int64_t last_gyro_motion_timestamp_ns;
|
||||
int64_t last_accel_motion_timestamp_ns;
|
||||
|
||||
double gyro[3]; // | x, y, z| right-hand-rules -- in rad/s
|
||||
double accel[3]; // | x, y, z| positive: right, up, towards player -- in m/s^2
|
||||
|
|
|
|||
19
main.c
19
main.c
|
|
@ -15,6 +15,16 @@ static const char* configuration_file = "/etc/ROGueENEMY/config.cfg";
|
|||
int main(int argc, char ** argv) {
|
||||
int ret = 0;
|
||||
|
||||
dev_in_settings_t in_settings = {
|
||||
.enable_qam = true,
|
||||
.ff_gain = 0xFFFF,
|
||||
.rumble_on_mode_switch = true,
|
||||
.m1m2_mode = 1,
|
||||
.touchbar = true,
|
||||
};
|
||||
|
||||
load_in_config(&in_settings, configuration_file);
|
||||
|
||||
input_dev_composite_t* in_devs = NULL;
|
||||
|
||||
int dmi_name_fd = open("/sys/class/dmi/id/board_name", O_RDONLY | O_NONBLOCK);
|
||||
|
|
@ -28,7 +38,7 @@ int main(int argc, char ** argv) {
|
|||
read(dmi_name_fd, bname, sizeof(bname));
|
||||
if (strstr(bname, "RC71L") != NULL) {
|
||||
printf("Running in an Asus ROG Ally device\n");
|
||||
in_devs = rog_ally_device_def();
|
||||
in_devs = rog_ally_device_def(&in_settings);
|
||||
} else if (strstr(bname, "LNVNB161216")) {
|
||||
printf("Running in an Lenovo Legion Go device\n");
|
||||
in_devs = legion_go_device_def();
|
||||
|
|
@ -51,12 +61,7 @@ int main(int argc, char ** argv) {
|
|||
},
|
||||
}
|
||||
},
|
||||
.settings = {
|
||||
.enable_qam = true,
|
||||
.ff_gain = 0xFFFF,
|
||||
.rumble_on_mode_switch = true,
|
||||
.m1m2_mode = 0,
|
||||
}
|
||||
.settings = in_settings,
|
||||
};
|
||||
|
||||
// fill in configuration from file: automatic fallback to default
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ typedef struct in_message_gamepad_touchpad_active {
|
|||
} in_message_gamepad_touchpad_active_t;
|
||||
|
||||
typedef struct in_message_gamepad_gyro {
|
||||
struct timeval sample_time;
|
||||
int64_t sample_timestamp_ns;
|
||||
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
|
|
@ -62,7 +62,7 @@ typedef struct in_message_gamepad_gyro {
|
|||
} in_message_gamepad_gyro_t;
|
||||
|
||||
typedef struct in_message_gamepad_accel {
|
||||
struct timeval sample_time;
|
||||
int64_t sample_timestamp_ns;
|
||||
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
|
|
|
|||
|
|
@ -1439,6 +1439,11 @@ input_dev_composite_t rc71l_composite = {
|
|||
.leds_fn = rc71l_platform_leds,
|
||||
};
|
||||
|
||||
input_dev_composite_t* rog_ally_device_def(void) {
|
||||
input_dev_composite_t* rog_ally_device_def(const dev_in_settings_t *const settings) {
|
||||
if (!settings->touchbar) {
|
||||
// this is because the touchscreen is the latest in the list
|
||||
rc71l_composite.dev_count -= 1;
|
||||
}
|
||||
|
||||
return &rc71l_composite;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@
|
|||
#include "input_dev.h"
|
||||
#include "settings.h"
|
||||
|
||||
input_dev_composite_t* rog_ally_device_def(void);
|
||||
input_dev_composite_t* rog_ally_device_def(const dev_in_settings_t *const settings);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,13 @@ void load_in_config(dev_in_settings_t *const out_conf, const char* const filepat
|
|||
fprintf(stderr, "m1m2_mode (int) configuration not found. Default value will be used.\n");
|
||||
}
|
||||
|
||||
int touchbar;
|
||||
if (config_lookup_bool(&cfg, "touchbar", &touchbar) != CONFIG_FALSE) {
|
||||
out_conf->touchbar = touchbar;
|
||||
} else {
|
||||
fprintf(stderr, "touchbar (bool) configuration not found. Default value will be used.\n");
|
||||
}
|
||||
|
||||
config_destroy(&cfg);
|
||||
|
||||
load_in_config_err:
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ typedef struct dev_in_settings {
|
|||
bool rumble_on_mode_switch;
|
||||
uint16_t ff_gain;
|
||||
uint8_t m1m2_mode;
|
||||
bool touchbar;
|
||||
} dev_in_settings_t;
|
||||
|
||||
void load_in_config(dev_in_settings_t *const out_conf, const char* const filepath);
|
||||
|
|
|
|||
16
stray_ally.c
16
stray_ally.c
|
|
@ -12,6 +12,15 @@ static const char* configuration_file = "/etc/ROGueENEMY/config.cfg";
|
|||
int main(int argc, char ** argv) {
|
||||
int ret = 0;
|
||||
|
||||
dev_out_settings_t out_settings = {
|
||||
.default_gamepad = 0,
|
||||
.nintendo_layout = false,
|
||||
.gamepad_leds_control = true,
|
||||
.gamepad_rumble_control = true,
|
||||
};
|
||||
|
||||
load_out_config(&out_settings, configuration_file);
|
||||
|
||||
// Create a signal set containing only SIGTERM
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
|
|
@ -42,12 +51,7 @@ int main(int argc, char ** argv) {
|
|||
}
|
||||
}
|
||||
},
|
||||
.settings = {
|
||||
.default_gamepad = 0,
|
||||
.nintendo_layout = false,
|
||||
.gamepad_leds_control = true,
|
||||
.gamepad_rumble_control = true,
|
||||
}
|
||||
.settings = out_settings,
|
||||
};
|
||||
|
||||
load_out_config(&dev_out_thread_data.settings, configuration_file);
|
||||
|
|
|
|||
|
|
@ -642,9 +642,9 @@ void virt_dualshock_close(virt_dualshock_t *const out_gamepad) {
|
|||
* This function arranges HID packets as described on https://www.psdevwiki.com/ps4/DS4-USB
|
||||
*/
|
||||
void virt_dualshock_compose(virt_dualshock_t *const gamepad, gamepad_status_t *const in_device_status, uint8_t *const out_buf) {
|
||||
const int64_t time_us = in_device_status->last_gyro_motion_time.tv_sec * 1000000 + in_device_status->last_gyro_motion_time.tv_usec;
|
||||
const int64_t time_us = in_device_status->last_gyro_motion_timestamp_ns / (int64_t)1000;
|
||||
|
||||
const int delta_time = time_us - gamepad->last_time;
|
||||
const int64_t delta_time = time_us - gamepad->last_time;
|
||||
gamepad->last_time = time_us;
|
||||
|
||||
// find the average Δt in the last 30 non-zero inputs;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ typedef struct virt_dualshock {
|
|||
uint32_t dt_buffer[30];
|
||||
|
||||
uint32_t empty_reports;
|
||||
uint64_t last_time;
|
||||
int64_t last_time;
|
||||
} virt_dualshock_t;
|
||||
|
||||
int virt_dualshock_init(virt_dualshock_t *const gamepad);
|
||||
|
|
|
|||
|
|
@ -1248,9 +1248,9 @@ void virt_dualsense_close(virt_dualsense_t *const out_gamepad) {
|
|||
}
|
||||
|
||||
void virt_dualsense_compose(virt_dualsense_t *const gamepad, gamepad_status_t *const in_device_status, uint8_t *const out_buf) {
|
||||
const int64_t time_us = in_device_status->last_gyro_motion_time.tv_sec * 1000000 + in_device_status->last_gyro_motion_time.tv_usec;
|
||||
const int64_t time_us = in_device_status->last_gyro_motion_timestamp_ns / (int64_t)1000;
|
||||
|
||||
const int delta_time = time_us - gamepad->last_time;
|
||||
const int64_t delta_time = time_us - gamepad->last_time;
|
||||
gamepad->last_time = time_us;
|
||||
|
||||
// find the average Δt in the last 30 non-zero inputs;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ typedef struct virt_dualsense {
|
|||
uint32_t dt_buffer[30];
|
||||
|
||||
uint32_t empty_reports;
|
||||
uint64_t last_time;
|
||||
int64_t last_time;
|
||||
} virt_dualsense_t;
|
||||
|
||||
int virt_dualsense_init(virt_dualsense_t *const gamepad, bool bluetooth);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue