1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/************************************************************************************
Filename : OVR_HIDDevice.h
Content : Cross platform HID device interface.
Created : February 22, 2013
Authors : Lee Cooper
Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
Use of this software is subject to the terms of the Oculus license
agreement provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
*************************************************************************************/
#ifndef OVR_HIDDevice_h
#define OVR_HIDDevice_h
#include "OVR_HIDDeviceBase.h"
#include "Kernel/OVR_RefCount.h"
#include "Kernel/OVR_String.h"
#include "Kernel/OVR_Timer.h"
namespace OVR {
class HIDDevice;
class DeviceManager;
// HIDDeviceDesc contains interesting attributes of a HID device, including a Path
// that can be used to create it.
struct HIDDeviceDesc
{
UInt16 VendorId;
UInt16 ProductId;
UInt16 VersionNumber;
UInt16 Usage;
UInt16 UsagePage;
String Path; // Platform specific.
String Manufacturer;
String Product;
String SerialNumber;
};
// HIDEnumerateVisitor exposes a Visit interface called for every detected device
// by HIDDeviceManager::Enumerate.
class HIDEnumerateVisitor
{
public:
// Should return true if we are interested in supporting
// this HID VendorId and ProductId pair.
virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId)
{ OVR_UNUSED2(vendorId, productId); return true; }
// Override to get notified about available device. Will only be called for
// devices that matched MatchVendorProduct.
virtual void Visit(HIDDevice&, const HIDDeviceDesc&) { }
};
//-------------------------------------------------------------------------------------
// ***** HIDDeviceManager
// Internal manager for enumerating and opening HID devices.
// If an OVR::DeviceManager is created then an OVR::HIDDeviceManager will automatically be created and can be accessed from the
// DeviceManager by calling 'GetHIDDeviceManager()'. When using HIDDeviceManager in standalone mode, the client must call
// 'Create' below.
class HIDDeviceManager : public RefCountBase<HIDDeviceManager>
{
public:
// Creates a new HIDDeviceManager. Only one instance of HIDDeviceManager should be created at a time.
static HIDDeviceManager* Create();
// Enumerate HID devices using a HIDEnumerateVisitor derived visitor class.
virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor) = 0;
// Open a HID device with the specified path.
virtual HIDDevice* Open(const String& path) = 0;
protected:
HIDDeviceManager()
{ }
};
//-------------------------------------------------------------------------------------
// ***** HIDDevice
// HID device object. This is designed to be operated in synchronous
// and asynchronous modes. With no handler set, input messages will be
// stored and can be retrieved by calling 'Read' or 'ReadBlocking'.
class HIDDevice : public RefCountBase<HIDDevice>, public HIDDeviceBase
{
public:
HIDDevice()
: Handler(NULL)
{
}
virtual ~HIDDevice() {}
virtual bool SetFeatureReport(UByte* data, UInt32 length) = 0;
virtual bool GetFeatureReport(UByte* data, UInt32 length) = 0;
// Not yet implemented.
/*
virtual bool Write(UByte* data, UInt32 length) = 0;
virtual bool Read(UByte* pData, UInt32 length, UInt32 timeoutMilliS) = 0;
virtual bool ReadBlocking(UByte* pData, UInt32 length) = 0;
*/
class HIDHandler
{
public:
virtual void OnInputReport(const UByte* pData, UInt32 length)
{ OVR_UNUSED2(pData, length); }
virtual UInt64 OnTicks(UInt64 ticksMks)
{ OVR_UNUSED1(ticksMks); return Timer::MksPerSecond * 1000; ; }
enum HIDDeviceMessageType
{
HIDDeviceMessage_DeviceAdded = 0,
HIDDeviceMessage_DeviceRemoved = 1
};
virtual void OnDeviceMessage(HIDDeviceMessageType messageType)
{ OVR_UNUSED1(messageType); }
};
void SetHandler(HIDHandler* handler)
{ Handler = handler; }
protected:
HIDHandler* Handler;
};
} // namespace OVR
#endif
|