diff options
| author | Leo Lam <leolino.lam@gmail.com> | 2017-11-19 16:53:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-19 16:53:23 +0100 |
| commit | 38f44b2839d1cb3792f1bf517efe4a092933c43e (patch) | |
| tree | bc2dad207404addb20dae8ac25d602cc5ebe9366 /Source/Core/InputCommon | |
| parent | 80bcc0d58d7d3b39d0e1b7973cbce34d4cf61f4e (diff) | |
| parent | c62d83a34b34fe591dca1d3c03354ff915c589f4 (diff) | |
Merge pull request #4853 from ligfx/always_connected
GCPadEmu: only connected if default device connected
Diffstat (limited to 'Source/Core/InputCommon')
5 files changed, 18 insertions, 9 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp index cf70fa8468..98b9e5828b 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp @@ -34,6 +34,8 @@ std::unique_lock<std::recursive_mutex> EmulatedController::GetStateLock() void EmulatedController::UpdateReferences(const ControllerInterface& devi) { const auto lock = GetStateLock(); + m_default_device_is_connected = devi.HasConnectedDevice(m_default_device); + for (auto& ctrlGroup : groups) { for (auto& control : ctrlGroup->controls) @@ -48,6 +50,11 @@ void EmulatedController::UpdateReferences(const ControllerInterface& devi) } } +bool EmulatedController::IsDefaultDeviceConnected() const +{ + return m_default_device_is_connected; +} + const ciface::Core::DeviceQualifier& EmulatedController::GetDefaultDevice() const { return m_default_device; diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h index c9faf4457c..8b7925f7df 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.h @@ -33,6 +33,7 @@ public: virtual void LoadConfig(IniFile::Section* sec, const std::string& base = ""); virtual void SaveConfig(IniFile::Section* sec, const std::string& base = ""); + bool IsDefaultDeviceConnected() const; const ciface::Core::DeviceQualifier& GetDefaultDevice() const; void SetDefaultDevice(const std::string& device); void SetDefaultDevice(ciface::Core::DeviceQualifier devq); @@ -49,5 +50,6 @@ public: private: ciface::Core::DeviceQualifier m_default_device; + bool m_default_device_is_connected{false}; }; } // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index f83dae268e..48d40cb9af 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -199,5 +199,11 @@ Device::Output* DeviceContainer::FindOutput(const std::string& name, const Devic { return def_dev->FindOutput(name); } + +bool DeviceContainer::HasConnectedDevice(const DeviceQualifier& qualifier) const +{ + const auto device = FindDevice(qualifier); + return device != nullptr && device->IsValid(); +} } } diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index 7b601cc775..5482b93ac0 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -158,6 +158,8 @@ public: std::string GetDefaultDeviceString() const; std::shared_ptr<Device> FindDevice(const DeviceQualifier& devq) const; + bool HasConnectedDevice(const DeviceQualifier& qualifier) const; + protected: mutable std::mutex m_devices_mutex; std::vector<std::shared_ptr<Device>> m_devices; diff --git a/Source/Core/InputCommon/GCPadStatus.h b/Source/Core/InputCommon/GCPadStatus.h index d9aa6c5a91..7da1bbd4fc 100644 --- a/Source/Core/InputCommon/GCPadStatus.h +++ b/Source/Core/InputCommon/GCPadStatus.h @@ -6,14 +6,6 @@ #include "Common/CommonTypes.h" -enum PadError -{ - PAD_ERR_NONE = 0, - PAD_ERR_NO_CONTROLLER = -1, - PAD_ERR_NOT_READY = -2, - PAD_ERR_TRANSFER = -3, -}; - enum { PAD_USE_ORIGIN = 0x0080, @@ -48,7 +40,7 @@ struct GCPadStatus u8 triggerRight; // 0 <= triggerRight <= 255 u8 analogA; // 0 <= analogA <= 255 u8 analogB; // 0 <= analogB <= 255 - s8 err; // one of PAD_ERR_* number + bool isConnected{true}; static const u8 MAIN_STICK_CENTER_X = 0x80; static const u8 MAIN_STICK_CENTER_Y = 0x80; |
