OVR_HIDDevice.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   OVR_HIDDevice.h
00004 Content     :   Cross platform HID device interface.
00005 Created     :   February 22, 2013
00006 Authors     :   Lee Cooper
00007 
00008 Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
00009 
00010 Use of this software is subject to the terms of the Oculus license
00011 agreement provided at the time of installation or download, or which
00012 otherwise accompanies this software in either electronic or hard copy form.
00013 
00014 *************************************************************************************/
00015 
00016 #ifndef OVR_HIDDevice_h
00017 #define OVR_HIDDevice_h
00018 
00019 #include "OVR_HIDDeviceBase.h"
00020 
00021 #include "Kernel/OVR_RefCount.h"
00022 #include "Kernel/OVR_String.h"
00023 #include "Kernel/OVR_Timer.h"
00024 
00025 namespace OVR {
00026 
00027 class HIDDevice;
00028 class DeviceManager;
00029 
00030 // HIDDeviceDesc contains interesting attributes of a HID device, including a Path
00031 // that can be used to create it.
00032 struct HIDDeviceDesc
00033 {
00034     UInt16  VendorId;
00035     UInt16  ProductId;
00036     UInt16  VersionNumber;
00037     UInt16  Usage;
00038     UInt16  UsagePage;
00039     String  Path;           // Platform specific.
00040     String  Manufacturer;
00041     String  Product;
00042     String  SerialNumber;
00043 };
00044 
00045 // HIDEnumerateVisitor exposes a Visit interface called for every detected device
00046 // by HIDDeviceManager::Enumerate. 
00047 class HIDEnumerateVisitor
00048 {
00049 public:
00050 
00051     // Should return true if we are interested in supporting
00052     // this HID VendorId and ProductId pair.
00053     virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId)
00054     { OVR_UNUSED2(vendorId, productId); return true; }
00055 
00056     // Override to get notified about available device. Will only be called for
00057     // devices that matched MatchVendorProduct.
00058     virtual void Visit(HIDDevice&, const HIDDeviceDesc&) { }
00059 };
00060 
00061 
00062 //-------------------------------------------------------------------------------------
00063 // ***** HIDDeviceManager
00064 
00065 // Internal manager for enumerating and opening HID devices.
00066 // If an OVR::DeviceManager is created then an OVR::HIDDeviceManager will automatically be created and can be accessed from the
00067 // DeviceManager by calling 'GetHIDDeviceManager()'. When using HIDDeviceManager in standalone mode, the client must call
00068 // 'Create' below.
00069 class HIDDeviceManager : public RefCountBase<HIDDeviceManager>
00070 {
00071 public:
00072 
00073     // Creates a new HIDDeviceManager. Only one instance of HIDDeviceManager should be created at a time.
00074     static HIDDeviceManager* Create();
00075 
00076     // Enumerate HID devices using a HIDEnumerateVisitor derived visitor class.
00077     virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor) = 0;
00078 
00079     // Open a HID device with the specified path.
00080     virtual HIDDevice* Open(const String& path) = 0;
00081 
00082 protected:
00083     HIDDeviceManager()
00084     { }
00085 };
00086 
00087 //-------------------------------------------------------------------------------------
00088 // ***** HIDDevice
00089 
00090 // HID device object. This is designed to be operated in synchronous
00091 // and asynchronous modes. With no handler set, input messages will be
00092 // stored and can be retrieved by calling 'Read' or 'ReadBlocking'.
00093 class HIDDevice : public RefCountBase<HIDDevice>, public HIDDeviceBase
00094 {
00095 public:
00096 
00097     HIDDevice()
00098      :  Handler(NULL)
00099     {
00100     }
00101 
00102     virtual ~HIDDevice() {}
00103 
00104     virtual bool SetFeatureReport(UByte* data, UInt32 length) = 0;
00105     virtual bool GetFeatureReport(UByte* data, UInt32 length) = 0;
00106 
00107 // Not yet implemented.
00108 /*
00109     virtual bool Write(UByte* data, UInt32 length) = 0;
00110 
00111     virtual bool Read(UByte* pData, UInt32 length, UInt32 timeoutMilliS) = 0;
00112     virtual bool ReadBlocking(UByte* pData, UInt32 length) = 0;
00113 */
00114 
00115     class HIDHandler
00116     {
00117     public:
00118         virtual void OnInputReport(UByte* pData, UInt32 length)
00119         { OVR_UNUSED2(pData, length); }
00120 
00121         virtual UInt64 OnTicks(UInt64 ticksMks)
00122         { OVR_UNUSED1(ticksMks);  return Timer::MksPerSecond * 1000; ; }
00123 
00124         enum HIDDeviceMessageType
00125         {
00126             HIDDeviceMessage_DeviceAdded    = 0,
00127             HIDDeviceMessage_DeviceRemoved  = 1
00128         };
00129 
00130         virtual void OnDeviceMessage(HIDDeviceMessageType messageType) 
00131         { OVR_UNUSED1(messageType); }
00132     };
00133 
00134     void SetHandler(HIDHandler* handler)
00135     { Handler = handler; }
00136 
00137 protected:
00138     HIDHandler* Handler;
00139 };
00140 
00141 } // namespace OVR
00142 
00143 #endif


oculus_sdk
Author(s):
autogenerated on Fri Aug 28 2015 11:53:11