[SDL2] Log controller device events.
This commit is contained in:
parent
87389e2486
commit
64c5c63eaf
|
@ -419,6 +419,25 @@ void SDLInputDriver::OnControllerDeviceAdded(const SDL_Event& event) {
|
||||||
assert_always();
|
assert_always();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
XELOGI(
|
||||||
|
"SDL OnControllerDeviceAdded: \"{}\", "
|
||||||
|
"JoystickType({}), "
|
||||||
|
"GameControllerType({}), "
|
||||||
|
"VendorID(0x{:04X}), "
|
||||||
|
"ProductID(0x{:04X})",
|
||||||
|
SDL_GameControllerName(controller),
|
||||||
|
SDL_JoystickGetType(SDL_GameControllerGetJoystick(controller)),
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 12)
|
||||||
|
SDL_GameControllerGetType(controller),
|
||||||
|
#else
|
||||||
|
"?",
|
||||||
|
#endif
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 6)
|
||||||
|
SDL_GameControllerGetVendor(controller),
|
||||||
|
SDL_GameControllerGetProduct(controller));
|
||||||
|
#else
|
||||||
|
"?", "?");
|
||||||
|
#endif
|
||||||
int user_id = -1;
|
int user_id = -1;
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
||||||
// Check if the controller has a player index LED.
|
// Check if the controller has a player index LED.
|
||||||
|
@ -434,6 +453,9 @@ void SDLInputDriver::OnControllerDeviceAdded(const SDL_Event& event) {
|
||||||
for (size_t i = 0; i < controllers_.size(); i++) {
|
for (size_t i = 0; i < controllers_.size(); i++) {
|
||||||
if (!controllers_.at(i).sdl) {
|
if (!controllers_.at(i).sdl) {
|
||||||
user_id = static_cast<int>(i);
|
user_id = static_cast<int>(i);
|
||||||
|
#if SDL_VERSION_ATLEAST(2, 0, 12)
|
||||||
|
SDL_GameControllerSetPlayerIndex(controller, user_id);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,9 +464,11 @@ void SDLInputDriver::OnControllerDeviceAdded(const SDL_Event& event) {
|
||||||
controllers_.at(user_id) = {controller, {}};
|
controllers_.at(user_id) = {controller, {}};
|
||||||
// XInput seems to start with packet_number = 1 .
|
// XInput seems to start with packet_number = 1 .
|
||||||
controllers_.at(user_id).state_changed = true;
|
controllers_.at(user_id).state_changed = true;
|
||||||
|
XELOGI("SDL OnControllerDeviceAdded: Added at index {}.", user_id);
|
||||||
} else {
|
} else {
|
||||||
// No more controllers needed, close it.
|
// No more controllers needed, close it.
|
||||||
SDL_GameControllerClose(controller);
|
SDL_GameControllerClose(controller);
|
||||||
|
XELOGW("SDL OnControllerDeviceAdded: Ignored. No free slots.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,10 +477,15 @@ void SDLInputDriver::OnControllerDeviceRemoved(const SDL_Event& event) {
|
||||||
|
|
||||||
// Find the disconnected gamecontroller and close it.
|
// Find the disconnected gamecontroller and close it.
|
||||||
auto idx = GetControllerIndexFromInstanceID(event.cdevice.which);
|
auto idx = GetControllerIndexFromInstanceID(event.cdevice.which);
|
||||||
assert(idx);
|
if (idx) {
|
||||||
SDL_GameControllerClose(controllers_.at(*idx).sdl);
|
SDL_GameControllerClose(controllers_.at(*idx).sdl);
|
||||||
controllers_.at(*idx) = {};
|
controllers_.at(*idx) = {};
|
||||||
keystroke_states_.at(*idx) = {};
|
keystroke_states_.at(*idx) = {};
|
||||||
|
XELOGI("SDL OnControllerDeviceRemoved: Removed at player index {}.", *idx);
|
||||||
|
} else {
|
||||||
|
// Can happen in case all slots where full previously.
|
||||||
|
XELOGW("SDL OnControllerDeviceRemoved: Ignored. Unused device.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLInputDriver::OnControllerDeviceAxisMotion(const SDL_Event& event) {
|
void SDLInputDriver::OnControllerDeviceAxisMotion(const SDL_Event& event) {
|
||||||
|
|
Loading…
Reference in New Issue