From ee60171b26757ab59324deb9491b9da27a9eb89b Mon Sep 17 00:00:00 2001 From: capitalistspz Date: Thu, 26 Sep 2024 01:42:24 +0100 Subject: [PATCH] Allow `WiimoteControllerProvider` to receive `L2CapWiimote`s --- src/input/api/Wiimote/WiimoteControllerProvider.cpp | 11 ++++++++++- src/input/api/Wiimote/hidapi/HidapiWiimote.h | 2 -- src/input/api/Wiimote/l2cap/L2CapWiimote.cpp | 11 ++++++++--- src/input/api/Wiimote/l2cap/L2CapWiimote.h | 1 + 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/input/api/Wiimote/WiimoteControllerProvider.cpp b/src/input/api/Wiimote/WiimoteControllerProvider.cpp index c80f3fbe..33b02262 100644 --- a/src/input/api/Wiimote/WiimoteControllerProvider.cpp +++ b/src/input/api/Wiimote/WiimoteControllerProvider.cpp @@ -4,6 +4,10 @@ #include "input/api/Wiimote/hidapi/HidapiWiimote.h" +#if BOOST_OS_LINUX +#include "input/api/Wiimote/l2cap/L2CapWiimote.h" +#endif + #include #include @@ -45,7 +49,12 @@ std::vector> WiimoteControllerProvider::get_cont return writeable && not_already_connected; }; - for (auto& device : WiimoteDevice_t::get_devices()) + auto devices = HidapiWiimote::get_devices(); +#if BOOST_OS_LINUX + const auto& l2capDevices = L2CapWiimote::get_devices(); + std::ranges::copy(l2capDevices, std::back_inserter(devices)); +#endif + for (auto& device : devices) { if (!valid_new_device(device)) continue; diff --git a/src/input/api/Wiimote/hidapi/HidapiWiimote.h b/src/input/api/Wiimote/hidapi/HidapiWiimote.h index 858cb1f3..c914d007 100644 --- a/src/input/api/Wiimote/hidapi/HidapiWiimote.h +++ b/src/input/api/Wiimote/hidapi/HidapiWiimote.h @@ -19,5 +19,3 @@ private: const std::string m_path; }; - -using WiimoteDevice_t = HidapiWiimote; \ No newline at end of file diff --git a/src/input/api/Wiimote/l2cap/L2CapWiimote.cpp b/src/input/api/Wiimote/l2cap/L2CapWiimote.cpp index 35271146..cb4c8fcd 100644 --- a/src/input/api/Wiimote/l2cap/L2CapWiimote.cpp +++ b/src/input/api/Wiimote/l2cap/L2CapWiimote.cpp @@ -2,7 +2,7 @@ #include namespace { - // TODO: Add procedure to get addresses. Should add to PairingDialog + // TODO: Get addresses upon user request via PairingDialog std::vector s_address; std::mutex s_addressMutex; @@ -39,6 +39,12 @@ L2CapWiimote::~L2CapWiimote() ::close(m_sendFd); } +void L2CapWiimote::AddCandidateAddresses(const std::vector& addrs) +{ + std::scoped_lock lock(s_addressMutex); + std::ranges::copy(addrs, std::back_inserter(s_address)); +} + std::vector L2CapWiimote::get_devices() { s_addressMutex.lock(); @@ -123,5 +129,4 @@ bool L2CapWiimote::operator==(WiimoteDevice& rhs) const if (!mote) return false; return m_recvFd == mote->m_recvFd || m_recvFd == mote->m_sendFd; -} - +} \ No newline at end of file diff --git a/src/input/api/Wiimote/l2cap/L2CapWiimote.h b/src/input/api/Wiimote/l2cap/L2CapWiimote.h index 8b980a24..e0f179fb 100644 --- a/src/input/api/Wiimote/l2cap/L2CapWiimote.h +++ b/src/input/api/Wiimote/l2cap/L2CapWiimote.h @@ -12,6 +12,7 @@ class L2CapWiimote : public WiimoteDevice std::optional> read_data() override; bool operator==(WiimoteDevice& o) const override; + static void AddCandidateAddresses(const std::vector& addrs); static std::vector get_devices(); private: int m_recvFd;