Skip to content

Commit

Permalink
Changes to finding wiimotes (again)
Browse files Browse the repository at this point in the history
- Clear `m_wiimotes` before finding new wiimotes
- Use only paths for comparison
  • Loading branch information
capitalistspz committed Sep 5, 2023
1 parent 2abf1c2 commit 1545198
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/input/api/Wiimote/WiimoteControllerProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ WiimoteControllerProvider::~WiimoteControllerProvider()
std::vector<std::shared_ptr<ControllerBase>> WiimoteControllerProvider::get_controllers()
{
std::scoped_lock lock(m_device_mutex);
m_wiimotes.clear();
for (const auto& device : WiimoteDevice_t::get_devices())
{
// test connection of all devices as they might have been changed
Expand Down
13 changes: 4 additions & 9 deletions src/input/api/Wiimote/hidapi/HidapiWiimote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ static constexpr uint16 WIIMOTE_PRODUCT_ID = 0x0306;
static constexpr uint16 WIIMOTE_MP_PRODUCT_ID = 0x0330;
static constexpr uint16 WIIMOTE_MAX_INPUT_REPORT_LENGTH = 22;

HidapiWiimote::HidapiWiimote(hid_device* dev, uint64_t identifier, std::string_view path)
: m_handle(dev), m_identifier(identifier), m_path(path) {
HidapiWiimote::HidapiWiimote(hid_device* dev, std::string_view path)
: m_handle(dev), m_path(path) {

}

Expand Down Expand Up @@ -36,20 +36,15 @@ std::vector<WiimoteDevicePtr> HidapiWiimote::get_devices() {
}
else {
hid_set_nonblocking(dev, true);
// Enough to have a unique id for each device within a session
uint64_t id = (static_cast<uint64>(it->interface_number) << 32) |
(static_cast<uint64>(it->usage_page) << 16) |
(it->usage);
wiimote_devices.push_back(std::make_shared<HidapiWiimote>(dev, id, it->path));
wiimote_devices.push_back(std::make_shared<HidapiWiimote>(dev, it->path));
}
}
hid_free_enumeration(device_enumeration);
return wiimote_devices;
}

bool HidapiWiimote::operator==(WiimoteDevice& o) const {
auto const& other_mote = static_cast<HidapiWiimote const&>(o);
return m_identifier == other_mote.m_identifier && other_mote.m_path == m_path;
return static_cast<HidapiWiimote const&>(o).m_path == m_path;
}

HidapiWiimote::~HidapiWiimote() {
Expand Down
3 changes: 1 addition & 2 deletions src/input/api/Wiimote/hidapi/HidapiWiimote.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class HidapiWiimote : public WiimoteDevice {
public:
HidapiWiimote(hid_device* dev, uint64_t identifier, std::string_view path);
HidapiWiimote(hid_device* dev, std::string_view path);
~HidapiWiimote() override;

bool write_data(const std::vector<uint8> &data) override;
Expand All @@ -16,7 +16,6 @@ class HidapiWiimote : public WiimoteDevice {

private:
hid_device* m_handle;
const uint64_t m_identifier;
const std::string m_path;

};
Expand Down

0 comments on commit 1545198

Please sign in to comment.