mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-16 08:27:10 +00:00
Win32 input device refinements and XInput support
This commit is contained in:
@@ -37,7 +37,7 @@ private:
|
||||
|
||||
/* Platform-specific USB event registration
|
||||
* (for auto-scanning, NULL if not registered) */
|
||||
IHIDListener* m_listener;
|
||||
std::unique_ptr<IHIDListener> m_listener;
|
||||
|
||||
/* Set of presently-connected device tokens */
|
||||
TDeviceTokens m_tokens;
|
||||
@@ -95,7 +95,6 @@ public:
|
||||
|
||||
/* Application must specify its interested device-types */
|
||||
DeviceFinder(std::unordered_set<std::type_index> types)
|
||||
: m_listener(NULL)
|
||||
{
|
||||
if (skDevFinder)
|
||||
{
|
||||
@@ -118,7 +117,6 @@ public:
|
||||
{
|
||||
if (m_listener)
|
||||
m_listener->stopScanning();
|
||||
delete m_listener;
|
||||
skDevFinder = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <typeindex>
|
||||
#include <memory>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
@@ -13,7 +14,8 @@ enum class DeviceType
|
||||
None = 0,
|
||||
USB = 1,
|
||||
Bluetooth = 2,
|
||||
HID = 3
|
||||
HID = 3,
|
||||
XInput = 4
|
||||
};
|
||||
|
||||
class DeviceToken;
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace boo
|
||||
class DeviceToken
|
||||
{
|
||||
friend struct DeviceSignature;
|
||||
friend class HIDListenerWinUSB;
|
||||
DeviceType m_devType;
|
||||
unsigned m_vendorId;
|
||||
unsigned m_productId;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdint.h>
|
||||
#include <type_traits>
|
||||
#include "DeviceBase.hpp"
|
||||
#include "../System.hpp"
|
||||
#include "boo/System.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
@@ -117,9 +117,8 @@ struct DualshockPadState
|
||||
class DualshockPad;
|
||||
struct IDualshockPadCallback
|
||||
{
|
||||
DualshockPad* ctrl = nullptr;
|
||||
virtual void controllerDisconnected() {}
|
||||
virtual void controllerUpdate(const DualshockPadState&) {}
|
||||
virtual void controllerUpdate(DualshockPad&, const DualshockPadState&) {}
|
||||
};
|
||||
|
||||
class DualshockPad final : public DeviceBase
|
||||
@@ -141,8 +140,7 @@ public:
|
||||
DualshockPad(DeviceToken* token);
|
||||
~DualshockPad();
|
||||
|
||||
void setCallback(IDualshockPadCallback* cb)
|
||||
{ m_callback = cb; if (m_callback) m_callback->ctrl = this; }
|
||||
void setCallback(IDualshockPadCallback* cb) { m_callback = cb; }
|
||||
|
||||
void startRumble(EDualshockMotor motor, uint8_t duration = 254, uint8_t intensity=255)
|
||||
{
|
||||
@@ -159,9 +157,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void stopRumble(int motor)
|
||||
void stopRumble(EDualshockMotor motor)
|
||||
{
|
||||
m_rumbleRequest &= ~EDualshockMotor(motor);
|
||||
m_rumbleRequest &= ~motor;
|
||||
}
|
||||
|
||||
EDualshockLED getLED()
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
};
|
||||
|
||||
/* Platform-specific constructor */
|
||||
IHIDListener* IHIDListenerNew(DeviceFinder& finder);
|
||||
std::unique_ptr<IHIDListener> IHIDListenerNew(DeviceFinder& finder);
|
||||
|
||||
}
|
||||
|
||||
|
||||
68
include/boo/inputdev/XInputPad.hpp
Normal file
68
include/boo/inputdev/XInputPad.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef XINPUTPAD_HPP
|
||||
#define XINPUTPAD_HPP
|
||||
|
||||
#include "DeviceBase.hpp"
|
||||
#include "boo/System.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
struct XInputPadState
|
||||
{
|
||||
uint16_t wButtons;
|
||||
uint8_t bLeftTrigger;
|
||||
uint8_t bRightTrigger;
|
||||
int16_t sThumbLX;
|
||||
int16_t sThumbLY;
|
||||
int16_t sThumbRX;
|
||||
int16_t sThumbRY;
|
||||
};
|
||||
|
||||
enum class EXInputMotor : uint8_t
|
||||
{
|
||||
None = 0,
|
||||
Right = 1<<0,
|
||||
Left = 1<<1,
|
||||
};
|
||||
ENABLE_BITWISE_ENUM(EXInputMotor)
|
||||
|
||||
class XInputPad;
|
||||
struct IXInputPadCallback
|
||||
{
|
||||
virtual void controllerDisconnected() {}
|
||||
virtual void controllerUpdate(XInputPad& pad, const XInputPadState&) {}
|
||||
};
|
||||
|
||||
class XInputPad final : public DeviceBase
|
||||
{
|
||||
friend class HIDListenerWinUSB;
|
||||
IXInputPadCallback* m_callback;
|
||||
uint16_t m_rumbleRequest[2] = {};
|
||||
uint16_t m_rumbleState[2] = {};
|
||||
public:
|
||||
XInputPad(DeviceToken* token) : DeviceBase(token) {}
|
||||
void setCallback(IXInputPadCallback* cb) { m_callback = cb; }
|
||||
void deviceDisconnected()
|
||||
{
|
||||
if (m_callback)
|
||||
m_callback->controllerDisconnected();
|
||||
}
|
||||
void startRumble(EXInputMotor motors, uint16_t intensity)
|
||||
{
|
||||
if ((motors & EXInputMotor::Left) != EXInputMotor::None)
|
||||
m_rumbleRequest[0] = intensity;
|
||||
if ((motors & EXInputMotor::Right) != EXInputMotor::None)
|
||||
m_rumbleRequest[1] = intensity;
|
||||
}
|
||||
void stopRumble(EXInputMotor motors)
|
||||
{
|
||||
if ((motors & EXInputMotor::Left) != EXInputMotor::None)
|
||||
m_rumbleRequest[0] = 0;
|
||||
if ((motors & EXInputMotor::Right) != EXInputMotor::None)
|
||||
m_rumbleRequest[1] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // XINPUTPAD_HPP
|
||||
Reference in New Issue
Block a user