testing mouse mode and swtich

This commit is contained in:
Denis 2023-12-16 23:15:04 +01:00
parent 4bdff1a50d
commit 587fe7ffcf
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
3 changed files with 52 additions and 17 deletions

View file

@ -333,6 +333,10 @@ void *dev_out_thread_func(void *ptr) {
virt_mouse_send(&mouse_data, &dev_out_data->dev_stats.mouse, &now);
// reset mouse movements now
dev_out_data->dev_stats.mouse.x = 0;
dev_out_data->dev_stats.mouse.y = 0;
// this does reset the for, ensuring every other device has nothing to say
continue;
} else if (kbd_time_diff_usecs >= kbd_report_timing_us) {

View file

@ -85,7 +85,16 @@ static char* find_kernel_sysfs_device_path(struct udev *udev) {
}
static int get_next_mode(int current_mode) {
return 1 + ((current_mode + 1) % 3);
if (current_mode == 1)
return 2;
if (current_mode == 2)
return 3;
if (current_mode == 3)
return 2;
else
fprintf(stderr, "Invalid current mode: %d -- gamepad will be set\n", current_mode);
return 1;
}
static int asus_kbd_ev_map(
@ -184,23 +193,22 @@ static int asus_kbd_ev_map(
char current_mode_str[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int current_mode_read_res = read(gamepad_mode_fd, (void*)current_mode_str, sizeof(current_mode_str));
if (current_mode_read_res > 0) {
close(gamepad_mode_fd);
int current_mode;
sscanf("%d", current_mode_str, &current_mode);
const int new_mode = get_next_mode(current_mode);
printf("Current mode is set to %d -- switching to %d", current_mode, new_mode);
// end the current mode read
close(gamepad_mode_fd);
printf("Current mode is set to %d (read from %s) -- switching to %d", current_mode, current_mode_str, new_mode);
char new_mode_str[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
snprintf(new_mode_str, sizeof(new_mode_str) - 1, "%d", new_mode);
gamepad_mode_fd = open(tmp_path, O_RDONLY);
gamepad_mode_fd = open(tmp_path, O_WRONLY);
if (gamepad_mode_fd > 0) {
if (write(gamepad_mode_fd, new_mode_str, strlen(new_mode_str)) > 0) {
printf("Controller mode switched successfully to %d\n", new_mode);
printf("Controller mode switched successfully to %s\n", new_mode_str);
} else {
fprintf(stderr, "Unable to switch controller mode: %d -- expect bugs\n", errno);
fprintf(stderr, "Unable to switch controller mode to %s: %d -- expect bugs\n", new_mode_str, errno);
}
close(gamepad_mode_fd);
} else {

View file

@ -69,34 +69,32 @@ int virt_mouse_get_fd(virt_mouse_t *const mouse) {
int virt_mouse_send(virt_mouse_t *const mouse, mouse_status_t *const status, struct timeval *const now) {
int res = 0;
struct timeval syn_time;
gettimeofday(&syn_time, NULL);
struct input_event tmp_ev;
if (now == NULL) {
gettimeofday(&tmp_ev.time, NULL);
} else {
if (now != NULL) {
tmp_ev.time = *now;
}
tmp_ev.type = EV_REL;
if (status->x > 0) {
if (status->x != 0) {
tmp_ev.code = REL_X;
tmp_ev.value = status->x;
if (write(mouse->fd, &tmp_ev, sizeof(tmp_ev)) != sizeof(struct input_event)) {
res = errno < 0 ? errno : -1 * errno;
goto virt_mouse_send_err;
} else {
status->x = 0;
}
}
if (status->y > 0) {
if (status->y != 0) {
tmp_ev.code = REL_Y;
tmp_ev.value = status->y;
if (write(mouse->fd, &tmp_ev, sizeof(tmp_ev)) != sizeof(struct input_event)) {
res = errno < 0 ? errno : -1 * errno;
goto virt_mouse_send_err;
} else {
status->y = 0;
}
}
@ -132,6 +130,31 @@ int virt_mouse_send(virt_mouse_t *const mouse, mouse_status_t *const status, str
}
}
#if 0
const struct input_event timestamp_ev = {
.code = MSC_TIMESTAMP,
.type = EV_MSC,
.value = (now.tv_sec - secAtInit)*1000000 + (now.tv_usec - usecAtInit),
.time = now,
};
const ssize_t timestamp_written = write(fd, (void*)&timestamp_ev, sizeof(timestamp_ev));
if (timestamp_written != sizeof(timestamp_ev)) {
fprintf(stderr, "Error in sync: written %ld bytes out of %ld\n", timestamp_written, sizeof(timestamp_ev));
}
#endif
syn_time.tv_usec += 1;
const struct input_event syn_ev = {
.code = SYN_REPORT,
.type = EV_SYN,
.value = 0,
.time = syn_time,
};
const ssize_t sync_written = write(mouse->fd, (void*)&syn_ev, sizeof(syn_ev));
if (sync_written != sizeof(syn_ev)) {
fprintf(stderr, "Error in sync: written %ld bytes out of %ld\n", sync_written, sizeof(syn_ev));
}
virt_mouse_send_err:
return res;
}