2015-08-18 22:43:30 +00:00
|
|
|
#include "boo/inputdev/DeviceBase.hpp"
|
|
|
|
#include "boo/inputdev/DeviceToken.hpp"
|
2015-04-21 04:02:43 +00:00
|
|
|
#include "IHIDDevice.hpp"
|
2015-08-18 23:32:19 +00:00
|
|
|
#include <cstdarg>
|
2015-04-21 04:02:43 +00:00
|
|
|
|
2015-04-29 10:24:39 +00:00
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
2018-10-07 02:49:22 +00:00
|
|
|
DeviceBase::DeviceBase(uint64_t typeHash, DeviceToken* token)
|
|
|
|
: m_typeHash(typeHash), m_token(token)
|
2015-04-23 00:46:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
void DeviceBase::_deviceDisconnected()
|
2015-04-21 04:02:43 +00:00
|
|
|
{
|
2015-04-22 21:48:23 +00:00
|
|
|
deviceDisconnected();
|
2017-05-07 21:24:00 +00:00
|
|
|
m_token = nullptr;
|
2015-04-23 00:46:32 +00:00
|
|
|
if (m_hidDev)
|
|
|
|
{
|
|
|
|
m_hidDev->_deviceDisconnected();
|
2017-05-07 21:24:00 +00:00
|
|
|
m_hidDev.reset();
|
2015-04-23 00:46:32 +00:00
|
|
|
}
|
2015-04-21 04:02:43 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
void DeviceBase::closeDevice()
|
2015-04-22 21:48:23 +00:00
|
|
|
{
|
|
|
|
if (m_token)
|
|
|
|
m_token->_deviceClose();
|
|
|
|
}
|
|
|
|
|
2015-08-18 23:32:19 +00:00
|
|
|
void DeviceBase::deviceError(const char* error, ...)
|
|
|
|
{
|
|
|
|
va_list vl;
|
|
|
|
va_start(vl, error);
|
|
|
|
vfprintf(stderr, error, vl);
|
|
|
|
va_end(vl);
|
|
|
|
}
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
bool DeviceBase::sendUSBInterruptTransfer(const uint8_t* data, size_t length)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
|
|
|
if (m_hidDev)
|
2015-05-10 07:02:18 +00:00
|
|
|
return m_hidDev->_sendUSBInterruptTransfer(data, length);
|
2015-04-24 00:24:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
size_t DeviceBase::receiveUSBInterruptTransfer(uint8_t* data, size_t length)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
|
|
|
if (m_hidDev)
|
2015-05-10 07:02:18 +00:00
|
|
|
return m_hidDev->_receiveUSBInterruptTransfer(data, length);
|
2015-04-24 00:24:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-16 02:09:56 +00:00
|
|
|
unsigned DeviceBase::getVendorId()
|
|
|
|
{
|
|
|
|
if (m_token)
|
|
|
|
return m_token->getVendorId();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned DeviceBase::getProductId()
|
|
|
|
{
|
|
|
|
if (m_token)
|
|
|
|
return m_token->getProductId();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string_view DeviceBase::getVendorName()
|
|
|
|
{
|
|
|
|
if (m_token)
|
|
|
|
return m_token->getVendorName();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string_view DeviceBase::getProductName()
|
|
|
|
{
|
|
|
|
if (m_token)
|
|
|
|
return m_token->getProductName();
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
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 DeviceBase::getReportDescriptor()
|
|
|
|
{
|
|
|
|
if (m_hidDev)
|
|
|
|
return m_hidDev->_getReportDescriptor();
|
|
|
|
return {};
|
|
|
|
}
|
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> DeviceBase::getReportDescriptor()
|
|
|
|
{
|
|
|
|
if (m_hidDev)
|
|
|
|
return m_hidDev->_getReportDescriptor();
|
|
|
|
return {};
|
|
|
|
}
|
2017-09-15 22:26:39 +00:00
|
|
|
#endif
|
2017-09-15 17:20:52 +00:00
|
|
|
|
2017-05-07 21:24:00 +00:00
|
|
|
bool DeviceBase::sendHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message)
|
2015-08-18 23:32:19 +00:00
|
|
|
{
|
|
|
|
if (m_hidDev)
|
2017-05-07 21:24:00 +00:00
|
|
|
return m_hidDev->_sendHIDReport(data, length, tp, message);
|
2015-08-18 23:32:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-07 21:24:00 +00:00
|
|
|
size_t DeviceBase::receiveHIDReport(uint8_t* data, size_t length, HIDReportType tp, uint32_t message)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
|
|
|
if (m_hidDev)
|
2017-05-07 21:24:00 +00:00
|
|
|
return m_hidDev->_receiveHIDReport(data, length, tp, message);
|
|
|
|
return 0;
|
2015-04-24 00:24:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-29 10:24:39 +00:00
|
|
|
}
|