oculus1

view libovr/Src/OVR_HIDDevice.h @ 21:ef4c9d8eeca7

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