rev |
line source |
nuclear@1
|
1 /************************************************************************************
|
nuclear@1
|
2
|
nuclear@1
|
3 Filename : OVR_SensorImpl.h
|
nuclear@1
|
4 Content : Sensor device specific implementation.
|
nuclear@1
|
5 Created : March 7, 2013
|
nuclear@1
|
6 Authors : Lee Cooper
|
nuclear@1
|
7
|
nuclear@1
|
8 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
|
nuclear@1
|
9
|
nuclear@1
|
10 Use of this software is subject to the terms of the Oculus license
|
nuclear@1
|
11 agreement provided at the time of installation or download, or which
|
nuclear@1
|
12 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@1
|
13
|
nuclear@1
|
14 *************************************************************************************/
|
nuclear@1
|
15
|
nuclear@1
|
16 #ifndef OVR_SensorImpl_h
|
nuclear@1
|
17 #define OVR_SensorImpl_h
|
nuclear@1
|
18
|
nuclear@1
|
19 #include "OVR_HIDDeviceImpl.h"
|
nuclear@1
|
20
|
nuclear@1
|
21 namespace OVR {
|
nuclear@1
|
22
|
nuclear@1
|
23 struct TrackerMessage;
|
nuclear@1
|
24 class ExternalVisitor;
|
nuclear@1
|
25
|
nuclear@1
|
26 //-------------------------------------------------------------------------------------
|
nuclear@1
|
27 // SensorDeviceFactory enumerates Oculus Sensor devices.
|
nuclear@1
|
28 class SensorDeviceFactory : public DeviceFactory
|
nuclear@1
|
29 {
|
nuclear@1
|
30 public:
|
nuclear@1
|
31 static SensorDeviceFactory Instance;
|
nuclear@1
|
32
|
nuclear@1
|
33 // Enumerates devices, creating and destroying relevant objects in manager.
|
nuclear@1
|
34 virtual void EnumerateDevices(EnumerateVisitor& visitor);
|
nuclear@1
|
35
|
nuclear@1
|
36 virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId) const;
|
nuclear@1
|
37 virtual bool DetectHIDDevice(DeviceManager* pdevMgr, const HIDDeviceDesc& desc);
|
nuclear@1
|
38 protected:
|
nuclear@1
|
39 DeviceManager* getManager() const { return (DeviceManager*) pManager; }
|
nuclear@1
|
40 };
|
nuclear@1
|
41
|
nuclear@1
|
42
|
nuclear@1
|
43 // Describes a single a Oculus Sensor device and supports creating its instance.
|
nuclear@1
|
44 class SensorDeviceCreateDesc : public HIDDeviceCreateDesc
|
nuclear@1
|
45 {
|
nuclear@1
|
46 public:
|
nuclear@1
|
47 SensorDeviceCreateDesc(DeviceFactory* factory, const HIDDeviceDesc& hidDesc)
|
nuclear@1
|
48 : HIDDeviceCreateDesc(factory, Device_Sensor, hidDesc) { }
|
nuclear@1
|
49
|
nuclear@1
|
50 virtual DeviceCreateDesc* Clone() const
|
nuclear@1
|
51 {
|
nuclear@1
|
52 return new SensorDeviceCreateDesc(*this);
|
nuclear@1
|
53 }
|
nuclear@1
|
54
|
nuclear@1
|
55 virtual DeviceBase* NewDeviceInstance();
|
nuclear@1
|
56
|
nuclear@1
|
57 virtual MatchResult MatchDevice(const DeviceCreateDesc& other,
|
nuclear@1
|
58 DeviceCreateDesc**) const
|
nuclear@1
|
59 {
|
nuclear@1
|
60 if ((other.Type == Device_Sensor) && (pFactory == other.pFactory))
|
nuclear@1
|
61 {
|
nuclear@1
|
62 const SensorDeviceCreateDesc& s2 = (const SensorDeviceCreateDesc&) other;
|
nuclear@1
|
63 if (MatchHIDDevice(s2.HIDDesc))
|
nuclear@1
|
64 return Match_Found;
|
nuclear@1
|
65 }
|
nuclear@1
|
66 return Match_None;
|
nuclear@1
|
67 }
|
nuclear@1
|
68
|
nuclear@1
|
69 virtual bool MatchHIDDevice(const HIDDeviceDesc& hidDesc) const
|
nuclear@1
|
70 {
|
nuclear@1
|
71 // should paths comparison be case insensitive?
|
nuclear@1
|
72 return ((HIDDesc.Path.CompareNoCase(hidDesc.Path) == 0) &&
|
nuclear@1
|
73 (HIDDesc.SerialNumber == hidDesc.SerialNumber));
|
nuclear@1
|
74 }
|
nuclear@1
|
75
|
nuclear@1
|
76 virtual bool GetDeviceInfo(DeviceInfo* info) const;
|
nuclear@1
|
77 };
|
nuclear@1
|
78
|
nuclear@1
|
79
|
nuclear@1
|
80 //-------------------------------------------------------------------------------------
|
nuclear@1
|
81 // ***** OVR::SensorDisplayInfoImpl
|
nuclear@1
|
82
|
nuclear@1
|
83 // DisplayInfo obtained from sensor; these values are used to report distortion
|
nuclear@1
|
84 // settings and other coefficients.
|
nuclear@1
|
85 // Older SensorDisplayInfo will have all zeros, causing the library to apply hard-coded defaults.
|
nuclear@1
|
86 // Currently, only resolutions and sizes are used.
|
nuclear@1
|
87 struct SensorDisplayInfoImpl
|
nuclear@1
|
88 {
|
nuclear@1
|
89 enum { PacketSize = 56 };
|
nuclear@1
|
90 UByte Buffer[PacketSize];
|
nuclear@1
|
91
|
nuclear@1
|
92 enum
|
nuclear@1
|
93 {
|
nuclear@1
|
94 Mask_BaseFmt = 0x0f,
|
nuclear@1
|
95 Mask_OptionFmts = 0xf0,
|
nuclear@1
|
96 Base_None = 0,
|
nuclear@1
|
97 Base_ScreenOnly = 1,
|
nuclear@1
|
98 Base_Distortion = 2,
|
nuclear@1
|
99 };
|
nuclear@1
|
100
|
nuclear@1
|
101 UInt16 CommandId;
|
nuclear@1
|
102 UByte DistortionType;
|
nuclear@1
|
103 UInt16 HResolution, VResolution;
|
nuclear@1
|
104 float HScreenSize, VScreenSize;
|
nuclear@1
|
105 float VCenter;
|
nuclear@1
|
106 float LensSeparation;
|
nuclear@1
|
107 float EyeToScreenDistance[2];
|
nuclear@1
|
108 float DistortionK[6];
|
nuclear@1
|
109
|
nuclear@1
|
110 SensorDisplayInfoImpl();
|
nuclear@1
|
111
|
nuclear@1
|
112 void Unpack();
|
nuclear@1
|
113 };
|
nuclear@1
|
114
|
nuclear@1
|
115
|
nuclear@1
|
116 //-------------------------------------------------------------------------------------
|
nuclear@1
|
117 // ***** OVR::SensorDeviceImpl
|
nuclear@1
|
118
|
nuclear@1
|
119 // Oculus Sensor interface.
|
nuclear@1
|
120
|
nuclear@1
|
121 class SensorDeviceImpl : public HIDDeviceImpl<OVR::SensorDevice>
|
nuclear@1
|
122 {
|
nuclear@1
|
123 public:
|
nuclear@1
|
124 SensorDeviceImpl(SensorDeviceCreateDesc* createDesc);
|
nuclear@1
|
125 ~SensorDeviceImpl();
|
nuclear@1
|
126
|
nuclear@1
|
127
|
nuclear@1
|
128 // DeviceCommaon interface
|
nuclear@1
|
129 virtual bool Initialize(DeviceBase* parent);
|
nuclear@1
|
130 virtual void Shutdown();
|
nuclear@1
|
131
|
nuclear@1
|
132 virtual void SetMessageHandler(MessageHandler* handler);
|
nuclear@1
|
133
|
nuclear@1
|
134 // HIDDevice::Notifier interface.
|
nuclear@1
|
135 virtual void OnInputReport(UByte* pData, UInt32 length);
|
nuclear@1
|
136 virtual UInt64 OnTicks(UInt64 ticksMks);
|
nuclear@1
|
137
|
nuclear@1
|
138 // HMD-Mounted sensor has a different coordinate frame.
|
nuclear@1
|
139 virtual void SetCoordinateFrame(CoordinateFrame coordframe);
|
nuclear@1
|
140 virtual CoordinateFrame GetCoordinateFrame() const;
|
nuclear@1
|
141
|
nuclear@1
|
142 // SensorDevice interface
|
nuclear@1
|
143 virtual bool SetRange(const SensorRange& range, bool waitFlag);
|
nuclear@1
|
144 virtual void GetRange(SensorRange* range) const;
|
nuclear@1
|
145
|
nuclear@1
|
146 // Sets report rate (in Hz) of MessageBodyFrame messages (delivered through MessageHandler::OnMessage call).
|
nuclear@1
|
147 // Currently supported maximum rate is 1000Hz. If the rate is set to 500 or 333 Hz then OnMessage will be
|
nuclear@1
|
148 // called twice or thrice at the same 'tick'.
|
nuclear@1
|
149 // If the rate is < 333 then the OnMessage / MessageBodyFrame will be called three
|
nuclear@1
|
150 // times for each 'tick': the first call will contain averaged values, the second
|
nuclear@1
|
151 // and third calls will provide with most recent two recorded samples.
|
nuclear@1
|
152 virtual void SetReportRate(unsigned rateHz);
|
nuclear@1
|
153 // Returns currently set report rate, in Hz. If 0 - error occurred.
|
nuclear@1
|
154 // Note, this value may be different from the one provided for SetReportRate. The return
|
nuclear@1
|
155 // value will contain the actual rate.
|
nuclear@1
|
156 virtual unsigned GetReportRate() const;
|
nuclear@1
|
157
|
nuclear@1
|
158 // Hack to create HMD device from sensor display info.
|
nuclear@1
|
159 static void EnumerateHMDFromSensorDisplayInfo(const SensorDisplayInfoImpl& displayInfo,
|
nuclear@1
|
160 DeviceFactory::EnumerateVisitor& visitor);
|
nuclear@1
|
161 protected:
|
nuclear@1
|
162
|
nuclear@1
|
163 void openDevice();
|
nuclear@1
|
164 void closeDeviceOnError();
|
nuclear@1
|
165
|
nuclear@1
|
166 Void setCoordinateFrame(CoordinateFrame coordframe);
|
nuclear@1
|
167 bool setRange(const SensorRange& range);
|
nuclear@1
|
168
|
nuclear@1
|
169 Void setReportRate(unsigned rateHz);
|
nuclear@1
|
170
|
nuclear@1
|
171 // Called for decoded messages
|
nuclear@1
|
172 void onTrackerMessage(TrackerMessage* message);
|
nuclear@1
|
173
|
nuclear@1
|
174 // Helpers to reduce casting.
|
nuclear@1
|
175 /*
|
nuclear@1
|
176 SensorDeviceCreateDesc* getCreateDesc() const
|
nuclear@1
|
177 { return (SensorDeviceCreateDesc*)pCreateDesc.GetPtr(); }
|
nuclear@1
|
178
|
nuclear@1
|
179 HIDDeviceDesc* getHIDDesc() const
|
nuclear@1
|
180 { return &getCreateDesc()->HIDDesc; }
|
nuclear@1
|
181 */
|
nuclear@1
|
182
|
nuclear@1
|
183 // Set if the sensor is located on the HMD.
|
nuclear@1
|
184 // Older prototype firmware doesn't support changing HW coordinates,
|
nuclear@1
|
185 // so we track its state.
|
nuclear@1
|
186 CoordinateFrame Coordinates;
|
nuclear@1
|
187 CoordinateFrame HWCoordinates;
|
nuclear@1
|
188 UInt64 NextKeepAliveTicks;
|
nuclear@1
|
189
|
nuclear@1
|
190 bool SequenceValid;
|
nuclear@1
|
191 SInt16 LastTimestamp;
|
nuclear@1
|
192 UByte LastSampleCount;
|
nuclear@1
|
193 float LastTemperature;
|
nuclear@1
|
194 Vector3f LastAcceleration;
|
nuclear@1
|
195 Vector3f LastRotationRate;
|
nuclear@1
|
196 Vector3f LastMagneticField;
|
nuclear@1
|
197
|
nuclear@1
|
198 // Current sensor range obtained from device.
|
nuclear@1
|
199 SensorRange MaxValidRange;
|
nuclear@1
|
200 SensorRange CurrentRange;
|
nuclear@1
|
201
|
nuclear@1
|
202 UInt16 OldCommandId;
|
nuclear@1
|
203 };
|
nuclear@1
|
204
|
nuclear@1
|
205
|
nuclear@1
|
206 } // namespace OVR
|
nuclear@1
|
207
|
nuclear@1
|
208 #endif // OVR_SensorImpl_h
|