diff --git a/Makefile b/Makefile index 1a4211a..15435ff 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,16 @@ CXXFLAGS ?= -O2 -Wall LDFLAGS += -Wl,-Bsymbolic-functions -lusb-1.0 GASIA_GAMEPAD_HACKS = false # Set to 'true' to enable hacks +SHANWAN_FAKE_DS3 = false ifeq ($(GASIA_GAMEPAD_HACKS),true) CXXFLAGS += -DGASIA_GAMEPAD_HACKS endif +ifeq ($(SHANWAN_FAKE_DS3),true) + CXXFLAGS += -DSHANWAN_FAKE_DS3 +endif + all: sixad_bins sixpair_bin sixad_bins: diff --git a/bluetooth.cpp b/bluetooth.cpp index 19d2077..419c20e 100644 --- a/bluetooth.cpp +++ b/bluetooth.cpp @@ -203,7 +203,7 @@ void l2cap_accept(int ctl, int csk, int isk, int debug, int legacy) return; } -#ifdef GASIA_GAMEPAD_HACKS +#if defined(GASIA_GAMEPAD_HACKS) || defined(SHANWAN_FAKE_DS3) req.vendor = 0x054c; req.product = 0x0268; req.version = 0x0100; @@ -377,7 +377,7 @@ int create_device(int ctl, int csk, int isk) req.idle_to = 1800; -#ifdef GASIA_GAMEPAD_HACKS +#if defined(GASIA_GAMEPAD_HACKS) || defined(SHANWAN_FAKE_DS3) req.vendor = 0x054c; req.product = 0x0268; req.version = 0x0100; diff --git a/shared.cpp b/shared.cpp index 6af1eb3..5057a27 100644 --- a/shared.cpp +++ b/shared.cpp @@ -277,7 +277,6 @@ void enable_sixaxis(int csk) 0x00, 0x00, 0x00 }; #else - char buf[128]; unsigned char enable[] = { 0x53, /* HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE */ 0xf4, 0x42, 0x03, 0x00, 0x00 @@ -286,7 +285,8 @@ void enable_sixaxis(int csk) /* enable reporting */ send(csk, enable, sizeof(enable), 0); -#ifndef GASIA_GAMEPAD_HACKS +#if !defined(GASIA_GAMEPAD_HACKS) || defined(SHANWAN_FAKE_DS3) + char buf[128]; recv(csk, buf, sizeof(buf), 0); #endif } diff --git a/sixad-bin.cpp b/sixad-bin.cpp index 81551bd..bcd0906 100644 --- a/sixad-bin.cpp +++ b/sixad-bin.cpp @@ -81,7 +81,8 @@ int main(int argc, char *argv[]) open_log("sixad-bin"); syslog(LOG_INFO, "started"); - bacpy(&bdaddr, BDADDR_ANY); + bdaddr_t tmp = {}; + bacpy(&bdaddr, &tmp); ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HIDP); if (ctl < 0) { diff --git a/sixad-sixaxis.cpp b/sixad-sixaxis.cpp index 3544e74..c86d33b 100644 --- a/sixad-sixaxis.cpp +++ b/sixad-sixaxis.cpp @@ -20,6 +20,7 @@ #include "uinput.h" #include +#include #include #include #include @@ -259,6 +260,15 @@ int main(int argc, char *argv[]) return 1; } +#ifdef SHANWAN_FAKE_DS3 + timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 50000; // 0.05 sec. + + if (-1 == setsockopt(csk, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) + syslog(LOG_ERR, "could not set socket read timeout, error: %s", strerror(errno)); +#endif + enable_sixaxis(csk); led_n = set_sixaxis_led(csk, settings.led, settings.rumble.enabled); diff --git a/sixaxis.cpp b/sixaxis.cpp index dee5fa4..3fc8762 100644 --- a/sixaxis.cpp +++ b/sixaxis.cpp @@ -422,7 +422,7 @@ void do_rumble(int csk, int led_n, int weak, int strong, int timeout) setrumble[11] = ledpattern[led_n]; //keep old led send(csk, setrumble, sizeof(setrumble), 0); -#ifndef GASIA_GAMEPAD_HACKS +#if !defined(GASIA_GAMEPAD_HACKS) || defined(SHANWAN_FAKE_DS3) unsigned char buf[128]; recv(csk, buf, sizeof(buf), 0); //MSG_DONTWAIT? #endif @@ -432,8 +432,7 @@ int set_sixaxis_led(int csk, struct dev_led led, int rumble) { int led_n, led_number; -#ifndef GASIA_GAMEPAD_HACKS - int i; +#if !defined(GASIA_GAMEPAD_HACKS) || defined(SHANWAN_FAKE_DS3) unsigned char buf[128]; #endif @@ -480,7 +479,7 @@ int set_sixaxis_led(int csk, struct dev_led led, int rumble) { /* Sixaxis LED animation - Way Cool!! */ if (rumble) setleds[3] = setleds[5] = 0xfe; - for (i=0; i<4; i++) { // repeat it 4 times + for (int i=0; i<4; i++) { // repeat it 4 times if (rumble) setleds[4] = setleds[6] = 0xff; setleds[11] = ledpattern[1]; send(csk, setleds, sizeof(setleds), 0); @@ -545,7 +544,7 @@ int set_sixaxis_led(int csk, struct dev_led led, int rumble) setleds[11] = ledpattern[led_n]; if (rumble) setleds[3] = setleds[4] = setleds[5] = setleds[6] = 0x00; send(csk, setleds, sizeof(setleds), 0); -#ifndef GASIA_GAMEPAD_HACKS +#if !defined(GASIA_GAMEPAD_HACKS) || defined(SHANWAN_FAKE_DS3) recv(csk, buf, sizeof(buf), 0); #endif