diff --git a/include/boo/inputdev/NintendoPowerA.hpp b/include/boo/inputdev/NintendoPowerA.hpp index 20096a1..a7373a8 100644 --- a/include/boo/inputdev/NintendoPowerA.hpp +++ b/include/boo/inputdev/NintendoPowerA.hpp @@ -34,7 +34,7 @@ struct INintendoPowerACallback { }; class NintendoPowerA final : public TDeviceBase { - NintendoPowerAState m_last; + NintendoPowerAState m_last{}; void deviceDisconnected() override; void initialCycle() override; void transferCycle() override; @@ -42,7 +42,7 @@ class NintendoPowerA final : public TDeviceBase { void receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) override; public: - NintendoPowerA(DeviceToken*); + explicit NintendoPowerA(DeviceToken*); ~NintendoPowerA() override; }; } // namespace boo diff --git a/lib/inputdev/NintendoPowerA.cpp b/lib/inputdev/NintendoPowerA.cpp index fbc46dd..788cacd 100644 --- a/lib/inputdev/NintendoPowerA.cpp +++ b/lib/inputdev/NintendoPowerA.cpp @@ -1,5 +1,6 @@ #include "boo/inputdev/NintendoPowerA.hpp" +#include #include #include "boo/inputdev/DeviceSignature.hpp" @@ -8,27 +9,31 @@ namespace boo { NintendoPowerA::NintendoPowerA(DeviceToken* token) : TDeviceBase(dev_typeid(NintendoPowerA), token) {} -NintendoPowerA::~NintendoPowerA() {} +NintendoPowerA::~NintendoPowerA() = default; void NintendoPowerA::deviceDisconnected() { - std::lock_guard lk(m_callbackLock); - if (m_callback) + std::lock_guard lk{m_callbackLock}; + if (m_callback != nullptr) { m_callback->controllerDisconnected(); + } } void NintendoPowerA::initialCycle() {} void NintendoPowerA::transferCycle() { - uint8_t payload[8]; - size_t recvSz = receiveUSBInterruptTransfer(payload, sizeof(payload)); - if (recvSz != 8) + std::array payload; + const size_t recvSz = receiveUSBInterruptTransfer(payload.data(), payload.size()); + if (recvSz != payload.size()) { return; + } - NintendoPowerAState state = *reinterpret_cast(&payload); + NintendoPowerAState state; + std::memcpy(&state, payload.data(), sizeof(state)); - std::lock_guard lk(m_callbackLock); - if (state != m_last && m_callback) + std::lock_guard lk{m_callbackLock}; + if (state != m_last && m_callback != nullptr) { m_callback->controllerUpdate(state); + } m_last = state; } @@ -37,7 +42,7 @@ void NintendoPowerA::finalCycle() {} void NintendoPowerA::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {} bool NintendoPowerAState::operator==(const NintendoPowerAState& other) const { - return memcmp(this, &other, sizeof(NintendoPowerAState)) == 0; + return std::memcmp(this, &other, sizeof(NintendoPowerAState)) == 0; } bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) const { return !operator==(other); }