Prepare to support normal dualsense
This commit is contained in:
parent
43b3871a7a
commit
b27f1778e3
8 changed files with 76 additions and 21 deletions
|
|
@ -32,6 +32,7 @@ int main(int argc, char ** argv) {
|
|||
.gamepad_leds_control = true,
|
||||
.gamepad_rumble_control = true,
|
||||
.controller_bluetooth = false,
|
||||
.dualsense_edge = false,
|
||||
};
|
||||
|
||||
load_out_config(&out_settings, configuration_file);
|
||||
|
|
|
|||
|
|
@ -7,4 +7,5 @@ gamepad_rumble_control = true;
|
|||
gamepad_leds_control = true;
|
||||
m1m2_mode = 1;
|
||||
touchbar = true;
|
||||
controller_bluetooth = false;
|
||||
controller_bluetooth = true;
|
||||
dualsense_edge = false;
|
||||
15
dev_out.c
15
dev_out.c
|
|
@ -8,8 +8,6 @@
|
|||
#include "virt_mouse.h"
|
||||
#include "virt_kbd.h"
|
||||
|
||||
#include <libconfig.h>
|
||||
|
||||
static void handle_incoming_message_gamepad_action(
|
||||
const dev_out_settings_t *const in_settings,
|
||||
const in_message_gamepad_action_t *const msg_payload,
|
||||
|
|
@ -442,7 +440,12 @@ void *dev_out_thread_func(void *ptr) {
|
|||
const int64_t gamepad_report_timing_us = 1250;
|
||||
|
||||
if (current_gamepad == GAMEPAD_DUALSENSE) {
|
||||
const int ds5_init_res = virt_dualsense_init(&controller_data.ds5, dev_out_data->settings.controller_bluetooth);
|
||||
const int ds5_init_res = virt_dualsense_init(
|
||||
&controller_data.ds5,
|
||||
dev_out_data->settings.controller_bluetooth,
|
||||
dev_out_data->settings.dualsense_edge
|
||||
);
|
||||
|
||||
if (ds5_init_res != 0) {
|
||||
fprintf(stderr, "Unable to initialize the DualSense device: %d\n", ds5_init_res);
|
||||
} else {
|
||||
|
|
@ -450,7 +453,11 @@ void *dev_out_thread_func(void *ptr) {
|
|||
printf("DualSense initialized: fd=%d, bluetooth=%s\n", current_gamepad_fd, dev_out_data->settings.controller_bluetooth ? "true" : "false");
|
||||
}
|
||||
} else if (current_gamepad == GAMEPAD_DUALSHOCK) {
|
||||
const int ds4_init_res = virt_dualshock_init(&controller_data.ds4, dev_out_data->settings.controller_bluetooth);
|
||||
const int ds4_init_res = virt_dualshock_init(
|
||||
&controller_data.ds4,
|
||||
dev_out_data->settings.controller_bluetooth
|
||||
);
|
||||
|
||||
if (ds4_init_res != 0) {
|
||||
fprintf(stderr, "Unable to initialize the DualShock device: %d\n", ds4_init_res);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -106,6 +106,13 @@ void load_out_config(dev_out_settings_t *const out_conf, const char* const filep
|
|||
fprintf(stderr, "controller_bluetooth (bool) configuration not found. Default value will be used.\n");
|
||||
}
|
||||
|
||||
int dualsense_edge;
|
||||
if (config_lookup_bool(&cfg, "dualsense_edge", &dualsense_edge) != CONFIG_FALSE) {
|
||||
out_conf->dualsense_edge = dualsense_edge;
|
||||
} else {
|
||||
fprintf(stderr, "dualsense_edge (bool) configuration not found. Default value will be used.\n");
|
||||
}
|
||||
|
||||
config_destroy(&cfg);
|
||||
|
||||
load_out_config_err:
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ typedef struct dev_out_settings {
|
|||
bool gamepad_leds_control;
|
||||
bool gamepad_rumble_control;
|
||||
bool controller_bluetooth;
|
||||
bool dualsense_edge;
|
||||
} dev_out_settings_t;
|
||||
|
||||
void load_out_config(dev_out_settings_t *const out_conf, const char* const filepath);
|
||||
|
|
@ -18,6 +18,7 @@ int main(int argc, char ** argv) {
|
|||
.gamepad_leds_control = true,
|
||||
.gamepad_rumble_control = true,
|
||||
.controller_bluetooth = false,
|
||||
.dualsense_edge = false,
|
||||
};
|
||||
|
||||
load_out_config(&out_settings, configuration_file);
|
||||
|
|
|
|||
35
virt_ds5.c
35
virt_ds5.c
|
|
@ -40,10 +40,16 @@ static uint8_t PS_INPUT_CRC32_SEED = 0xA1;
|
|||
static uint8_t PS_OUTPUT_CRC32_SEED = 0xA2;
|
||||
static uint8_t PS_FEATURE_CRC32_SEED = 0xA3;
|
||||
|
||||
#define DS5_EDGE_NAME "Sony Corp. DualSense Edge wireless controller (PS5)"
|
||||
#define DS5_EDGE_VERSION 256
|
||||
#define DS5_EDGE_VENDOR 0x054C
|
||||
#define DS5_EDGE_PRODUCT 0x0DF2
|
||||
|
||||
#define DS5_NAME "Sony Corp. DualSense Edge wireless controller (PS5)"
|
||||
#define DS5_VERSION 256
|
||||
#define DS5_VENDOR 0x054C
|
||||
#define DS5_PRODUCT 0x0DF2
|
||||
|
||||
static const char* path = "/dev/uhid";
|
||||
|
||||
//static const char* const MAC_ADDR_STR = "e8:47:3a:d6:e7:74";
|
||||
|
|
@ -890,22 +896,32 @@ static int uhid_write(int fd, const struct uhid_event *ev)
|
|||
}
|
||||
}
|
||||
|
||||
static int create(int fd, bool bluetooth)
|
||||
static int create(int fd, bool bluetooth, bool dualsense_edge)
|
||||
{
|
||||
struct uhid_event ev;
|
||||
|
||||
char uniq[sizeof(ev.u.create.uniq)];
|
||||
sprintf(uniq, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
|
||||
MAC_ADDR[5], MAC_ADDR[4], MAC_ADDR[3], MAC_ADDR[2], MAC_ADDR[1], MAC_ADDR[0]
|
||||
);
|
||||
|
||||
memset(&ev, 0, sizeof(ev));
|
||||
ev.type = UHID_CREATE;
|
||||
strcpy((char*)ev.u.create.name, "Sony Corp. DualSense Edge wireless controller (PS5)");
|
||||
|
||||
if (dualsense_edge) {
|
||||
strcpy((char*)ev.u.create.name, DS5_EDGE_NAME);
|
||||
} else {
|
||||
strcpy((char*)ev.u.create.name, DS5_NAME);
|
||||
}
|
||||
|
||||
ev.u.create.rd_data = bluetooth ? rdesc_bt : rdesc;
|
||||
ev.u.create.rd_size = bluetooth ? sizeof(rdesc_bt) : sizeof(rdesc);
|
||||
ev.u.create.bus = bluetooth ? BUS_BLUETOOTH : BUS_USB;
|
||||
ev.u.create.vendor = DS5_EDGE_VENDOR;
|
||||
ev.u.create.product = DS5_EDGE_PRODUCT;
|
||||
ev.u.create.version = DS5_EDGE_VERSION;
|
||||
ev.u.create.vendor = dualsense_edge ? DS5_EDGE_VENDOR : DS5_VENDOR;
|
||||
ev.u.create.product = dualsense_edge ? DS5_EDGE_PRODUCT : DS5_PRODUCT;
|
||||
ev.u.create.version = dualsense_edge ? DS5_EDGE_VERSION : DS5_VERSION;
|
||||
ev.u.create.country = 0;
|
||||
memset(&ev.u.create.uniq, 0, sizeof(ev.u.create.uniq));
|
||||
memcpy(&ev.u.create.uniq, (void*)MAC_ADDR, sizeof(MAC_ADDR));
|
||||
memcpy(&ev.u.create.uniq, (void*)uniq, sizeof(uniq));
|
||||
|
||||
return uhid_write(fd, &ev);
|
||||
}
|
||||
|
|
@ -920,9 +936,10 @@ static void destroy(int fd)
|
|||
uhid_write(fd, &ev);
|
||||
}
|
||||
|
||||
int virt_dualsense_init(virt_dualsense_t *const out_gamepad, bool bluetooth) {
|
||||
int virt_dualsense_init(virt_dualsense_t *const out_gamepad, bool bluetooth, bool dualsense_edge) {
|
||||
int ret = 0;
|
||||
|
||||
out_gamepad->edge_model = dualsense_edge;
|
||||
out_gamepad->bluetooth = bluetooth;
|
||||
out_gamepad->dt_sum = 0;
|
||||
out_gamepad->dt_buffer_current = 0;
|
||||
|
|
@ -939,7 +956,7 @@ int virt_dualsense_init(virt_dualsense_t *const out_gamepad, bool bluetooth) {
|
|||
goto virt_dualshock_init_err;
|
||||
}
|
||||
|
||||
ret = create(out_gamepad->fd, bluetooth);
|
||||
ret = create(out_gamepad->fd, bluetooth, dualsense_edge);
|
||||
if (ret) {
|
||||
fprintf(stderr, "Error creating uhid device: %d\n", ret);
|
||||
close(out_gamepad->fd);
|
||||
|
|
|
|||
32
virt_ds5.h
32
virt_ds5.h
|
|
@ -15,6 +15,8 @@ typedef struct virt_dualsense {
|
|||
|
||||
bool bluetooth;
|
||||
|
||||
bool edge_model;
|
||||
|
||||
uint8_t seq_num;
|
||||
|
||||
uint32_t dt_sum;
|
||||
|
|
@ -25,15 +27,33 @@ typedef struct virt_dualsense {
|
|||
int64_t last_time;
|
||||
} virt_dualsense_t;
|
||||
|
||||
int virt_dualsense_init(virt_dualsense_t *const gamepad, bool bluetooth);
|
||||
int virt_dualsense_init(
|
||||
virt_dualsense_t *const gamepad,
|
||||
bool bluetooth,
|
||||
bool dualsense_edge
|
||||
);
|
||||
|
||||
int virt_dualsense_get_fd(virt_dualsense_t *const gamepad);
|
||||
int virt_dualsense_get_fd(
|
||||
virt_dualsense_t *const gamepad
|
||||
);
|
||||
|
||||
int virt_dualsense_event(virt_dualsense_t *const gamepad, gamepad_status_t *const out_device_status);
|
||||
int virt_dualsense_event(
|
||||
virt_dualsense_t *const gamepad,
|
||||
gamepad_status_t *const out_device_status
|
||||
);
|
||||
|
||||
void virt_dualsense_compose(virt_dualsense_t *const gamepad, gamepad_status_t *const in_device_status, uint8_t *const out_buf);
|
||||
void virt_dualsense_compose(
|
||||
virt_dualsense_t *const gamepad,
|
||||
gamepad_status_t *const in_device_status,
|
||||
uint8_t *const out_buf
|
||||
);
|
||||
|
||||
int virt_dualsense_send(virt_dualsense_t *const gamepad, uint8_t *const out_buf);
|
||||
int virt_dualsense_send(
|
||||
virt_dualsense_t *const gamepad,
|
||||
uint8_t *const out_buf
|
||||
);
|
||||
|
||||
void virt_dualsense_close(virt_dualsense_t *const gamepad);
|
||||
void virt_dualsense_close(
|
||||
virt_dualsense_t *const gamepad
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue