2015-08-18 22:43:30 +00:00
|
|
|
#include "boo/inputdev/GenericPad.hpp"
|
|
|
|
#include "boo/inputdev/DeviceToken.hpp"
|
2015-04-30 23:17:46 +00:00
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
GenericPad::GenericPad(DeviceToken* token)
|
2017-12-15 23:35:54 +00:00
|
|
|
: TDeviceBase<IGenericPadCallback>(token)
|
2015-04-30 23:17:46 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-15 17:20:52 +00:00
|
|
|
GenericPad::~GenericPad() {}
|
|
|
|
|
|
|
|
void GenericPad::deviceDisconnected()
|
2015-04-30 23:17:46 +00:00
|
|
|
{
|
2017-12-15 23:35:54 +00:00
|
|
|
std::lock_guard<std::mutex> lk(m_callbackLock);
|
|
|
|
if (m_callback)
|
|
|
|
m_callback->controllerDisconnected();
|
2017-09-15 17:20:52 +00:00
|
|
|
}
|
2015-04-30 23:17:46 +00:00
|
|
|
|
2017-09-15 17:20:52 +00:00
|
|
|
void GenericPad::initialCycle()
|
|
|
|
{
|
2017-09-15 22:26:39 +00:00
|
|
|
#if _WIN32
|
2017-12-06 03:20:59 +00:00
|
|
|
#if !WINDOWS_STORE
|
2017-09-15 22:26:39 +00:00
|
|
|
const PHIDP_PREPARSED_DATA reportDesc = getReportDescriptor();
|
|
|
|
m_parser.Parse(reportDesc);
|
2017-12-06 03:20:59 +00:00
|
|
|
#endif
|
2017-09-15 22:26:39 +00:00
|
|
|
#else
|
2017-09-15 17:20:52 +00:00
|
|
|
std::vector<uint8_t> reportDesc = getReportDescriptor();
|
|
|
|
m_parser.Parse(reportDesc.data(), reportDesc.size());
|
2017-09-15 22:26:39 +00:00
|
|
|
#endif
|
2017-12-15 23:35:54 +00:00
|
|
|
std::lock_guard<std::mutex> lk(m_callbackLock);
|
|
|
|
if (m_callback)
|
|
|
|
m_callback->controllerConnected();
|
2015-04-30 23:17:46 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 17:20:52 +00:00
|
|
|
void GenericPad::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message)
|
2015-04-30 23:17:46 +00:00
|
|
|
{
|
2017-12-15 23:35:54 +00:00
|
|
|
std::lock_guard<std::mutex> lk(m_callbackLock);
|
|
|
|
if (length == 0 || tp != HIDReportType::Input || !m_callback)
|
2017-09-15 17:20:52 +00:00
|
|
|
return;
|
|
|
|
std::function<bool(const HIDMainItem&, int32_t)> func =
|
|
|
|
[this](const HIDMainItem& item, int32_t value)
|
|
|
|
{
|
2017-12-15 23:35:54 +00:00
|
|
|
m_callback->valueUpdate(item, value);
|
2017-09-15 17:20:52 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
m_parser.ScanValues(func, data, length);
|
|
|
|
}
|
2015-04-30 23:17:46 +00:00
|
|
|
|
2017-09-15 22:26:39 +00:00
|
|
|
void GenericPad::enumerateValues(const std::function<bool(const HIDMainItem& item)>& valueCB) const
|
2017-09-15 17:20:52 +00:00
|
|
|
{
|
2017-09-15 22:26:39 +00:00
|
|
|
m_parser.EnumerateValues(valueCB);
|
2015-04-30 23:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|