Files

51 lines
1.4 KiB
C++
Raw Permalink Normal View History

#include "boo/inputdev/NintendoPowerA.hpp"
2019-08-19 19:08:54 -04:00
#include <array>
2019-08-19 19:08:54 -04:00
#include <cstring>
2018-10-06 16:49:22 -10:00
#include "boo/inputdev/DeviceSignature.hpp"
2019-08-19 19:08:54 -04:00
2018-12-07 19:17:51 -10:00
namespace boo {
NintendoPowerA::NintendoPowerA(DeviceToken* token)
2018-12-07 19:17:51 -10:00
: TDeviceBase<INintendoPowerACallback>(dev_typeid(NintendoPowerA), token) {}
2019-09-06 07:23:34 -04:00
NintendoPowerA::~NintendoPowerA() = default;
2018-12-07 19:17:51 -10:00
void NintendoPowerA::deviceDisconnected() {
std::lock_guard lk{m_callbackLock};
if (m_callback != nullptr) {
2018-12-07 19:17:51 -10:00
m_callback->controllerDisconnected();
}
}
void NintendoPowerA::initialCycle() {}
2018-12-07 19:17:51 -10:00
void NintendoPowerA::transferCycle() {
std::array<uint8_t, 8> payload;
const size_t recvSz = receiveUSBInterruptTransfer(payload.data(), payload.size());
if (recvSz != payload.size()) {
2018-12-07 19:17:51 -10:00
return;
}
NintendoPowerAState state;
std::memcpy(&state, payload.data(), sizeof(state));
std::lock_guard lk{m_callbackLock};
if (state != m_last && m_callback != nullptr) {
2018-12-07 19:17:51 -10:00
m_callback->controllerUpdate(state);
}
2018-12-07 19:17:51 -10:00
m_last = state;
}
void NintendoPowerA::finalCycle() {}
2018-12-07 19:17:51 -10:00
void NintendoPowerA::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {}
bool NintendoPowerAState::operator==(const NintendoPowerAState& other) const {
return std::memcmp(this, &other, sizeof(NintendoPowerAState)) == 0;
}
bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) const { return !operator==(other); }
2018-12-07 19:17:51 -10:00
} // namespace boo