Improved codebase, compiling with clang
This commit is contained in:
parent
da0c1bc35f
commit
9117825bcf
19 changed files with 398 additions and 33 deletions
7
Makefile
7
Makefile
|
|
@ -1,6 +1,7 @@
|
|||
CFLAGS= -g -O0 -D _DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112L -std=c11 -fPIE -pedantic -Wall # -Werror
|
||||
LDFLAGS=-lpthread -levdev -lrt -lm
|
||||
CC=gcc
|
||||
#CFLAGS= -g -O0 -D _DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112L -std=c11 -fPIE -pedantic -Wall # -Werror
|
||||
CFLAGS= -O3 -D _DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112L -std=c11 -fPIE -pedantic -Wall -flto=full # -Werror
|
||||
LDFLAGS=-lpthread -levdev -lrt -lm -flto=full
|
||||
CC=clang
|
||||
OBJECTS=main.o input_dev.o dev_iio.o output_dev.o queue.o logic.o platform.o virt_ds4.o
|
||||
TARGET=rogue_enemy
|
||||
|
||||
|
|
|
|||
71
References/SteamDeck/rdesc
Normal file
71
References/SteamDeck/rdesc
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
00000000 05 0d 09 04 a1 01 85 01 09 22 a1 02 09 42 15 00 |........."...B..|
|
||||
00000010 25 01 75 01 95 01 81 02 95 01 81 03 95 06 81 03 |%.u.............|
|
||||
00000020 75 08 09 51 95 01 81 02 05 01 26 20 03 75 10 55 |u..Q......& .u.U|
|
||||
00000030 0e 65 11 09 30 35 00 46 0b 0a 95 02 81 02 35 01 |.e..05.F......5.|
|
||||
00000040 35 00 46 aa 05 26 00 05 09 31 81 02 35 01 35 00 |5.F..&...1..5.5.|
|
||||
00000050 05 0d 26 ff 00 46 ff 00 95 01 09 48 81 02 09 49 |..&..F.....H...I|
|
||||
00000060 81 02 c0 09 22 a1 02 09 42 15 00 25 01 75 01 95 |...."...B..%.u..|
|
||||
00000070 01 81 02 95 01 81 03 95 06 81 03 75 08 09 51 95 |...........u..Q.|
|
||||
00000080 01 81 02 05 01 26 20 03 75 10 55 0e 65 11 09 30 |.....& .u.U.e..0|
|
||||
00000090 35 00 46 0b 0a 95 02 81 02 35 01 35 00 46 aa 05 |5.F......5.5.F..|
|
||||
000000a0 26 00 05 09 31 81 02 35 01 35 00 05 0d 26 ff 00 |&...1..5.5...&..|
|
||||
000000b0 46 ff 00 95 01 09 48 81 02 09 49 81 02 c0 09 22 |F.....H...I...."|
|
||||
000000c0 a1 02 09 42 15 00 25 01 75 01 95 01 81 02 95 01 |...B..%.u.......|
|
||||
000000d0 81 03 95 06 81 03 75 08 09 51 95 01 81 02 05 01 |......u..Q......|
|
||||
000000e0 26 20 03 75 10 55 0e 65 11 09 30 35 00 46 0b 0a |& .u.U.e..05.F..|
|
||||
000000f0 95 02 81 02 35 01 35 00 46 aa 05 26 00 05 09 31 |....5.5.F..&...1|
|
||||
00000100 81 02 35 01 35 00 05 0d 26 ff 00 46 ff 00 95 01 |..5.5...&..F....|
|
||||
00000110 09 48 81 02 09 49 81 02 c0 09 22 a1 02 09 42 15 |.H...I...."...B.|
|
||||
00000120 00 25 01 75 01 95 01 81 02 95 01 81 03 95 06 81 |.%.u............|
|
||||
00000130 03 75 08 09 51 95 01 81 02 05 01 26 20 03 75 10 |.u..Q......& .u.|
|
||||
00000140 55 0e 65 11 09 30 35 00 46 0b 0a 95 02 81 02 35 |U.e..05.F......5|
|
||||
00000150 01 35 00 46 aa 05 26 00 05 09 31 81 02 35 01 35 |.5.F..&...1..5.5|
|
||||
00000160 00 05 0d 26 ff 00 46 ff 00 95 01 09 48 81 02 09 |...&..F.....H...|
|
||||
00000170 49 81 02 c0 05 0d 27 ff ff 00 00 75 10 95 01 09 |I.....'....u....|
|
||||
00000180 56 81 02 09 54 25 10 95 01 75 08 81 02 85 02 09 |V...T%...u......|
|
||||
00000190 55 95 01 25 0a b1 02 06 00 ff 09 c5 85 05 15 00 |U..%............|
|
||||
000001a0 26 ff 00 75 08 96 00 01 b1 02 c0 06 00 ff 09 01 |&..u............|
|
||||
000001b0 a1 01 15 00 26 ff 00 75 08 85 06 95 3f 09 01 81 |....&..u....?...|
|
||||
000001c0 02 09 01 91 02 c0 05 0d 09 00 a1 01 85 07 09 20 |............... |
|
||||
000001d0 a1 02 09 42 09 44 09 45 15 00 25 01 75 01 95 03 |...B.D.E..%.u...|
|
||||
000001e0 81 02 95 01 81 03 09 32 81 02 95 03 81 03 05 01 |.......2........|
|
||||
000001f0 55 0e 65 11 35 00 75 10 95 02 46 7c 0b 26 ff 0f |U.e.5.u...F|.&..|
|
||||
00000200 09 30 81 02 46 7c 06 26 ff 0f 09 31 81 02 05 0d |.0..F|.&...1....|
|
||||
00000210 09 30 15 01 26 ff 00 75 08 95 01 81 02 c0 c0 |.0..&..u.......|
|
||||
|
||||
static const char steamdeck_rdesk[] = {
|
||||
0x05, 0x0d, 0x09, 0x04, 0xa1, 0x01, 0x85, 0x01, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x42, 0x15, 0x00,
|
||||
0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x95, 0x01, 0x81, 0x03, 0x95, 0x06, 0x81, 0x03,
|
||||
0x75, 0x08, 0x09, 0x51, 0x95, 0x01, 0x81, 0x02, 0x05, 0x01, 0x26, 0x20, 0x03, 0x75, 0x10, 0x55,
|
||||
0x0e, 0x65, 0x11, 0x09, 0x30, 0x35, 0x00, 0x46, 0x0b, 0x0a, 0x95, 0x02, 0x81, 0x02, 0x35, 0x01,
|
||||
0x35, 0x00, 0x46, 0xaa, 0x05, 0x26, 0x00, 0x05, 0x09, 0x31, 0x81, 0x02, 0x35, 0x01, 0x35, 0x00,
|
||||
0x05, 0x0d, 0x26, 0xff, 0x00, 0x46, 0xff, 0x00, 0x95, 0x01, 0x09, 0x48, 0x81, 0x02, 0x09, 0x49,
|
||||
0x81, 0x02, 0xc0, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95,
|
||||
0x01, 0x81, 0x02, 0x95, 0x01, 0x81, 0x03, 0x95, 0x06, 0x81, 0x03, 0x75, 0x08, 0x09, 0x51, 0x95,
|
||||
0x01, 0x81, 0x02, 0x05, 0x01, 0x26, 0x20, 0x03, 0x75, 0x10, 0x55, 0x0e, 0x65, 0x11, 0x09, 0x30,
|
||||
0x35, 0x00, 0x46, 0x0b, 0x0a, 0x95, 0x02, 0x81, 0x02, 0x35, 0x01, 0x35, 0x00, 0x46, 0xaa, 0x05,
|
||||
0x26, 0x00, 0x05, 0x09, 0x31, 0x81, 0x02, 0x35, 0x01, 0x35, 0x00, 0x05, 0x0d, 0x26, 0xff, 0x00,
|
||||
0x46, 0xff, 0x00, 0x95, 0x01, 0x09, 0x48, 0x81, 0x02, 0x09, 0x49, 0x81, 0x02, 0xc0, 0x09, 0x22,
|
||||
0xa1, 0x02, 0x09, 0x42, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x95, 0x01,
|
||||
0x81, 0x03, 0x95, 0x06, 0x81, 0x03, 0x75, 0x08, 0x09, 0x51, 0x95, 0x01, 0x81, 0x02, 0x05, 0x01,
|
||||
0x26, 0x20, 0x03, 0x75, 0x10, 0x55, 0x0e, 0x65, 0x11, 0x09, 0x30, 0x35, 0x00, 0x46, 0x0b, 0x0a,
|
||||
0x95, 0x02, 0x81, 0x02, 0x35, 0x01, 0x35, 0x00, 0x46, 0xaa, 0x05, 0x26, 0x00, 0x05, 0x09, 0x31,
|
||||
0x81, 0x02, 0x35, 0x01, 0x35, 0x00, 0x05, 0x0d, 0x26, 0xff, 0x00, 0x46, 0xff, 0x00, 0x95, 0x01,
|
||||
0x09, 0x48, 0x81, 0x02, 0x09, 0x49, 0x81, 0x02, 0xc0, 0x09, 0x22, 0xa1, 0x02, 0x09, 0x42, 0x15,
|
||||
0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x01, 0x81, 0x02, 0x95, 0x01, 0x81, 0x03, 0x95, 0x06, 0x81,
|
||||
0x03, 0x75, 0x08, 0x09, 0x51, 0x95, 0x01, 0x81, 0x02, 0x05, 0x01, 0x26, 0x20, 0x03, 0x75, 0x10,
|
||||
0x55, 0x0e, 0x65, 0x11, 0x09, 0x30, 0x35, 0x00, 0x46, 0x0b, 0x0a, 0x95, 0x02, 0x81, 0x02, 0x35,
|
||||
0x01, 0x35, 0x00, 0x46, 0xaa, 0x05, 0x26, 0x00, 0x05, 0x09, 0x31, 0x81, 0x02, 0x35, 0x01, 0x35,
|
||||
0x00, 0x05, 0x0d, 0x26, 0xff, 0x00, 0x46, 0xff, 0x00, 0x95, 0x01, 0x09, 0x48, 0x81, 0x02, 0x09,
|
||||
0x49, 0x81, 0x02, 0xc0, 0x05, 0x0d, 0x27, 0xff, 0xff, 0x00, 0x00, 0x75, 0x10, 0x95, 0x01, 0x09,
|
||||
0x56, 0x81, 0x02, 0x09, 0x54, 0x25, 0x10, 0x95, 0x01, 0x75, 0x08, 0x81, 0x02, 0x85, 0x02, 0x09,
|
||||
0x55, 0x95, 0x01, 0x25, 0x0a, 0xb1, 0x02, 0x06, 0x00, 0xff, 0x09, 0xc5, 0x85, 0x05, 0x15, 0x00,
|
||||
0x26, 0xff, 0x00, 0x75, 0x08, 0x96, 0x00, 0x01, 0xb1, 0x02, 0xc0, 0x06, 0x00, 0xff, 0x09, 0x01,
|
||||
0xa1, 0x01, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x85, 0x06, 0x95, 0x3f, 0x09, 0x01, 0x81,
|
||||
0x02, 0x09, 0x01, 0x91, 0x02, 0xc0, 0x05, 0x0d, 0x09, 0x00, 0xa1, 0x01, 0x85, 0x07, 0x09, 0x20,
|
||||
0xa1, 0x02, 0x09, 0x42, 0x09, 0x44, 0x09, 0x45, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x03,
|
||||
0x81, 0x02, 0x95, 0x01, 0x81, 0x03, 0x09, 0x32, 0x81, 0x02, 0x95, 0x03, 0x81, 0x03, 0x05, 0x01,
|
||||
0x55, 0x0e, 0x65, 0x11, 0x35, 0x00, 0x75, 0x10, 0x95, 0x02, 0x46, 0x7c, 0x0b, 0x26, 0xff, 0x0f,
|
||||
0x09, 0x30, 0x81, 0x02, 0x46, 0x7c, 0x06, 0x26, 0xff, 0x0f, 0x09, 0x31, 0x81, 0x02, 0x05, 0x0d,
|
||||
0x09, 0x30, 0x15, 0x01, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81, 0x02, 0xc0, 0xc0
|
||||
};
|
||||
288
References/SteamDeck/virt_deck.c
Normal file
288
References/SteamDeck/virt_deck.c
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
#include "virt_ds4.h"
|
||||
|
||||
#include <bits/types/time_t.h>
|
||||
#include <linux/uhid.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
|
||||
#define DS4_GYRO_RES_PER_DEG_S 1024
|
||||
#define DS4_ACC_RES_PER_G 8192
|
||||
|
||||
static const uint16_t gyro_pitch_bias = 0xfff9;
|
||||
static const uint16_t gyro_yaw_bias = 0x0009;
|
||||
static const uint16_t gyro_roll_bias = 0xfff9;
|
||||
static const uint16_t gyro_pitch_plus = 0x22fe;
|
||||
static const uint16_t gyro_pitch_minus = 0xdcf4;
|
||||
static const uint16_t gyro_yaw_plus = 0x22bb;
|
||||
static const uint16_t gyro_yaw_minus = 0xdd59;
|
||||
static const uint16_t gyro_roll_plus = 0x2289;
|
||||
static const uint16_t gyro_roll_minus = 0xdd68;
|
||||
static const uint16_t gyro_speed_plus = 0x021c /* 540 */; // speed_2x = (gyro_speed_plus + gyro_speed_minus) = 1080;
|
||||
static const uint16_t gyro_speed_minus = 0x021c /* 540 */; // speed_2x = (gyro_speed_plus + gyro_speed_minus) = 1080;
|
||||
static const uint16_t acc_x_plus = 0x20d3;
|
||||
static const uint16_t acc_x_minus = 0xdf07;
|
||||
static const uint16_t acc_y_plus = 0x20bf;
|
||||
static const uint16_t acc_y_minus = 0xe0aa;
|
||||
static const uint16_t acc_z_plus = 0x1ebc;
|
||||
static const uint16_t acc_z_minus = 0xe086;
|
||||
|
||||
static const char* path = "/dev/uhid";
|
||||
|
||||
static unsigned char rdesc[] = {
|
||||
0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0xde, 0x28, 0x05, 0x12, 0x00, 0x02, 0x01, 0x02,
|
||||
0x03, 0x01, 0x09, 0x02, 0x96, 0x00, 0x05, 0x01, 0x00, 0x80, 0xfa, 0x09, 0x04, 0x00, 0x00, 0x01,
|
||||
0x03, 0x01, 0x01, 0x00, 0x09, 0x21, 0x11, 0x01, 0x21, 0x01, 0x22, 0x27, 0x00, 0x07, 0x05, 0x82,
|
||||
0x03, 0x08, 0x00, 0x01, 0x09, 0x04, 0x01, 0x00, 0x01, 0x03, 0x00, 0x02, 0x00, 0x09, 0x21, 0x11,
|
||||
0x01, 0x00, 0x01, 0x22, 0x41, 0x00, 0x07, 0x05, 0x81, 0x03, 0x08, 0x00, 0x01, 0x09, 0x04, 0x02,
|
||||
0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x09, 0x21, 0x11, 0x01, 0x00, 0x01, 0x22, 0x19, 0x00, 0x07,
|
||||
0x05, 0x83, 0x03, 0x40, 0x00, 0x01, 0x08, 0x0b, 0x03, 0x02, 0x02, 0x02, 0x01, 0x00, 0x09, 0x04,
|
||||
0x03, 0x00, 0x01, 0x02, 0x02, 0x01, 0x00, 0x05, 0x24, 0x00, 0x10, 0x01, 0x05, 0x24, 0x01, 0x01,
|
||||
0x02, 0x04, 0x24, 0x02, 0x02, 0x05, 0x24, 0x06, 0x03, 0x04, 0x07, 0x05, 0x84, 0x03, 0x40, 0x00,
|
||||
0xff, 0x09, 0x04, 0x04, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x00, 0x07, 0x05, 0x85, 0x02, 0x40, 0x00,
|
||||
0x00, 0x07, 0x05, 0x05, 0x02, 0x40, 0x00, 0x00,
|
||||
};
|
||||
|
||||
static int uhid_write(int fd, const struct uhid_event *ev)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
ret = write(fd, ev, sizeof(*ev));
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Cannot write to uhid: %d\n", (int)ret);
|
||||
return -errno;
|
||||
} else if (ret != sizeof(*ev)) {
|
||||
fprintf(stderr, "Wrong size written to uhid: %zd != %zu\n",
|
||||
ret, sizeof(ev));
|
||||
return -EFAULT;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int create(int fd)
|
||||
{
|
||||
struct uhid_event ev;
|
||||
|
||||
memset(&ev, 0, sizeof(ev));
|
||||
ev.type = UHID_CREATE;
|
||||
strcpy((char*)ev.u.create.name, "Sony Corp. DualShock 4 [CUH-ZCT2x]");
|
||||
ev.u.create.rd_data = rdesc;
|
||||
ev.u.create.rd_size = sizeof(rdesc);
|
||||
ev.u.create.bus = BUS_USB;
|
||||
ev.u.create.vendor = 0x28de;
|
||||
ev.u.create.product = 0x1205;
|
||||
ev.u.create.version = 0;
|
||||
ev.u.create.country = 0;
|
||||
|
||||
return uhid_write(fd, &ev);
|
||||
}
|
||||
|
||||
static void destroy(int fd)
|
||||
{
|
||||
struct uhid_event ev;
|
||||
|
||||
memset(&ev, 0, sizeof(ev));
|
||||
ev.type = UHID_DESTROY;
|
||||
|
||||
uhid_write(fd, &ev);
|
||||
}
|
||||
|
||||
/* This parses raw output reports sent by the kernel to the device. A normal
|
||||
* uhid program shouldn't do this but instead just forward the raw report.
|
||||
* However, for ducomentational purposes, we try to detect LED events here and
|
||||
* print debug messages for it. */
|
||||
static void handle_output(struct uhid_event *ev)
|
||||
{
|
||||
/* LED messages are adverised via OUTPUT reports; ignore the rest */
|
||||
if (ev->u.output.rtype != UHID_OUTPUT_REPORT) {
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* LED reports have length 2 bytes */
|
||||
if (ev->u.output.size != 2)
|
||||
return;
|
||||
/* first byte is report-id which is 0x02 for LEDs in our rdesc */
|
||||
if (ev->u.output.data[0] != 0x2)
|
||||
return;
|
||||
|
||||
/* print flags payload */
|
||||
fprintf(stderr, "LED output report received with flags %x\n",
|
||||
ev->u.output.data[1]);
|
||||
}
|
||||
|
||||
static int event(int fd)
|
||||
{
|
||||
struct uhid_event ev;
|
||||
ssize_t ret;
|
||||
|
||||
memset(&ev, 0, sizeof(ev));
|
||||
ret = read(fd, &ev, sizeof(ev));
|
||||
if (ret == 0) {
|
||||
fprintf(stderr, "Read HUP on uhid-cdev\n");
|
||||
return -EFAULT;
|
||||
} else if (ret == -1) {
|
||||
return 0;
|
||||
} else if (ret < 0) {
|
||||
fprintf(stderr, "Cannot read uhid-cdev: %d\n", (int)ret);
|
||||
return -errno;
|
||||
} else if (ret != sizeof(ev)) {
|
||||
fprintf(stderr, "Invalid size read from uhid-dev: %zd != %zu\n",
|
||||
ret, sizeof(ev));
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
switch (ev.type) {
|
||||
case UHID_START:
|
||||
fprintf(stderr, "UHID_START from uhid-dev\n");
|
||||
break;
|
||||
case UHID_STOP:
|
||||
fprintf(stderr, "UHID_STOP from uhid-dev\n");
|
||||
break;
|
||||
case UHID_OPEN:
|
||||
fprintf(stderr, "UHID_OPEN from uhid-dev\n");
|
||||
break;
|
||||
case UHID_CLOSE:
|
||||
fprintf(stderr, "UHID_CLOSE from uhid-dev\n");
|
||||
break;
|
||||
case UHID_OUTPUT:
|
||||
fprintf(stderr, "UHID_OUTPUT from uhid-dev\n");
|
||||
handle_output(&ev);
|
||||
break;
|
||||
case UHID_OUTPUT_EV:
|
||||
fprintf(stderr, "UHID_OUTPUT_EV from uhid-dev\n");
|
||||
break;
|
||||
case UHID_GET_REPORT:
|
||||
fprintf(stderr, "UHID_GET_REPORT from uhid-dev, report=%d\n", ev.u.get_report.rnum);
|
||||
if (ev.u.get_report.rnum == 18) {
|
||||
const struct uhid_event mac_addr_response = {
|
||||
.type = UHID_GET_REPORT_REPLY,
|
||||
.u = {
|
||||
.get_report_reply = {
|
||||
.size = 16,
|
||||
.id = ev.u.get_report.id,
|
||||
.err = 0,
|
||||
.data = {
|
||||
0x12, 0xf2, 0xa5, 0x71, 0x68, 0xaf, 0xdc, 0x08,
|
||||
0x25, 0x00, 0x4c, 0x46, 0x49, 0x0e, 0x41, 0x00
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
uhid_write(fd, &mac_addr_response);
|
||||
} else if (ev.u.get_report.rnum == 0xa3) {
|
||||
const struct uhid_event firmware_info_response = {
|
||||
.type = UHID_GET_REPORT_REPLY,
|
||||
.u = {
|
||||
.get_report_reply = {
|
||||
.size = 49,
|
||||
.id = ev.u.get_report.id,
|
||||
.err = 0,
|
||||
.data = {
|
||||
0xa3, 0x53, 0x65, 0x70, 0x20, 0x32, 0x31, 0x20,
|
||||
0x32, 0x30, 0x31, 0x38, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x30, 0x34, 0x3a, 0x35, 0x30, 0x3a, 0x35,
|
||||
0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x0c, 0xb4, 0x01, 0x00, 0x00,
|
||||
0x00, 0x0a, 0xa0, 0x10, 0x20, 0x00, 0xa0, 0x02,
|
||||
0x00
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
uhid_write(fd, &firmware_info_response);
|
||||
} else if (ev.u.get_report.rnum == 0x02) { // dualshock4_get_calibration_data
|
||||
struct uhid_event firmware_info_response = {
|
||||
.type = UHID_GET_REPORT_REPLY,
|
||||
.u = {
|
||||
.get_report_reply = {
|
||||
.size = 37,
|
||||
.id = ev.u.get_report.id,
|
||||
.err = 0,
|
||||
.data = {
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x06, 0x00,
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// bias in kernel is 0 (embedded constant)
|
||||
// speed_2x = speed_2x*DS4_GYRO_RES_PER_DEG_S; calculated by the kernel will be 1080.
|
||||
// As a consequence sens_numer (for every axis) is 1080*1024.
|
||||
// that number will be 1105920
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[1], (const void*)&gyro_pitch_bias, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[3], (const void*)&gyro_yaw_bias, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[5], (const void*)&gyro_roll_bias, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[7], (const void*)&gyro_pitch_plus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[9], (const void*)&gyro_pitch_minus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[11], (const void*)&gyro_yaw_plus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[13], (const void*)&gyro_yaw_minus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[15], (const void*)&gyro_roll_plus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[17], (const void*)&gyro_roll_minus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[19], (const void*)&gyro_speed_plus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[21], (const void*)&gyro_speed_minus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[23], (const void*)&acc_x_plus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[25], (const void*)&acc_x_minus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[27], (const void*)&acc_y_plus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[29], (const void*)&acc_y_minus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[31], (const void*)&acc_z_plus, sizeof(int16_t));
|
||||
memcpy((void*)&firmware_info_response.u.get_report_reply.data[33], (const void*)&acc_z_minus, sizeof(int16_t));
|
||||
|
||||
uhid_write(fd, &firmware_info_response);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Invalid event from uhid-dev: %u\n", ev.type);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
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;
|
||||
}
|
||||
|
||||
uint8_t counter = 0;
|
||||
|
||||
for (;;) {
|
||||
// if ((logic->flags & LOGIC_FLAGS_VIRT_DS4_ENABLE) != 0) {
|
||||
event(fd);
|
||||
|
||||
usleep(128);
|
||||
|
||||
// const int res = send_data(fd, logic, counter);
|
||||
// if (res >= 0) {
|
||||
// ++counter;
|
||||
// } else {
|
||||
// fprintf(stderr, "Error sending HID report: %d", res);
|
||||
// }
|
||||
// } else {
|
||||
// printf("PS4 output not enabled");
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
destroy(fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -602,4 +602,4 @@ int dev_iio_read_imu(const dev_iio_t *const iio, imu_message_t *const out) {
|
|||
memcpy(out->gyro_rad_s, gyro_out, sizeof(double[3]));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,4 +74,4 @@ int dev_iio_read(
|
|||
int dev_iio_read_imu(
|
||||
const dev_iio_t *const iio,
|
||||
imu_message_t *const out
|
||||
);
|
||||
);
|
||||
|
|
|
|||
|
|
@ -18,4 +18,4 @@ typedef struct imu_message {
|
|||
|
||||
double gyro_rad_s[3]; // | x, y, z| right-hand-rules -- in rad/s
|
||||
double accel_m2s[3]; // | x, y, z| positive: right, up, towards player -- in m/s^2
|
||||
} imu_message_t;
|
||||
} imu_message_t;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ static const char *input_path = "/dev/input/";
|
|||
static const char *iio_path = "/sys/bus/iio/devices/";
|
||||
|
||||
uint32_t input_filter_imu_identity(struct input_event* events, size_t* size, uint32_t* count, uint32_t* flags) {
|
||||
int32_t gyro_x = 0, gyro_y = 0, gyro_z = 0, accel_x = 0, accel_y = 0, accel_z = 0;
|
||||
/*
|
||||
int32_t gyro_x = 0, gyro_y = 0, gyro_z = 0, accel_x = 0, accel_y = 0, accel_z = 0;
|
||||
if (gyroscope_mouse_translation > 0) {
|
||||
for (uint32_t i = 0; i < *count; ++i) {
|
||||
if (events[i].type != EV_ABS) {
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ typedef struct input_dev {
|
|||
|
||||
void *input_dev_thread_func(void *ptr);
|
||||
|
||||
int open_and_hide_input();
|
||||
int open_and_hide_input(void);
|
||||
|
||||
uint32_t input_filter_imu_identity(struct input_event* events, size_t* size, uint32_t* count, uint32_t* flags);
|
||||
|
||||
uint32_t input_filter_identity(struct input_event* events, size_t* size, uint32_t* count, uint32_t* flags);
|
||||
|
||||
uint32_t input_filter_asus_kb(struct input_event*, size_t*, uint32_t*, uint32_t* flags);
|
||||
uint32_t input_filter_asus_kb(struct input_event*, size_t*, uint32_t*, uint32_t* flags);
|
||||
|
|
|
|||
2
logic.c
2
logic.c
|
|
@ -112,4 +112,4 @@ logic_begin_status_update_err:
|
|||
|
||||
void logic_end_status_update(logic_t *const logic) {
|
||||
pthread_mutex_unlock(&logic->gamepad_mutex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
logic.h
2
logic.h
|
|
@ -69,4 +69,4 @@ int logic_copy_gamepad_status(logic_t *const logic, gamepad_status_t *const out)
|
|||
|
||||
int logic_begin_status_update(logic_t *const logic);
|
||||
|
||||
void logic_end_status_update(logic_t *const logic);
|
||||
void logic_end_status_update(logic_t *const logic);
|
||||
|
|
|
|||
2
main.c
2
main.c
|
|
@ -74,7 +74,7 @@ static input_dev_t in_xbox_dev = {
|
|||
.ev_input_filter_fn = input_filter_identity,
|
||||
};
|
||||
|
||||
void request_termination() {
|
||||
void request_termination(void) {
|
||||
out_gamepadd_dev.crtl_flags |= OUTPUT_DEV_CTRL_FLAG_EXIT;
|
||||
|
||||
in_xbox_dev.crtl_flags |= INPUT_DEV_CTRL_FLAG_EXIT;
|
||||
|
|
|
|||
|
|
@ -690,7 +690,9 @@ static void update_gs_from_ev(gamepad_status_t *const gs, message_t *const msg)
|
|||
(msg->data.event.ev[1].code == KEY_F16) &&
|
||||
(msg->data.event.ev[1].value == 1)
|
||||
) {
|
||||
printf("RC71L AC button short-press detected");
|
||||
#if defined(INCLUDE_OUTPUT_DEBUG)
|
||||
printf("RC71L AC button short-press detected\n");
|
||||
#endif
|
||||
gs->flags |= GAMEPAD_STATUS_FLAGS_PRESS_AND_REALEASE_CENTER;
|
||||
}
|
||||
} else if (msg->data.event.ev[i].type == EV_ABS) {
|
||||
|
|
|
|||
|
|
@ -66,4 +66,4 @@ typedef struct output_dev {
|
|||
|
||||
int create_output_dev(const char* uinput_path, output_dev_type_t type);
|
||||
|
||||
void *output_dev_thread_func(void *ptr);
|
||||
void *output_dev_thread_func(void *ptr);
|
||||
|
|
|
|||
|
|
@ -74,4 +74,4 @@ int is_mouse_mode(rc71l_platform_t *const platform) {
|
|||
|
||||
int is_macro_mode(rc71l_platform_t *const platform) {
|
||||
return platform != NULL ? platform->mode == 2 : 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ int is_mouse_mode(rc71l_platform_t *const platform);
|
|||
|
||||
int is_gamepad_mode(rc71l_platform_t *const platform);
|
||||
|
||||
int is_macro_mode(rc71l_platform_t *const platform);
|
||||
int is_macro_mode(rc71l_platform_t *const platform);
|
||||
|
||||
|
|
|
|||
2
queue.h
2
queue.h
|
|
@ -23,4 +23,4 @@ int queue_push_timeout(queue_t* const q, void *in_item, int timeout_ms);
|
|||
|
||||
int queue_pop(queue_t* queue, void **out_item);
|
||||
|
||||
int queue_pop_timeout(queue_t* const q, void **out_item, int timeout_ms);
|
||||
int queue_pop_timeout(queue_t* const q, void **out_item, int timeout_ms);
|
||||
|
|
|
|||
|
|
@ -30,4 +30,4 @@
|
|||
#define LSB_PER_RAD_S_2000_DEG_S_STR "0.001064724"
|
||||
|
||||
#define LSB_PER_16G ((double)0.004785)
|
||||
#define LSB_PER_16G_STR "0.004785"
|
||||
#define LSB_PER_16G_STR "0.004785"
|
||||
|
|
|
|||
30
virt_ds4.c
30
virt_ds4.c
|
|
@ -557,11 +557,11 @@ static ds4_dpad_status_t ds4_dpad_from_gamepad(uint8_t dpad) {
|
|||
return DPAD_RELEASED;
|
||||
}
|
||||
|
||||
static int send_data(int fd, logic_t *const logic, uint8_t counter) {
|
||||
static int send_data(int fd, logic_t *const logic) {
|
||||
struct timeval first_read_time;
|
||||
static int first_read_time_arrived = 0;
|
||||
|
||||
gamepad_status_t gs = {};
|
||||
gamepad_status_t gs;
|
||||
const int gs_copy_res = logic_copy_gamepad_status(logic, &gs);
|
||||
if (gs_copy_res != 0) {
|
||||
fprintf(stderr, "Unable to copy the gamepad status: %d\n", gs_copy_res);
|
||||
|
|
@ -643,7 +643,14 @@ static int send_data(int fd, logic_t *const logic, uint8_t counter) {
|
|||
buf[4] = ((uint64_t)((int64_t)gs.joystick_positions[1][1] + (int64_t)32768) >> (uint64_t)8); // R stick, Y axis
|
||||
buf[5] = get_buttons_byte_by_gs(&gs) | (uint8_t)ds4_dpad_from_gamepad(gs.dpad);
|
||||
buf[6] = get_buttons_byte2_by_gs(&gs);
|
||||
buf[7] = ((counter % (uint8_t)64) << ((uint8_t)2)) | get_buttons_byte3_by_gs(&gs);
|
||||
|
||||
/*
|
||||
static uint8_t counter = 0;
|
||||
buf[7] = (((counter++) % (uint8_t)64) << ((uint8_t)2)) | get_buttons_byte3_by_gs(&gs);
|
||||
*/
|
||||
|
||||
buf[7] = get_buttons_byte3_by_gs(&gs);
|
||||
|
||||
buf[8] = gs.l2_trigger;
|
||||
buf[9] = gs.r2_trigger;
|
||||
memcpy(&buf[10], ×tamp, sizeof(timestamp));
|
||||
|
|
@ -695,27 +702,22 @@ void *virt_ds4_thread_func(void *ptr) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t counter = 0;
|
||||
|
||||
for (;;) {
|
||||
usleep(128);
|
||||
|
||||
if ((logic->flags & LOGIC_FLAGS_VIRT_DS4_ENABLE) != 0) {
|
||||
event(fd);
|
||||
|
||||
usleep(128);
|
||||
|
||||
|
||||
const int res = send_data(fd, logic, counter);
|
||||
if (res >= 0) {
|
||||
++counter;
|
||||
} else {
|
||||
const int res = send_data(fd, logic);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "Error sending HID report: %d", res);
|
||||
}
|
||||
} else {
|
||||
printf("PS4 output not enabled");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
destroy(fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
#include "logic.h"
|
||||
|
||||
void *virt_ds4_thread_func(void *ptr);
|
||||
void *virt_ds4_thread_func(void *ptr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue