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-09-15 17:20:52 +00:00
|
|
|
: DeviceBase(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-09-15 17:20:52 +00:00
|
|
|
if (m_cb)
|
|
|
|
m_cb->controllerDisconnected();
|
|
|
|
}
|
2015-04-30 23:17:46 +00:00
|
|
|
|
2017-09-15 17:20:52 +00:00
|
|
|
void GenericPad::initialCycle()
|
|
|
|
{
|
|
|
|
std::vector<uint8_t> reportDesc = getReportDescriptor();
|
|
|
|
m_parser.Parse(reportDesc.data(), reportDesc.size());
|
|
|
|
if (m_cb)
|
|
|
|
m_cb->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-09-15 17:20:52 +00:00
|
|
|
if (length == 0 || tp != HIDReportType::Input || !m_cb)
|
|
|
|
return;
|
|
|
|
std::function<bool(const HIDMainItem&, int32_t)> func =
|
|
|
|
[this](const HIDMainItem& item, int32_t value)
|
|
|
|
{
|
|
|
|
m_cb->valueUpdate(item, value);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
m_parser.ScanValues(func, data, length);
|
|
|
|
}
|
2015-04-30 23:17:46 +00:00
|
|
|
|
2017-09-15 17:20:52 +00:00
|
|
|
void GenericPad::enumerateValues(std::function<bool(const HIDMainItem& item)>& valueCB) const
|
|
|
|
{
|
|
|
|
std::function<bool(uint32_t, const HIDMainItem&)> func =
|
|
|
|
[&](uint32_t rep, const HIDMainItem& item) { return valueCB(item); };
|
|
|
|
m_parser.EnumerateValues(func);
|
2015-04-30 23:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|