mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-28 05:46:56 +01:00
controller: give the DualShock 4 the DualSense pad path and release p… (#453)
controller: give the DualShock 4 the DualSense pad path and release pads on exit
This commit is contained in:
@@ -59,6 +59,7 @@ int DbgExitHandler(const char* file, int line, fmt::text_style style, std::strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DbgExit(int status) {
|
void DbgExit(int status) {
|
||||||
|
Subsystems::EmergencyShutdownActive();
|
||||||
std::fflush(nullptr);
|
std::fflush(nullptr);
|
||||||
std::_Exit(status);
|
std::_Exit(status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,11 +29,7 @@ void DbgExit(int status);
|
|||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|
||||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS || KYTY_PLATFORM == KYTY_PLATFORM_LINUX
|
|
||||||
#define EXIT_HALT() (Common::DbgExit(321), 1)
|
#define EXIT_HALT() (Common::DbgExit(321), 1)
|
||||||
#else
|
|
||||||
#define EXIT_HALT() (std::_Exit(321), 1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef KYTY_FINAL
|
#ifndef KYTY_FINAL
|
||||||
#define EXIT_IF(x) \
|
#define EXIT_IF(x) \
|
||||||
|
|||||||
@@ -814,6 +814,7 @@ static void WindowCreate(WindowContext& context) {
|
|||||||
int width = static_cast<int>(context.graphic_ctx.screen_width);
|
int width = static_cast<int>(context.graphic_ctx.screen_width);
|
||||||
int height = static_cast<int>(context.graphic_ctx.screen_height);
|
int height = static_cast<int>(context.graphic_ctx.screen_height);
|
||||||
|
|
||||||
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
||||||
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
||||||
SDL_SetHint(SDL_HINT_WINDOWS_DPI_SCALING, "0");
|
SDL_SetHint(SDL_HINT_WINDOWS_DPI_SCALING, "0");
|
||||||
@@ -899,6 +900,7 @@ void WindowRun() {
|
|||||||
|
|
||||||
void WindowShutdown() {
|
void WindowShutdown() {
|
||||||
if (g_window != nullptr) {
|
if (g_window != nullptr) {
|
||||||
|
Controller::EmergencyShutdown();
|
||||||
g_window.reset();
|
g_window.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-1
@@ -23,8 +23,8 @@ LIB_NAME("Pad", "Pad");
|
|||||||
constexpr int PAD_ERROR_INVALID_ARG = -2137915391; /* 0x80920001 */
|
constexpr int PAD_ERROR_INVALID_ARG = -2137915391; /* 0x80920001 */
|
||||||
constexpr int PAD_ERROR_INVALID_HANDLE = -2137915389; /* 0x80920003 */
|
constexpr int PAD_ERROR_INVALID_HANDLE = -2137915389; /* 0x80920003 */
|
||||||
|
|
||||||
// SDL limits rumble commands to 0xffff ms; zero strengths stop immediately.
|
|
||||||
constexpr uint32_t RUMBLE_DURATION_MS = 0xffff;
|
constexpr uint32_t RUMBLE_DURATION_MS = 0xffff;
|
||||||
|
constexpr uint32_t RELEASE_FLUSH_MS = 50;
|
||||||
|
|
||||||
struct PadControllerInformation {
|
struct PadControllerInformation {
|
||||||
float touch_pixel_density;
|
float touch_pixel_density;
|
||||||
@@ -102,6 +102,7 @@ public:
|
|||||||
void RightStick(int id, int x, int y);
|
void RightStick(int id, int x, int y);
|
||||||
void TouchPad(int id, int finger, bool down, float x, float y);
|
void TouchPad(int id, int finger, bool down, float x, float y);
|
||||||
void ResetInputState();
|
void ResetInputState();
|
||||||
|
void ReleaseHostPads();
|
||||||
void GetConnectionInfo(bool* flag, int* count);
|
void GetConnectionInfo(bool* flag, int* count);
|
||||||
void SetVibration(uint8_t large_motor, uint8_t small_motor);
|
void SetVibration(uint8_t large_motor, uint8_t small_motor);
|
||||||
void SetLightBar(uint8_t r, uint8_t g, uint8_t b);
|
void SetLightBar(uint8_t r, uint8_t g, uint8_t b);
|
||||||
@@ -252,10 +253,17 @@ void Initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown() {
|
||||||
|
EmergencyShutdown();
|
||||||
delete g_controller;
|
delete g_controller;
|
||||||
g_controller = nullptr;
|
g_controller = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EmergencyShutdown() {
|
||||||
|
if (g_controller != nullptr) {
|
||||||
|
g_controller->ReleaseHostPads();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::Connect(int id) {
|
void GameController::Connect(int id) {
|
||||||
Common::LockGuard lock(m_mutex);
|
Common::LockGuard lock(m_mutex);
|
||||||
|
|
||||||
@@ -404,6 +412,39 @@ void GameController::ResetInputState() {
|
|||||||
AddState();
|
AddState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::ReleaseHostPads() {
|
||||||
|
Common::LockGuard lock(m_mutex);
|
||||||
|
|
||||||
|
std::vector<SDL_GameController*> pads;
|
||||||
|
for (const auto id: m_connected_ids) {
|
||||||
|
if (id == HOST_INPUT_CONTROLLER_ID) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(id));
|
||||||
|
pad != nullptr) {
|
||||||
|
if (SDL_GameControllerGetType(pad) == SDL_CONTROLLER_TYPE_PS5) {
|
||||||
|
DualSenseEffects effect {};
|
||||||
|
effect.enable_bits = 0x0c;
|
||||||
|
effect.right_trigger[0] = 0x05;
|
||||||
|
effect.left_trigger[0] = 0x05;
|
||||||
|
(void)SDL_GameControllerSendEffect(pad, &effect, sizeof(effect));
|
||||||
|
}
|
||||||
|
(void)SDL_GameControllerRumble(pad, 0, 0, 0);
|
||||||
|
(void)SDL_GameControllerSetLED(pad, 0, 0, 0);
|
||||||
|
pads.push_back(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pads.empty()) {
|
||||||
|
SDL_Delay(RELEASE_FLUSH_MS);
|
||||||
|
for (auto* pad: pads) {
|
||||||
|
SDL_GameControllerClose(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_connected_ids.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) {
|
void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) {
|
||||||
Common::LockGuard lock(m_mutex);
|
Common::LockGuard lock(m_mutex);
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ namespace Libs::Controller {
|
|||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
void EmergencyShutdown();
|
||||||
|
|
||||||
struct Lifecycle {
|
struct Lifecycle {
|
||||||
static constexpr const char* name = "Controller";
|
static constexpr const char* name = "Controller";
|
||||||
static constexpr auto initialize = Libs::Controller::Initialize;
|
static constexpr auto initialize = Libs::Controller::Initialize;
|
||||||
static constexpr auto shutdown = Libs::Controller::Shutdown;
|
static constexpr auto shutdown = Libs::Controller::Shutdown;
|
||||||
|
static constexpr auto emergency_shutdown = Libs::Controller::EmergencyShutdown;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr int HOST_INPUT_CONTROLLER_ID = -1000;
|
constexpr int HOST_INPUT_CONTROLLER_ID = -1000;
|
||||||
|
|||||||
Reference in New Issue
Block a user