Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
00028 class SensorDeviceFactory : public DeviceFactory
00029 {
00030 public:
00031 static SensorDeviceFactory Instance;
00032
00033
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
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
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
00082
00083
00084
00085
00086
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
00118
00119
00120
00121 class SensorDeviceImpl : public HIDDeviceImpl<OVR::SensorDevice>
00122 {
00123 public:
00124 SensorDeviceImpl(SensorDeviceCreateDesc* createDesc);
00125 ~SensorDeviceImpl();
00126
00127
00128
00129 virtual bool Initialize(DeviceBase* parent);
00130 virtual void Shutdown();
00131
00132 virtual void SetMessageHandler(MessageHandler* handler);
00133
00134
00135 virtual void OnInputReport(UByte* pData, UInt32 length);
00136 virtual UInt64 OnTicks(UInt64 ticksMks);
00137
00138
00139 virtual void SetCoordinateFrame(CoordinateFrame coordframe);
00140 virtual CoordinateFrame GetCoordinateFrame() const;
00141
00142
00143 virtual bool SetRange(const SensorRange& range, bool waitFlag);
00144 virtual void GetRange(SensorRange* range) const;
00145
00146
00147
00148
00149
00150
00151
00152 virtual void SetReportRate(unsigned rateHz);
00153
00154
00155
00156 virtual unsigned GetReportRate() const;
00157
00158
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
00172 void onTrackerMessage(TrackerMessage* message);
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
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
00199 SensorRange MaxValidRange;
00200 SensorRange CurrentRange;
00201
00202 UInt16 OldCommandId;
00203 };
00204
00205
00206 }
00207
00208 #endif // OVR_SensorImpl_h