OVR_SensorImpl.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   OVR_SensorImpl.h
00004 Content     :   Sensor device specific implementation.
00005 Created     :   March 7, 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_SensorImpl_h
00017 #define OVR_SensorImpl_h
00018 
00019 #include "OVR_HIDDeviceImpl.h"
00020 
00021 namespace OVR {
00022     
00023 struct TrackerMessage;
00024 class ExternalVisitor;
00025 
00026 //-------------------------------------------------------------------------------------
00027 // SensorDeviceFactory enumerates Oculus Sensor devices.
00028 class SensorDeviceFactory : public DeviceFactory
00029 {
00030 public:
00031     static SensorDeviceFactory Instance;
00032 
00033     // Enumerates devices, creating and destroying relevant objects in manager.
00034     virtual void EnumerateDevices(EnumerateVisitor& visitor);
00035 
00036     virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId) const;
00037     virtual bool DetectHIDDevice(DeviceManager* pdevMgr, const HIDDeviceDesc& desc);
00038 protected:
00039     DeviceManager* getManager() const { return (DeviceManager*) pManager; }   
00040 };
00041 
00042 
00043 // Describes a single a Oculus Sensor device and supports creating its instance.
00044 class SensorDeviceCreateDesc : public HIDDeviceCreateDesc
00045 {
00046 public:
00047     SensorDeviceCreateDesc(DeviceFactory* factory, const HIDDeviceDesc& hidDesc)
00048         : HIDDeviceCreateDesc(factory, Device_Sensor, hidDesc) { }
00049     
00050     virtual DeviceCreateDesc* Clone() const
00051     {
00052         return new SensorDeviceCreateDesc(*this);
00053     }
00054 
00055     virtual DeviceBase* NewDeviceInstance();
00056 
00057     virtual MatchResult MatchDevice(const DeviceCreateDesc& other,
00058                                     DeviceCreateDesc**) const
00059     {
00060         if ((other.Type == Device_Sensor) && (pFactory == other.pFactory))
00061         {
00062             const SensorDeviceCreateDesc& s2 = (const SensorDeviceCreateDesc&) other;
00063             if (MatchHIDDevice(s2.HIDDesc))
00064                 return Match_Found;
00065         }
00066         return Match_None;
00067     }
00068 
00069     virtual bool MatchHIDDevice(const HIDDeviceDesc& hidDesc) const
00070     {
00071         // should paths comparison be case insensitive?
00072         return ((HIDDesc.Path.CompareNoCase(hidDesc.Path) == 0) &&
00073                 (HIDDesc.SerialNumber == hidDesc.SerialNumber));
00074     }
00075 
00076     virtual bool        GetDeviceInfo(DeviceInfo* info) const;
00077 };
00078 
00079 
00080 //-------------------------------------------------------------------------------------
00081 // ***** OVR::SensorDisplayInfoImpl
00082 
00083 // DisplayInfo obtained from sensor; these values are used to report distortion
00084 // settings and other coefficients.
00085 // Older SensorDisplayInfo will have all zeros, causing the library to apply hard-coded defaults.
00086 // Currently, only resolutions and sizes are used.
00087 struct SensorDisplayInfoImpl
00088 {
00089     enum  { PacketSize = 56 };
00090     UByte   Buffer[PacketSize];
00091 
00092     enum
00093     {
00094         Mask_BaseFmt    = 0x0f,
00095         Mask_OptionFmts = 0xf0,
00096         Base_None       = 0,
00097         Base_ScreenOnly = 1,
00098         Base_Distortion = 2,
00099     };
00100 
00101     UInt16  CommandId;
00102     UByte   DistortionType;    
00103     UInt16  HResolution, VResolution;
00104     float   HScreenSize, VScreenSize;
00105     float   VCenter;
00106     float   LensSeparation;
00107     float   EyeToScreenDistance[2];
00108     float   DistortionK[6];
00109 
00110     SensorDisplayInfoImpl();
00111 
00112     void Unpack();
00113 };
00114 
00115 
00116 //-------------------------------------------------------------------------------------
00117 // ***** OVR::SensorDeviceImpl
00118 
00119 // Oculus Sensor interface.
00120 
00121 class SensorDeviceImpl : public HIDDeviceImpl<OVR::SensorDevice>
00122 {
00123 public:
00124      SensorDeviceImpl(SensorDeviceCreateDesc* createDesc);
00125     ~SensorDeviceImpl();
00126 
00127 
00128     // DeviceCommaon interface
00129     virtual bool Initialize(DeviceBase* parent);
00130     virtual void Shutdown();
00131     
00132     virtual void SetMessageHandler(MessageHandler* handler);
00133 
00134     // HIDDevice::Notifier interface.
00135     virtual void OnInputReport(UByte* pData, UInt32 length);
00136     virtual UInt64 OnTicks(UInt64 ticksMks);
00137 
00138     // HMD-Mounted sensor has a different coordinate frame.
00139     virtual void SetCoordinateFrame(CoordinateFrame coordframe);    
00140     virtual CoordinateFrame GetCoordinateFrame() const;    
00141 
00142     // SensorDevice interface
00143     virtual bool SetRange(const SensorRange& range, bool waitFlag);
00144     virtual void GetRange(SensorRange* range) const;
00145 
00146     // Sets report rate (in Hz) of MessageBodyFrame messages (delivered through MessageHandler::OnMessage call). 
00147     // Currently supported maximum rate is 1000Hz. If the rate is set to 500 or 333 Hz then OnMessage will be 
00148     // called twice or thrice at the same 'tick'. 
00149     // If the rate is  < 333 then the OnMessage / MessageBodyFrame will be called three
00150     // times for each 'tick': the first call will contain averaged values, the second
00151     // and third calls will provide with most recent two recorded samples.
00152     virtual void        SetReportRate(unsigned rateHz);
00153     // Returns currently set report rate, in Hz. If 0 - error occurred.
00154     // Note, this value may be different from the one provided for SetReportRate. The return
00155     // value will contain the actual rate.
00156     virtual unsigned    GetReportRate() const;
00157 
00158     // Hack to create HMD device from sensor display info.
00159     static void EnumerateHMDFromSensorDisplayInfo(const SensorDisplayInfoImpl& displayInfo, 
00160                                                   DeviceFactory::EnumerateVisitor& visitor);
00161 protected:
00162 
00163     void openDevice();
00164     void closeDeviceOnError();
00165 
00166     Void    setCoordinateFrame(CoordinateFrame coordframe);
00167     bool    setRange(const SensorRange& range);
00168 
00169     Void    setReportRate(unsigned rateHz);
00170 
00171     // Called for decoded messages
00172     void        onTrackerMessage(TrackerMessage* message);
00173 
00174     // Helpers to reduce casting.
00175 /*
00176     SensorDeviceCreateDesc* getCreateDesc() const
00177     { return (SensorDeviceCreateDesc*)pCreateDesc.GetPtr(); }
00178 
00179     HIDDeviceDesc* getHIDDesc() const
00180     { return &getCreateDesc()->HIDDesc; }    
00181 */
00182 
00183     // Set if the sensor is located on the HMD.
00184     // Older prototype firmware doesn't support changing HW coordinates,
00185     // so we track its state.
00186     CoordinateFrame Coordinates;
00187     CoordinateFrame HWCoordinates;
00188     UInt64      NextKeepAliveTicks;
00189 
00190     bool        SequenceValid;
00191     SInt16      LastTimestamp;
00192     UByte       LastSampleCount;
00193     float       LastTemperature;
00194     Vector3f    LastAcceleration;
00195     Vector3f    LastRotationRate;
00196     Vector3f    LastMagneticField;
00197 
00198     // Current sensor range obtained from device. 
00199     SensorRange MaxValidRange;
00200     SensorRange CurrentRange;
00201     
00202     UInt16      OldCommandId;
00203 };
00204 
00205 
00206 } // namespace OVR
00207 
00208 #endif // OVR_SensorImpl_h


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