leds test

This commit is contained in:
Denis 2023-12-08 20:49:24 +01:00
parent 69052dda16
commit 0db06c226c
No known key found for this signature in database
GPG key ID: DD9B63F805CF5C03
4 changed files with 41 additions and 4 deletions

2
main.c
View file

@ -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));

View file

@ -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));
}
}

View file

@ -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 = {

View file

@ -1,4 +1,5 @@
#include "virt_ds5.h"
#include "message.h"
#include <bits/types/time_t.h>
#include <linux/uhid.h>
@ -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) {