diff --git a/main.c b/main.c index 0a54e71..9f3470a 100644 --- a/main.c +++ b/main.c @@ -64,7 +64,7 @@ int main(int argc, char ** argv) { //dev_out_thread_data.timeout_ms = 400; dev_out_thread_data.in_message_pipe_fd = in_message_pipes[0]; dev_out_thread_data.out_message_pipe_fd = out_message_pipes[1]; - dev_out_thread_data.gamepad = GAMEPAD_DUALSHOCK; + dev_out_thread_data.gamepad = GAMEPAD_DUALSENSE; pthread_t dev_in_thread; dev_in_thread_creation = pthread_create(&dev_in_thread, NULL, dev_in_thread_func, (void*)(&dev_in_thread_data)); diff --git a/rogue_enemy.h b/rogue_enemy.h index fabb6d8..8202fda 100644 --- a/rogue_enemy.h +++ b/rogue_enemy.h @@ -51,4 +51,4 @@ inline int32_t div_round_closest(int32_t x, int32_t divisor) { const int32_t __x = x; const int32_t __d = divisor; return ((__x) > 0) == ((__d) > 0) ? (((__x) + ((__d) / 2)) / (__d)) : (((__x) - ((__d) / 2)) / (__d)); -} \ No newline at end of file +} diff --git a/virt_ds4.c b/virt_ds4.c index 4c3af70..b177d33 100644 --- a/virt_ds4.c +++ b/virt_ds4.c @@ -644,7 +644,7 @@ int virt_dualshock_event(virt_dualshock_t *const gamepad, gamepad_status_t *cons out_device_status->motors_intensity[1] = motor_right; ++out_device_status->rumble_events_count; - out_message_t msg = { + const out_message_t msg = { .type = OUT_MSG_TYPE_RUMBLE, .data = { .rumble = { diff --git a/virt_ds5.c b/virt_ds5.c index 47cc384..bd0ee0a 100644 --- a/virt_ds5.c +++ b/virt_ds5.c @@ -1,4 +1,5 @@ #include "virt_ds5.h" +#include "message.h" #include #include @@ -24,6 +25,8 @@ #define DS_OUTPUT_VALID_FLAG2_COMPATIBLE_VIBRATION2 0x04 #define DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION 0x01 +#define DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE 0x04 + #define DS5_SPEC_DELTA_TIME 4096.0f static const char* path = "/dev/uhid"; @@ -219,11 +222,26 @@ int virt_dualsense_event(virt_dualsense_t *const gamepad, gamepad_status_t *cons uint8_t lightbar_blue = ev.u.output.data[47]; if ((valid_flag0 & DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT)) { - if ((valid_flag2 & DS_OUTPUT_VALID_FLAG2_COMPATIBLE_VIBRATION2) || (valid_flag0 & DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION)) { + if (/*(valid_flag2 & DS_OUTPUT_VALID_FLAG2_COMPATIBLE_VIBRATION2) ||*/ (valid_flag0 & DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION)) { out_device_status->motors_intensity[0] = motor_left; out_device_status->motors_intensity[1] = motor_right; ++out_device_status->rumble_events_count; + const out_message_t msg = { + .type = OUT_MSG_TYPE_RUMBLE, + .data = { + .rumble = { + .motors_left = motor_left, + .motors_right = motor_right, + } + } + }; + + const int write_res = write(out_message_pipe_fd, (void*)&msg, sizeof(msg)); + if (write_res != 0) { + return write_res; + } + if (gamepad->debug) { printf( "Updated rumble -- motor_left: %d, motor_right: %d, valid_flag0; %d, valid_flag1: %d\n", @@ -235,6 +253,25 @@ int virt_dualsense_event(virt_dualsense_t *const gamepad, gamepad_status_t *cons } } } + + if (valid_flag1 & DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE) { + const out_message_t msg = { + .type = OUT_MSG_TYPE_LEDS, + .data = { + .leds = { + .r = lightbar_red, + .g = lightbar_green, + .b = lightbar_blue, + } + } + }; + + const int write_res = write(out_message_pipe_fd, (void*)&msg, sizeof(msg)); + if (write_res != 0) { + return write_res; + } + } + break; case UHID_OUTPUT_EV: if (gamepad->debug) {