Skip to content

Commit

Permalink
Add support for PS3 Rock Band guitars
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjay900 authored and AKuHAK committed Mar 23, 2023
1 parent 2320fdd commit 20628ba
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion include/ds34common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define DS4_PID 0x05C4 // PS4 Controller
#define DS4_PID_SLIM 0x09CC // PS4 Slim Controller
#define GUITAR_HERO_PS3_PID 0x0100 // PS3 Guitar Hero Guitar
#define ROCK_BAND_PS3_PID 0x0200 // PS3 Rock Band Guitar

// NOTE: struct member prefixed with "n" means it's active-low (i.e. value of 0 indicates button is pressed, value 1 is released)
enum DS2ButtonBitNumber {
Expand Down Expand Up @@ -294,8 +295,9 @@ void translate_pad_ds3(const struct ds3report *in, struct ds2report *out, uint8_
* Translate PS3 Guitar pad data into DS2 Guitar pad data.
* @param in PS3 Guitar report
* @param out PS2 Guitar report
* @param guitar_hero_format set to 1 if this is a guitar hero guitar, set to 0 if this is a rock band guitar
*/
void translate_pad_guitar(const struct ds3guitarreport *in, struct ds2report *out);
void translate_pad_guitar(const struct ds3guitarreport *in, struct ds2report *out, uint8_t guitar_hero_format);

/**
* Translate DS3 pad data into DS2 pad data.
Expand Down
13 changes: 9 additions & 4 deletions modules/pademu/ds34common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "loadcore.h"
#include "sysclib.h"

void translate_pad_guitar(const struct ds3guitarreport *in, struct ds2report *out)
void translate_pad_guitar(const struct ds3guitarreport *in, struct ds2report *out, uint8_t guitar_hero_format)
{
out->RightStickX = 0x7F;
out->RightStickY = 0x7F;
Expand All @@ -25,13 +25,18 @@ void translate_pad_guitar(const struct ds3guitarreport *in, struct ds2report *ou
u8 dpad = in->Dpad > DS4DpadDirectionReleased ? DS4DpadDirectionReleased : in->Dpad;

out->nButtonStateL = ~(in->Select | in->Start << 3 | dpad_mapping[dpad]);
out->nButtonStateH = ~(in->Green << 1 | in->Yellow << 4 | in->Red << 5 | in->Blue << 6 | in->Orange << 7);

out->nLeft = 0;
out->nL2 = 1;

if (in->AccelX > 512 || in->AccelX < 432) {
out->nL2 = 0;
if (guitar_hero_format) {
// GH PS3 Guitars swap Yellow and Blue
out->nButtonStateH = ~(in->Green << 1 | in->Yellow << 4 | in->Red << 5 | in->Blue << 6 | in->Orange << 7);
if (in->AccelX > 512 || in->AccelX < 432) {
out->nL2 = 0;
}
} else {
out->nButtonStateH = ~(in->StarPower | in->Green << 1 | in->Blue << 4 | in->Red << 5 | in->Yellow << 6 | in->Orange << 7);
}
}

Expand Down
11 changes: 7 additions & 4 deletions modules/pademu/ds34usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ int usb_connect(int devId)
ds34pad[pad].type = DS3;
epCount = interface->bNumEndpoints - 1;
} else if (device->idProduct == GUITAR_HERO_PS3_PID) {
ds34pad[pad].type = GUITAR;
ds34pad[pad].type = GUITAR_GH;
epCount = interface->bNumEndpoints - 1;
} else if (device->idProduct == ROCK_BAND_PS3_PID) {
ds34pad[pad].type = GUITAR_RB;
epCount = interface->bNumEndpoints - 1;
} else {
ds34pad[pad].type = DS4;
Expand Down Expand Up @@ -268,12 +271,12 @@ static void DS3USB_init(int pad)
static void readReport(u8 *data, int pad_idx)
{
ds34usb_device *pad = &ds34pad[pad_idx];
if (pad->type == GUITAR) {
if (pad->type == GUITAR_GH || pad->type == GUITAR_RB) {
struct ds3guitarreport *report;

report = (struct ds3guitarreport *)data;

translate_pad_guitar(report, &pad->ds2);
translate_pad_guitar(report, &pad->ds2, pad->type == GUITAR_GH);
padMacroPerform(&pad->ds2, report->PSButton);
}
if (data[0]) {
Expand Down Expand Up @@ -516,7 +519,7 @@ int ds34usb_get_model(int port)
int ret;

WaitSema(ds34pad[port].sema);
if (ds34pad[port].type == GUITAR) {
if (ds34pad[port].type == GUITAR_GH || ds34pad[port].type == GUITAR_RB) {
ret = MODEL_GUITAR;
} else {
ret = MODEL_PS2;
Expand Down
7 changes: 4 additions & 3 deletions modules/pademu/ds34usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

#include <ds34common.h>

#define DS3 0
#define DS4 1
#define GUITAR 2
#define DS3 0
#define DS4 1
#define GUITAR_GH 2
#define GUITAR_RB 2

#define MODEL_GUITAR 1
#define MODEL_PS2 3
Expand Down

0 comments on commit 20628ba

Please sign in to comment.