Skip to content

Commit

Permalink
message size correction, no magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
capitalistspz committed Aug 7, 2023
1 parent ec61c3e commit 74b5a10
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/input/api/Wiimote/hidapi/HidapiWiimote.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "HidapiWiimote.h"

static constexpr uint16 WIIMOTE_VENDOR_ID = 0x057e;
static constexpr uint16 WIIMOTE_PRODUCT_ID = 0x0306;
static constexpr uint16 WIIMOTE_MAX_MESSAGE_LENGTH = 21;

HidapiWiimote::HidapiWiimote(fs::path const& device_path, uint64_t identifier)
: m_handle(hid_open_path(_pathToUtf8(device_path).c_str())), m_identifier(identifier) {

Expand All @@ -10,8 +14,8 @@ bool HidapiWiimote::write_data(const std::vector<uint8> &data) {
}

std::optional<std::vector<uint8>> HidapiWiimote::read_data() {
std::array<uint8_t, 21> read_data{};
const auto result = hid_read(m_handle, read_data.data(), 20);
std::array<uint8, WIIMOTE_MAX_MESSAGE_LENGTH> read_data{};
const auto result = hid_read(m_handle, read_data.data(), WIIMOTE_MAX_MESSAGE_LENGTH);
if (result < 0)
return {};
return {{read_data.cbegin(), read_data.cend()}};
Expand All @@ -20,7 +24,7 @@ std::optional<std::vector<uint8>> HidapiWiimote::read_data() {
std::vector<WiimoteDevicePtr> HidapiWiimote::get_devices() {
std::vector<WiimoteDevicePtr> wiimote_devices;
hid_init();
const auto device_enumeration = hid_enumerate(0x057e, 0x0306);
const auto device_enumeration = hid_enumerate(WIIMOTE_VENDOR_ID, WIIMOTE_PRODUCT_ID);
auto it = device_enumeration;
while (it){
// Enough to have a unique id for each device within a session
Expand Down

0 comments on commit 74b5a10

Please sign in to comment.