From d85142c407f08e7cb6c739d4ab90b42afccf9b6b Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Fri, 10 Jul 2020 21:37:31 +0200 Subject: [PATCH] btdrv-mitm: use the same player led colours as ps4 console for dualshock4 controller --- btdrv-mitm/source/controllers/dualshock4.cpp | 20 ++++++++++++-------- btdrv-mitm/source/controllers/dualshock4.hpp | 6 ++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/btdrv-mitm/source/controllers/dualshock4.cpp b/btdrv-mitm/source/controllers/dualshock4.cpp index acbeef2..6954b5e 100644 --- a/btdrv-mitm/source/controllers/dualshock4.cpp +++ b/btdrv-mitm/source/controllers/dualshock4.cpp @@ -12,6 +12,13 @@ namespace controller { const constexpr float scale_factor = float(UINT12_MAX) / UINT8_MAX; + const Dualshock4LedColour playerLedColours[] = { + {0x00, 0x00, 0x7f}, // blue + {0x7f, 0x00, 0x00}, // red + {0x00, 0x7f, 0x00}, // green + {0x7f, 0x00, 0x7f} // pink + }; + } Dualshock4Controller::Dualshock4Controller(const BluetoothAddress *address) @@ -21,15 +28,12 @@ namespace controller { Result Dualshock4Controller::initialize(void) { R_TRY(BluetoothController::initialize()); - - //uint8_t r = 0xff; - //uint8_t g = 0x00; - //uint8_t b = 0x00; - //Dualshock4OutputReport0x11 report = {0xa2, 0x11, 0xc0, 0x20, 0xf3, 0x04, 0x00, 0x00, 0x00, r, g, b}; - uint8_t rgb[3]; - randomGet(rgb, sizeof(rgb)); - Dualshock4OutputReport0x11 report = {0xa2, 0x11, 0xc0, 0x20, 0xf3, 0x04, 0x00, 0x00, 0x00, rgb[0], rgb[1], rgb[2]}; + u8 ind; + randomGet(&ind, 1); + auto colour = playerLedColours[ind >> 6]; + + Dualshock4OutputReport0x11 report = {0xa2, 0x11, 0xc0, 0x20, 0xf3, 0x04, 0x00, 0x00, 0x00, colour.r, colour.g, colour.b}; report.crc = crc32Calculate(report.data, sizeof(report.data)); BluetoothHidData hidData = {}; diff --git a/btdrv-mitm/source/controllers/dualshock4.hpp b/btdrv-mitm/source/controllers/dualshock4.hpp index aa17d5a..8cb6931 100644 --- a/btdrv-mitm/source/controllers/dualshock4.hpp +++ b/btdrv-mitm/source/controllers/dualshock4.hpp @@ -4,6 +4,12 @@ namespace controller { + struct Dualshock4LedColour { + uint8_t r; + uint8_t g; + uint8_t b; + }; + enum Dualshock4ControllerVariant { Dualshock4ControllerVariant_V1, Dualshock4ControllerVariant_V2,