disable the device when unused
This commit is contained in:
parent
350151627e
commit
ca037b1080
1 changed files with 34 additions and 22 deletions
56
virt_ds5.c
56
virt_ds5.c
|
|
@ -495,34 +495,46 @@ static int send_data(int fd, logic_t *const logic) {
|
|||
void *virt_ds5_thread_func(void *ptr) {
|
||||
logic_t *const logic = (logic_t*)ptr;
|
||||
|
||||
fprintf(stderr, "Open uhid-cdev %s\n", path);
|
||||
int fd = open(path, O_RDWR | O_CLOEXEC | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Cannot open uhid-cdev %s: %d\n", path, fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Create uhid device\n");
|
||||
int ret = create(fd);
|
||||
if (ret) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
usleep(1250);
|
||||
|
||||
event(fd, logic);
|
||||
if (logic->gamepad_output != GAMEPAD_OUTPUT_DS5) {
|
||||
// sleep for 500ms before re-checking
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
if (logic->gamepad_output == GAMEPAD_OUTPUT_DS5) {
|
||||
const int res = send_data(fd, logic);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "Error sending HID report: %d\n", res);
|
||||
fprintf(stderr, "Open uhid-cdev %s\n", path);
|
||||
int fd = open(path, O_RDWR | O_CLOEXEC | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Cannot open uhid-cdev %s: %d\n", path, fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Create uhid device\n");
|
||||
int ret = create(fd);
|
||||
if (ret) {
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
usleep(1250);
|
||||
|
||||
event(fd, logic);
|
||||
|
||||
if (logic->gamepad_output == GAMEPAD_OUTPUT_DS5) {
|
||||
const int res = send_data(fd, logic);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "Error sending HID report: %d\n", res);
|
||||
}
|
||||
} else {
|
||||
printf("DualSense has been terminated: closing the device.\n");
|
||||
goto virt_ds5_thread_func_reset;
|
||||
}
|
||||
}
|
||||
|
||||
virt_ds5_thread_func_reset:
|
||||
destroy(fd);
|
||||
}
|
||||
|
||||
destroy(fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue