2015-08-18 12:43:30 -10:00
|
|
|
#include "boo/inputdev/DeviceBase.hpp"
|
|
|
|
|
#include "boo/inputdev/DeviceToken.hpp"
|
2019-08-19 19:08:54 -04:00
|
|
|
#include "lib/inputdev/IHIDDevice.hpp"
|
2015-04-20 18:02:43 -10:00
|
|
|
|
2018-12-07 19:17:51 -10:00
|
|
|
namespace boo {
|
2015-04-29 00:24:39 -10:00
|
|
|
|
2018-12-07 19:17:51 -10:00
|
|
|
DeviceBase::DeviceBase(uint64_t typeHash, DeviceToken* token) : m_typeHash(typeHash), m_token(token) {}
|
|
|
|
|
|
|
|
|
|
void DeviceBase::_deviceDisconnected() {
|
|
|
|
|
deviceDisconnected();
|
|
|
|
|
m_token = nullptr;
|
|
|
|
|
if (m_hidDev) {
|
|
|
|
|
m_hidDev->_deviceDisconnected();
|
|
|
|
|
m_hidDev.reset();
|
|
|
|
|
}
|
2015-04-22 14:46:32 -10:00
|
|
|
}
|
|
|
|
|
|
2018-12-07 19:17:51 -10:00
|
|
|
void DeviceBase::closeDevice() {
|
|
|
|
|
if (m_token)
|
|
|
|
|
m_token->_deviceClose();
|
2015-04-20 18:02:43 -10:00
|
|
|
}
|
|
|
|
|
|
2019-07-19 18:22:36 -10:00
|
|
|
void DeviceBase::vdeviceError(fmt::string_view error, fmt::format_args args) {
|
|
|
|
|
fmt::vprint(error, args);
|
2015-04-22 11:48:23 -10:00
|
|
|
}
|
|
|
|
|
|
2018-12-07 19:17:51 -10:00
|
|
|
bool DeviceBase::sendUSBInterruptTransfer(const uint8_t* data, size_t length) {
|
|
|
|
|
if (m_hidDev)
|
|
|
|
|
return m_hidDev->_sendUSBInterruptTransfer(data, length);
|
|
|
|
|
return false;
|
2015-08-18 16:32:19 -07:00
|
|
|
}
|
|
|
|
|
|
2018-12-07 19:17:51 -10:00
|
|
|
size_t DeviceBase::receiveUSBInterruptTransfer(uint8_t* data, size_t length) {
|
|
|
|
|
if (m_hidDev)
|
|
|
|
|
return m_hidDev->_receiveUSBInterruptTransfer(data, length);
|
|
|
|
|
return false;
|
2015-04-23 14:24:15 -10:00
|
|
|
}
|
|
|
|
|
|
2019-08-16 02:06:51 -04:00
|
|
|
unsigned DeviceBase::getVendorId() const {
|
2018-12-07 19:17:51 -10:00
|
|
|
if (m_token)
|
|
|
|
|
return m_token->getVendorId();
|
|
|
|
|
return -1;
|
2015-04-23 14:24:15 -10:00
|
|
|
}
|
|
|
|
|
|
2019-08-16 02:06:51 -04:00
|
|
|
unsigned DeviceBase::getProductId() const {
|
2018-12-07 19:17:51 -10:00
|
|
|
if (m_token)
|
|
|
|
|
return m_token->getProductId();
|
|
|
|
|
return -1;
|
2017-12-15 18:09:56 -08:00
|
|
|
}
|
|
|
|
|
|
2019-08-16 02:06:51 -04:00
|
|
|
std::string_view DeviceBase::getVendorName() const {
|
2018-12-07 19:17:51 -10:00
|
|
|
if (m_token)
|
|
|
|
|
return m_token->getVendorName();
|
|
|
|
|
return {};
|
2017-12-15 18:09:56 -08:00
|
|
|
}
|
|
|
|
|
|
2019-08-16 02:06:51 -04:00
|
|
|
std::string_view DeviceBase::getProductName() const {
|
2018-12-07 19:17:51 -10:00
|
|
|
if (m_token)
|
|
|
|
|
return m_token->getProductName();
|
|
|
|
|
return {};
|
2017-12-15 18:09:56 -08:00
|
|
|
}
|
|
|
|
|
|
2017-09-15 12:26:39 -10:00
|
|
|
#if _WIN32
|
2017-12-05 17:20:59 -10:00
|
|
|
#if !WINDOWS_STORE
|
2019-08-16 02:06:51 -04:00
|
|
|
PHIDP_PREPARSED_DATA DeviceBase::getReportDescriptor() const {
|
2018-12-07 19:17:51 -10:00
|
|
|
if (m_hidDev)
|
|
|
|
|
return m_hidDev->_getReportDescriptor();
|
|
|
|
|
return {};
|
2017-09-15 12:26:39 -10:00
|
|
|
}
|
2017-12-05 17:20:59 -10:00
|
|
|
#endif
|
2017-09-15 12:26:39 -10:00
|
|
|
#else
|
2019-08-16 02:06:51 -04:00
|
|
|
std::vector<uint8_t> DeviceBase::getReportDescriptor() const {
|
2018-12-07 19:17:51 -10:00
|
|
|
if (m_hidDev)
|
|
|
|
|
return m_hidDev->_getReportDescriptor();
|
|
|
|
|
return {};
|
2017-09-15 07:20:52 -10:00
|
|
|
}
|
2017-09-15 12:26:39 -10:00
|
|
|
#endif
|
2017-09-15 07:20:52 -10:00
|
|
|
|
2018-12-07 19:17:51 -10:00
|
|
|
bool DeviceBase::sendHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {
|
|
|
|
|
if (m_hidDev)
|
|
|
|
|
return m_hidDev->_sendHIDReport(data, length, tp, message);
|
|
|
|
|
return false;
|
2015-08-18 16:32:19 -07:00
|
|
|
}
|
|
|
|
|
|
2018-12-07 19:17:51 -10:00
|
|
|
size_t DeviceBase::receiveHIDReport(uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {
|
|
|
|
|
if (m_hidDev)
|
|
|
|
|
return m_hidDev->_receiveHIDReport(data, length, tp, message);
|
|
|
|
|
return 0;
|
2015-04-23 14:24:15 -10:00
|
|
|
}
|
|
|
|
|
|
2018-12-07 19:17:51 -10:00
|
|
|
} // namespace boo
|