WiimoteReal/IOLinux: Improvements, fixes, and code cleanups.

This commit is contained in:
Jordan Woyak
2025-10-04 14:51:27 -05:00
parent b2fef6ee1f
commit 38dc8ae3b6
3 changed files with 276 additions and 188 deletions
File diff suppressed because it is too large Load Diff
+23 -19
View File
@@ -4,8 +4,10 @@
#pragma once
#if defined(__linux__) && HAVE_BLUEZ
#include <bluetooth/bluetooth.h>
#include <atomic>
#include "Common/Network.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
namespace WiimoteReal
@@ -13,14 +15,10 @@ namespace WiimoteReal
class WiimoteLinux final : public Wiimote
{
public:
WiimoteLinux(bdaddr_t bdaddr);
explicit WiimoteLinux(Common::BluetoothAddress bdaddr);
~WiimoteLinux() override;
std::string GetId() const override
{
char bdaddr_str[18] = {};
ba2str(&m_bdaddr, bdaddr_str);
return bdaddr_str;
}
std::string GetId() const override;
protected:
bool ConnectInternal() override;
@@ -31,11 +29,10 @@ protected:
int IOWrite(u8 const* buf, size_t len) override;
private:
bdaddr_t m_bdaddr; // Bluetooth address
int m_cmd_sock; // Command socket
int m_int_sock; // Interrupt socket
int m_wakeup_pipe_w;
int m_wakeup_pipe_r;
const Common::BluetoothAddress m_bdaddr;
const int m_wakeup_fd{-1}; // Used to kick the read thread.
int m_cmd_sock{-1}; // Command socket
int m_int_sock{-1}; // Interrupt socket
};
class WiimoteScannerLinux final : public WiimoteScannerBackend
@@ -43,16 +40,23 @@ class WiimoteScannerLinux final : public WiimoteScannerBackend
public:
WiimoteScannerLinux();
~WiimoteScannerLinux() override;
bool IsReady() const override;
void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override;
void Update() override {} // not needed on Linux
void RequestStopSearching() override {} // not needed on Linux
private:
int m_device_id;
int m_device_sock;
void Update() override;
void RequestStopSearching() override;
void AddAutoConnectAddresses(std::vector<Wiimote*>&);
private:
bool Open();
void Close();
int m_device_id{-1};
int m_device_sock{-1};
// FYI: Atomic because UI calls IsReady.
std::atomic<bool> m_is_device_open{};
};
} // namespace WiimoteReal
#else
@@ -175,7 +175,10 @@ class WiimoteScannerBackend
{
public:
virtual ~WiimoteScannerBackend() = default;
// Note: Invoked from UI thread.
virtual bool IsReady() const = 0;
virtual void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) = 0;
// function called when not looking for more Wiimotes
virtual void Update() = 0;