mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-09 13:37:48 +00:00
Windows refactors
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
#include "boo/inputdev/DualshockPad.hpp"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <endian.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
static inline uint16_t bswap16(uint16_t val) {return _byteswap_ushort(val);}
|
||||
#else
|
||||
static inline uint16_t bswap16(uint16_t val) {return __builtin_byteswap(val);}
|
||||
#endif
|
||||
|
||||
#define RAD_TO_DEG (180.0/M_PI)
|
||||
|
||||
void hexdump(void *ptr, int buflen) {
|
||||
@@ -80,9 +86,9 @@ void DualshockPad::transferCycle()
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
state.m_accelerometer[i] = be16toh(state.m_accelerometer[i]);
|
||||
state.m_accelerometer[i] = bswap16(state.m_accelerometer[i]);
|
||||
|
||||
state.m_gyrometerZ = be16toh(state.m_gyrometerZ);
|
||||
state.m_gyrometerZ = bswap16(state.m_gyrometerZ);
|
||||
if (m_callback)
|
||||
m_callback->controllerUpdate(state);
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS 1 /* STFU MSVC */
|
||||
#include "IHIDDevice.hpp"
|
||||
#include "inputdev/CDeviceToken.hpp"
|
||||
#include "inputdev/CDeviceBase.hpp"
|
||||
#include "boo/inputdev/DeviceToken.hpp"
|
||||
#include "boo/inputdev/DeviceBase.hpp"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define _WIN32_LEAN_AND_MEAN 1
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <winusb.h>
|
||||
#include <usb100.h>
|
||||
@@ -17,10 +19,10 @@
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CHIDDeviceWinUSB final : public IHIDDevice
|
||||
class HIDDeviceWinUSB final : public IHIDDevice
|
||||
{
|
||||
CDeviceToken& m_token;
|
||||
CDeviceBase& m_devImp;
|
||||
DeviceToken& m_token;
|
||||
DeviceBase& m_devImp;
|
||||
|
||||
HANDLE m_devHandle = 0;
|
||||
WINUSB_INTERFACE_HANDLE m_usbHandle = NULL;
|
||||
@@ -60,7 +62,7 @@ class CHIDDeviceWinUSB final : public IHIDDevice
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _threadProcUSBLL(CHIDDeviceWinUSB* device)
|
||||
static void _threadProcUSBLL(HIDDeviceWinUSB* device)
|
||||
{
|
||||
unsigned i;
|
||||
char errStr[256];
|
||||
@@ -141,7 +143,7 @@ class CHIDDeviceWinUSB final : public IHIDDevice
|
||||
|
||||
}
|
||||
|
||||
static void _threadProcBTLL(CHIDDeviceWinUSB* device)
|
||||
static void _threadProcBTLL(HIDDeviceWinUSB* device)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(device->m_initMutex);
|
||||
|
||||
@@ -158,7 +160,7 @@ class CHIDDeviceWinUSB final : public IHIDDevice
|
||||
|
||||
}
|
||||
|
||||
static void _threadProcHID(CHIDDeviceWinUSB* device)
|
||||
static void _threadProcHID(HIDDeviceWinUSB* device)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(device->m_initMutex);
|
||||
|
||||
@@ -187,26 +189,26 @@ class CHIDDeviceWinUSB final : public IHIDDevice
|
||||
|
||||
public:
|
||||
|
||||
CHIDDeviceWinUSB(CDeviceToken& token, CDeviceBase& devImp)
|
||||
HIDDeviceWinUSB(DeviceToken& token, DeviceBase& devImp)
|
||||
: m_token(token),
|
||||
m_devImp(devImp),
|
||||
m_devPath(token.getDevicePath())
|
||||
{
|
||||
devImp.m_hidDev = this;
|
||||
std::unique_lock<std::mutex> lk(m_initMutex);
|
||||
CDeviceToken::TDeviceType dType = token.getDeviceType();
|
||||
if (dType == CDeviceToken::DEVTYPE_USB)
|
||||
DeviceToken::TDeviceType dType = token.getDeviceType();
|
||||
if (dType == DeviceToken::DEVTYPE_USB)
|
||||
m_thread = new std::thread(_threadProcUSBLL, this);
|
||||
else if (dType == CDeviceToken::DEVTYPE_BLUETOOTH)
|
||||
else if (dType == DeviceToken::DEVTYPE_BLUETOOTH)
|
||||
m_thread = new std::thread(_threadProcBTLL, this);
|
||||
else if (dType == CDeviceToken::DEVTYPE_GENERICHID)
|
||||
else if (dType == DeviceToken::DEVTYPE_GENERICHID)
|
||||
m_thread = new std::thread(_threadProcHID, this);
|
||||
else
|
||||
throw std::runtime_error("invalid token supplied to device constructor");
|
||||
m_initCond.wait(lk);
|
||||
}
|
||||
|
||||
~CHIDDeviceWinUSB()
|
||||
~HIDDeviceWinUSB()
|
||||
{
|
||||
m_runningTransferLoop = false;
|
||||
m_thread->join();
|
||||
@@ -216,9 +218,9 @@ public:
|
||||
|
||||
};
|
||||
|
||||
IHIDDevice* IHIDDeviceNew(CDeviceToken& token, CDeviceBase& devImp)
|
||||
IHIDDevice* IHIDDeviceNew(DeviceToken& token, DeviceBase& devImp)
|
||||
{
|
||||
return new CHIDDeviceWinUSB(token, devImp);
|
||||
return new HIDDeviceWinUSB(token, devImp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS 1 /* STFU MSVC */
|
||||
#include "inputdev/IHIDListener.hpp"
|
||||
#include "inputdev/CDeviceFinder.hpp"
|
||||
#include "boo/inputdev/IHIDListener.hpp"
|
||||
#include "boo/inputdev/DeviceFinder.hpp"
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
#define _WIN32_LEAN_AND_MEAN 1
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#endif
|
||||
#include <windows.h>
|
||||
|
||||
#include <initguid.h>
|
||||
@@ -16,9 +18,9 @@
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CHIDListenerWinUSB final : public IHIDListener
|
||||
class HIDListenerWinUSB final : public IHIDListener
|
||||
{
|
||||
CDeviceFinder& m_finder;
|
||||
DeviceFinder& m_finder;
|
||||
|
||||
bool m_scanningEnabled;
|
||||
|
||||
@@ -140,9 +142,9 @@ class CHIDListenerWinUSB final : public IHIDListener
|
||||
|
||||
/* Whew!! that's a single device enumerated!! */
|
||||
if (!m_finder._hasToken(DeviceInterfaceDetailData.wtf.DevicePath))
|
||||
m_finder._insertToken(CDeviceToken(CDeviceToken::DEVTYPE_USB,
|
||||
vid, pid, manuf, product,
|
||||
DeviceInterfaceDetailData.wtf.DevicePath));
|
||||
m_finder._insertToken(DeviceToken(DeviceToken::DEVTYPE_USB,
|
||||
vid, pid, manuf, product,
|
||||
DeviceInterfaceDetailData.wtf.DevicePath));
|
||||
|
||||
}
|
||||
|
||||
@@ -151,14 +153,14 @@ class CHIDListenerWinUSB final : public IHIDListener
|
||||
}
|
||||
|
||||
public:
|
||||
CHIDListenerWinUSB(CDeviceFinder& finder)
|
||||
HIDListenerWinUSB(DeviceFinder& finder)
|
||||
: m_finder(finder)
|
||||
{
|
||||
/* Initial HID Device Add */
|
||||
_pollDevices(NULL);
|
||||
}
|
||||
|
||||
~CHIDListenerWinUSB()
|
||||
~HIDListenerWinUSB()
|
||||
{}
|
||||
|
||||
/* Automatic device scanning */
|
||||
@@ -201,9 +203,9 @@ public:
|
||||
|
||||
};
|
||||
|
||||
IHIDListener* IHIDListenerNew(CDeviceFinder& finder)
|
||||
IHIDListener* IHIDListenerNew(DeviceFinder& finder)
|
||||
{
|
||||
return new CHIDListenerWinUSB(finder);
|
||||
return new HIDListenerWinUSB(finder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class IHIDDevice
|
||||
virtual bool _sendUSBInterruptTransfer(const uint8_t* data, size_t length)=0;
|
||||
virtual size_t _receiveUSBInterruptTransfer(uint8_t* data, size_t length)=0;
|
||||
virtual bool _sendHIDReport(const uint8_t* data, size_t length, uint16_t message)=0;
|
||||
virtual size_t _recieveReport(const uint8_t* data, size_t length, uint16_t message){}
|
||||
virtual size_t _recieveReport(const uint8_t* data, size_t length, uint16_t message) {return 0;}
|
||||
public:
|
||||
inline virtual ~IHIDDevice() {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user