Skip to content

Commit

Permalink
Add SHANWAN_FAKE_DS3
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo98 committed Nov 11, 2015
1 parent 02432bb commit 37d7561
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion sixad-bin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions sixad-sixaxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "uinput.h"

#include <cstdlib>
#include <errno.h>
#include <iostream>
#include <poll.h>
#include <signal.h>
Expand Down Expand Up @@ -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);

Expand Down
9 changes: 4 additions & 5 deletions sixaxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 37d7561

Please sign in to comment.