Files
rpcs3/rpcs3/Input/wiimote_handler.h
T
Frog Business 2ba2f75bce Wiimote to GunCon3 (#18154)
So I could play Deadstorm Pirates 2 players with DolphinBar + 2 Wiimotes
99% of this is AI assisted development.
I reviewed the code and the functionality.
- There is this logic where you might find it weird.
It maps first available player with GunCon3 to slot 0.
So if you have P4:G and P6:G, you'll have P4:0, P6:1
This is intentional because I couldn't figure out why P2 is reserved and
I needed to map to P1 and P2.
- Has a GUI so you can see your Wiimotes and remap them.
- Enabling PS Move cursor overlay will also show GunCon3 IRs on the
screen.

### NOTE

On Linux you'll need udev rules (same as Dolphin) for this to work. 
Put [THIS
FILE](https://github.com/dolphin-emu/dolphin/blob/master/Data/51-usb-device.rules)
in `/etc/udev/rules.d/`
2026-10-11 10:01:57 +00:00

76 lines
1.5 KiB
C++

#pragma once
#include "util/types.hpp"
#include "Utilities/Thread.h"
#include "wiimote_types.h"
#include "Utilities/mutex.h"
#include <hidapi.h>
#include <vector>
#include <string>
#include <memory>
#include <thread>
#include <shared_mutex>
#include <chrono>
#include <array>
struct wiimote_state
{
u16 buttons = 0;
s16 acc_x = 0;
s16 acc_y = 0;
s16 acc_z = 0;
std::array<wiimote_ir_point, MAX_WIIMOTE_IR_POINTS> ir {};
bool connected = false;
};
class wiimote_device
{
public:
wiimote_device();
~wiimote_device();
bool open(hid_device_info* info);
void close();
bool update();
const wiimote_state& get_state() const { return m_state; }
const std::string& get_path() const { return m_path; }
const std::wstring& get_serial() const { return m_serial; }
private:
hid_device* m_handle = nullptr;
std::string m_path;
std::wstring m_serial;
wiimote_state m_state {};
std::chrono::steady_clock::time_point m_last_ir_check;
bool initialize_ir();
bool verify_ir_health();
bool write_reg(u32 addr, const std::vector<u8>& data);
};
class wiimote_handler
{
public:
wiimote_handler();
~wiimote_handler();
static wiimote_handler* get_instance();
void start();
void stop();
bool is_running() const { return m_running; }
std::vector<wiimote_state> get_states();
usz get_device_count();
private:
std::unique_ptr<named_thread<std::function<void()>>> m_thread;
atomic_t<bool> m_running{false};
std::vector<std::unique_ptr<wiimote_device>> m_devices;
shared_mutex m_mutex;
void thread_proc();
};