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