add support for grip

This commit is contained in:
Narr the Reg 2023-02-01 10:34:16 -06:00
parent 0d25195f22
commit ab4a961768
5 changed files with 52 additions and 7 deletions

View File

@ -46,6 +46,12 @@ void Joycons::Reset() {
}
device->Stop();
}
for (const auto& device : grip_joycons) {
if (!device) {
continue;
}
device->Stop();
}
SDL_hid_exit();
}
@ -61,6 +67,11 @@ void Joycons::Setup() {
PreSetController(GetIdentifier(port, Joycon::ControllerType::Right));
device = std::make_shared<Joycon::JoyconDriver>(port++);
}
port = 0;
for (auto& device : grip_joycons) {
PreSetController(GetIdentifier(port, Joycon::ControllerType::Grip));
device = std::make_shared<Joycon::JoyconDriver>(port++);
}
scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); });
}
@ -129,6 +140,13 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
}
}
break;
case Joycon::ControllerType::Grip:
for (const auto& device : grip_joycons) {
if (is_handle_identical(device)) {
return false;
}
}
break;
default:
return false;
}
@ -199,6 +217,14 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetNextFreeHandle(
return *unconnected_device;
}
}
if (type == Joycon::ControllerType::Grip) {
const auto unconnected_device = std::ranges::find_if(
grip_joycons, [](auto& device) { return !device->IsConnected(); });
if (unconnected_device != grip_joycons.end()) {
return *unconnected_device;
}
}
return nullptr;
}
@ -408,6 +434,14 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetHandle(PadIdentifier identifie
return *matching_device;
}
}
if (type == Joycon::ControllerType::Grip) {
const auto matching_device = std::ranges::find_if(
grip_joycons, [is_handle_active](auto& device) { return is_handle_active(device); });
if (matching_device != grip_joycons.end()) {
return *matching_device;
}
}
return nullptr;
}
@ -455,6 +489,9 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
for (const auto& controller : right_joycons) {
add_entry(controller);
}
for (const auto& controller : grip_joycons) {
add_entry(controller);
}
// List dual joycon pairs
for (std::size_t i = 0; i < MaxSupportedControllers; i++) {
@ -666,8 +703,8 @@ std::string Joycons::JoyconName(Joycon::ControllerType type) const {
return "Left Joycon";
case Joycon::ControllerType::Right:
return "Right Joycon";
case Joycon::ControllerType::Pro:
return "Pro Controller";
case Joycon::ControllerType::Grip:
return "Joycon grip <- custom driver";
case Joycon::ControllerType::Dual:
return "Dual Joycon";
default:

View File

@ -106,6 +106,7 @@ private:
// Joycon types are split by type to ease supporting dualjoycon configurations
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{};
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> right_joycons{};
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> grip_joycons{};
};
} // namespace InputCommon

View File

@ -336,7 +336,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
if (Settings::values.enable_joycon_driver) {
if (guid.uuid[5] == 0x05 && guid.uuid[4] == 0x7e &&
(guid.uuid[8] == 0x06 || guid.uuid[8] == 0x07)) {
(guid.uuid[8] == 0x06 || guid.uuid[8] == 0x07 || guid.uuid[8] == 0x0e)) {
LOG_WARNING(Input, "Preferring joycon driver for device index {}", joystick_index);
SDL_JoystickClose(sdl_joystick);
return;

View File

@ -164,6 +164,15 @@ void JoyconDriver::InputThread(std::stop_token stop_token) {
void JoyconDriver::OnNewData(std::span<u8> buffer) {
const auto report_mode = static_cast<ReportMode>(buffer[0]);
std::string out = "";
for (const u8& bb : buffer) {
out += fmt::format("{} ", bb);
}
LOG_ERROR(Input, "{}", out);
// Packages can be a litte bit inconsistent. Average the delta time to provide a smoother motion
// experience
switch (report_mode) {

View File

@ -29,9 +29,8 @@ void JoyconPoller::ReadActiveMode(std::span<u8> buffer, const MotionStatus& moti
UpdateActiveRightPadInput(data, motion_status);
break;
case Joycon::ControllerType::Pro:
UpdateActiveProPadInput(data, motion_status);
break;
default:
UpdateActiveProPadInput(data, motion_status);
break;
}
@ -54,9 +53,8 @@ void JoyconPoller::ReadPassiveMode(std::span<u8> buffer) {
UpdatePasiveRightPadInput(data);
break;
case Joycon::ControllerType::Pro:
UpdatePasiveProPadInput(data);
break;
default:
UpdatePasiveProPadInput(data);
break;
}
}