Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_HIDDevice.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 Filename : OVR_HIDDevice.h
4 Content : Cross platform HID device interface.
5 Created : February 22, 2013
6 Authors : Lee Cooper
7 
8 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
9 
10 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
14 
15 You may obtain a copy of the License at
16 
17 http://www.oculusvr.com/licenses/LICENSE-3.1
18 
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
24 
25 *************************************************************************************/
26 
27 #ifndef OVR_HIDDevice_h
28 #define OVR_HIDDevice_h
29 
30 #include "OVR_HIDDeviceBase.h"
31 
32 #include "Kernel/OVR_RefCount.h"
33 #include "Kernel/OVR_String.h"
34 #include "Kernel/OVR_Timer.h"
35 
36 namespace OVR {
37 
38 class HIDDevice;
39 class DeviceManager;
40 
41 // HIDDeviceDesc contains interesting attributes of a HID device, including a Path
42 // that can be used to create it.
44 {
50  String Path; // Platform specific.
54 };
55 
56 // HIDEnumerateVisitor exposes a Visit interface called for every detected device
57 // by HIDDeviceManager::Enumerate.
59 {
60 public:
61 
62  // Should return true if we are interested in supporting
63  // this HID VendorId and ProductId pair.
64  virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId)
65  { OVR_UNUSED2(vendorId, productId); return true; }
66 
67  // Override to get notified about available device. Will only be called for
68  // devices that matched MatchVendorProduct.
69  virtual void Visit(HIDDevice&, const HIDDeviceDesc&) { }
70 };
71 
72 
73 //-------------------------------------------------------------------------------------
74 // ***** HIDDeviceManager
75 
76 // Internal manager for enumerating and opening HID devices.
77 // If an OVR::DeviceManager is created then an OVR::HIDDeviceManager will automatically be created and can be accessed from the
78 // DeviceManager by calling 'GetHIDDeviceManager()'. When using HIDDeviceManager in standalone mode, the client must call
79 // 'Create' below.
80 class HIDDeviceManager : public RefCountBase<HIDDeviceManager>
81 {
82 public:
83 
84  // Creates a new HIDDeviceManager. Only one instance of HIDDeviceManager should be created at a time.
85  static HIDDeviceManager* Create(Ptr<OVR::DeviceManager>& deviceManager);
86 
87  // Enumerate HID devices using a HIDEnumerateVisitor derived visitor class.
88  virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor) = 0;
89 
90  // Open a HID device with the specified path.
91  virtual HIDDevice* Open(const String& path) = 0;
92 
93 protected:
95  { }
96 };
97 
98 //-------------------------------------------------------------------------------------
99 // ***** HIDDevice
100 
101 // HID device object. This is designed to be operated in synchronous
102 // and asynchronous modes. With no handler set, input messages will be
103 // stored and can be retrieved by calling 'Read' or 'ReadBlocking'.
104 class HIDDevice : public RefCountBase<HIDDevice>, public HIDDeviceBase
105 {
106 public:
107 
109  : Handler(NULL)
110  {
111  }
112 
113  virtual ~HIDDevice() {}
114 
115  virtual bool SetFeatureReport(UByte* data, UInt32 length) = 0;
116  virtual bool GetFeatureReport(UByte* data, UInt32 length) = 0;
117 
118 // Not yet implemented.
119 /*
120  virtual bool Write(UByte* data, UInt32 length) = 0;
121 
122  virtual bool Read(UByte* pData, UInt32 length, UInt32 timeoutMilliS) = 0;
123  virtual bool ReadBlocking(UByte* pData, UInt32 length) = 0;
124 */
125 
127  {
128  public:
129  virtual void OnInputReport(UByte* pData, UInt32 length)
130  { OVR_UNUSED2(pData, length); }
131 
132  virtual double OnTicks(double tickSeconds)
133  { OVR_UNUSED1(tickSeconds); return 1000.0 ; }
134 
136  {
139  };
140 
141  virtual void OnDeviceMessage(HIDDeviceMessageType messageType)
142  { OVR_UNUSED1(messageType); }
143  };
144 
145  void SetHandler(HIDHandler* handler)
146  { Handler = handler; }
147 
148 protected:
150 };
151 
152 } // namespace OVR
153 
154 #endif
virtual void OnInputReport(UByte *pData, UInt32 length)
#define NULL
static HIDDeviceManager * Create(Ptr< OVR::DeviceManager > &deviceManager)
uint16_t UInt16
Definition: OVR_Types.h:251
uint32_t UInt32
Definition: OVR_Types.h:253
virtual double OnTicks(double tickSeconds)
virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId)
Definition: OVR_HIDDevice.h:64
virtual bool Enumerate(HIDEnumerateVisitor *enumVisitor)=0
virtual ~HIDDevice()
uint8_t UByte
Definition: OVR_Types.h:249
virtual void Visit(HIDDevice &, const HIDDeviceDesc &)
Definition: OVR_HIDDevice.h:69
#define OVR_UNUSED1(a1)
void SetHandler(HIDHandler *handler)
virtual void OnDeviceMessage(HIDDeviceMessageType messageType)
virtual HIDDevice * Open(const String &path)=0
virtual bool SetFeatureReport(UByte *data, UInt32 length)=0
HIDHandler * Handler
#define OVR_UNUSED2(a1, a2)
virtual bool GetFeatureReport(UByte *data, UInt32 length)=0