Skip to content

Commit

Permalink
use wii u led patterns for ds, support up to 7 controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed Nov 23, 2021
1 parent 1a5f998 commit c2e574a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bloopair allows connecting controllers from other consoles like native Wii U Pro
It temporarily applies patches to the IOS-PAD module responsible for Bluetooth controller connections.

## Features
- Connect up to 4 controllers wirelessly via Bluetooth
- Connect up to 7 controllers wirelessly via Bluetooth
- Rumble support
- Battery levels

Expand Down
15 changes: 15 additions & 0 deletions source/ios_pad/source/controllers.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,18 @@ void deinitContinuousReports(Controller_t* controller)
IOS_Free(0xcaff, controller->reportData);
controller->reportData = NULL;
}

uint8_t ledMaskToPlayerNum(uint8_t mask)
{
switch (mask & 0xf) {
case 0b0001: return 1;
case 0b0010: return 2;
case 0b0100: return 3;
case 0b1000: return 4;
case 0b0011: return 5;
case 0b0101: return 6;
case 0b1001: return 7;
}

return 0;
}
2 changes: 2 additions & 0 deletions source/ios_pad/source/controllers.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ void sendControllerInput(Controller_t* controller, uint32_t buttons, int16_t lef
void initContinuousReports(Controller_t* controller);

void deinitContinuousReports(Controller_t* controller);

uint8_t ledMaskToPlayerNum(uint8_t mask);
48 changes: 26 additions & 22 deletions source/ios_pad/source/controllers/dualsense_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,35 @@
#include "utils.h"

typedef struct {
uint8_t led_flags;
uint8_t player_leds;
uint8_t led_color[3];
uint8_t rumble;
} DualsenseData_t;

static const uint8_t led_flags[] = {
// the dualsense has 5 leds, with one in the center
// we'll use the same pattern the Wii U uses on the 4 outer ones
static const uint8_t player_leds[] = {
0,
0x01, // player 1
0x03, // player 2
0,
0x0b, // player 3
0,
0,
0,
0x1b, // player 4
0b00001,
0b00010,
0b01000,
0b10000,
0b00011,
0b01001,
0b10001,
};

static const uint8_t led_colors[][3] = {
{0},
{0x00, 0x00, 0x40}, // player 1
{0x40, 0x00, 0x00}, // player 2
{0},
{0x00, 0x40, 0x00}, // player 3
{0},
{0},
{0},
{0x20, 0x00, 0x20}, // player 4
// same colors as used on ps4/ps5
{0x00, 0x00, 0x40}, // blue
{0x40, 0x00, 0x00}, // red
{0x00, 0x40, 0x00}, // green
{0x20, 0x00, 0x20}, // pink
// for 5-7 we'll use the same colors missioncontrol is using
{0x00, 0x20, 0x20}, // cyan
{0x30, 0x10, 0x00}, // orange
{0x20, 0x20, 0x00}, // yellow
};

static const uint32_t dpad_map[9] = {
Expand Down Expand Up @@ -77,7 +79,7 @@ static void sendRumbleLedState(Controller_t* controller)
data[6] = ds_data->rumble;
data[41] = 0x02;
data[44] = 0x02;
data[46] = ds_data->led_flags;
data[46] = ds_data->player_leds;
data[47] = ds_data->led_color[0];
data[48] = ds_data->led_color[1];
data[49] = ds_data->led_color[2];
Expand All @@ -101,9 +103,11 @@ void controllerSetLed_dualsense(Controller_t* controller, uint8_t led)
{
DualsenseData_t* ds_data = (DualsenseData_t*) controller->additionalData;

ds_data->led_flags = led_flags[led];

memcpy(ds_data->led_color, &led_colors[led], 3);
uint8_t player_num = ledMaskToPlayerNum(led);

ds_data->player_leds = player_leds[player_num];

memcpy(ds_data->led_color, &led_colors[player_num], 3);

sendRumbleLedState(controller);
}
Expand Down
20 changes: 11 additions & 9 deletions source/ios_pad/source/controllers/dualshock4_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ typedef struct {

static const uint8_t led_colors[][3] = {
{0},
{0x00, 0x00, 0x40}, // player 1
{0x40, 0x00, 0x00}, // player 2
{0},
{0x00, 0x40, 0x00}, // player 3
{0},
{0},
{0},
{0x20, 0x00, 0x20}, // player 4
// same colors as used on ps4/ps5
{0x00, 0x00, 0x40}, // blue
{0x40, 0x00, 0x00}, // red
{0x00, 0x40, 0x00}, // green
{0x20, 0x00, 0x20}, // pink
// for 5-7 we'll use the same colors missioncontrol is using
{0x00, 0x20, 0x20}, // cyan
{0x30, 0x10, 0x00}, // orange
{0x20, 0x20, 0x00}, // yellow
};

static const uint32_t dpad_map[9] = {
Expand Down Expand Up @@ -86,7 +87,8 @@ void controllerSetLed_dualshock4(Controller_t* controller, uint8_t led)
{
Dualshock4Data_t* ds_data = (Dualshock4Data_t*) controller->additionalData;

memcpy(ds_data->led_color, &led_colors[led], 3);
uint8_t player_num = ledMaskToPlayerNum(led);
memcpy(ds_data->led_color, &led_colors[player_num], 3);

sendRumbleLedState(controller);
}
Expand Down

0 comments on commit c2e574a

Please sign in to comment.