Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_Device.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 PublicHeader: OVR.h
4 Filename : OVR_Device.h
5 Content : Definition of HMD-related Device interfaces
6 Created : September 21, 2012
7 Authors : Michael Antonov
8 
9 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
10 
11 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
15 
16 You may obtain a copy of the License at
17 
18 http://www.oculusvr.com/licenses/LICENSE-3.1
19 
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
25 
26 *************************************************************************************/
27 
28 #ifndef OVR_Device_h
29 #define OVR_Device_h
30 
31 #include "OVR_DeviceConstants.h"
32 #include "OVR_DeviceHandle.h"
33 #include "OVR_DeviceMessages.h"
34 #include "OVR_HIDDeviceBase.h"
35 
36 #include "Kernel/OVR_Atomic.h"
37 #include "Kernel/OVR_RefCount.h"
38 #include "Kernel/OVR_String.h"
39 
40 
41 namespace OVR {
42 
43 // Declared externally
44 class Profile;
45 class ProfileManager; // << Should be renamed for consistency
46 
47 // Forward declarations
48 class SensorDevice;
49 class DeviceCommon;
50 class DeviceManager;
51 
52 // MessageHandler is a base class from which users derive to receive messages,
53 // its OnMessage handler will be called for messages once it is installed on
54 // a device. Same message handler can be installed on multiple devices.
56 {
57  friend class MessageHandlerImpl;
58 public:
60  virtual ~MessageHandler();
61 
62  // Returns 'true' if handler is currently installed on any devices.
63  bool IsHandlerInstalled() const;
64 
65  // Should be called from derived class destructor to avoid handler
66  // being called after it exits.
68 
69  // Returns a pointer to the internal lock object that is locked by a
70  // background thread while OnMessage() is called.
71  // This lock guaranteed to survive until ~MessageHandler.
72  Lock* GetHandlerLock() const;
73 
74 
75  virtual void OnMessage(const Message&) { }
76 
77  // Determines if handler supports a specific message type. Can
78  // be used to filter out entire message groups. The result
79  // returned by this function shouldn't change after handler creation.
80  virtual bool SupportsMessageType(MessageType) const { return true; }
81 
82 private:
84 };
85 
86 
87 //-------------------------------------------------------------------------------------
88 // ***** DeviceBase
89 
90 // DeviceBase is the base class for all OVR Devices. It provides the following basic
91 // functionality:
92 // - Reports device type, manager, and associated parent (if any).
93 // - Supports installable message handlers, which are notified of device events.
94 // - Device objects are created through DeviceHandle::CreateDevice or more commonly
95 // through DeviceEnumerator<>::CreateDevice.
96 // - Created devices are reference counted, starting with RefCount of 1.
97 // - Device is resources are cleaned up when it is Released, although its handles
98 // may survive longer if referenced.
99 
101 {
102  friend class DeviceHandle;
103  friend class DeviceManagerImpl;
104 public:
105 
106  // Enumerating DeviceBase enumerates all devices.
108 
109  virtual ~DeviceBase() { }
110  virtual void AddRef();
111  virtual void Release();
112 
113  virtual DeviceBase* GetParent() const;
114  virtual DeviceManager* GetManager() const;
115 
116  virtual void AddMessageHandler(MessageHandler* handler);
117 
118  virtual DeviceType GetType() const;
119  virtual bool GetDeviceInfo(DeviceInfo* info) const;
120 
121  // Returns true if device is connected and usable
122  virtual bool IsConnected();
123 
124  // returns the MessageHandler's lock
125  Lock* GetHandlerLock() const;
126 protected:
127  // Internal
128  virtual DeviceCommon* getDeviceCommon() const = 0;
129 };
130 
131 
132 //-------------------------------------------------------------------------------------
133 // ***** DeviceInfo
134 
135 // DeviceInfo describes a device and its capabilities, obtained by calling
136 // GetDeviceInfo. This base class only contains device-independent functionality;
137 // users will normally use a derived HMDInfo or SensorInfo classes for more
138 // extensive device info.
139 
141 {
142 public:
144  {}
145 
146  // Type of device for which DeviceInfo is intended.
147  // This will be set to Device_HMD for HMDInfo structure, note that this may be
148  // different form the actual device type since (Device_None) is valid.
150  // Type of device this describes. This must be the same as InfoClassType when
151  // InfoClassType != Device_None.
153  // Name string describing the product: "Oculus Rift DK1", etc.
156  unsigned Version;
157 
158 protected:
159  DeviceInfo(DeviceType type) : InfoClassType(type), Type(type), Version(0)
160  {}
161  void operator = (const DeviceInfo&) { OVR_ASSERT(0); } // Assignment not allowed.
162 };
163 
164 
165 //-------------------------------------------------------------------------------------
166 // DeviceEnumerationArgs provides device enumeration argumenrs for DeviceManager::EnumerateDevicesEx.
168 {
169 public:
170  DeviceEnumerationArgs(DeviceType enumType, bool availableOnly)
171  : EnumType(enumType), AvailableOnly(availableOnly)
172  { }
173 
174  // Helper; returns true if args match our enumeration criteria.
175  bool MatchRule(DeviceType type, bool available) const
176  {
177  return ((EnumType == type) || (EnumType == Device_All)) &&
178  (available || !AvailableOnly);
179  }
180 
181 protected:
184 };
185 
186 
187 // DeviceEnumerator<> is used to enumerate and create devices of specified class,
188 // it is returned by calling MeviceManager::EnumerateDevices. Initially, the enumerator will
189 // refer to the first device of specified type. Additional devices can be accessed by
190 // calling Next().
191 
192 template<class T = DeviceBase>
194 {
195  friend class DeviceManager;
196  friend class DeviceManagerImpl;
197 public:
199  : DeviceHandle(), EnumArgs(Device_None, true) { }
200 
201  // Next advances enumeration to the next device that first criteria.
202  // Returns false if no more devices exist that match enumeration criteria.
203  bool Next() { return enumerateNext(EnumArgs); }
204 
205  // Creates an instance of the device referenced by enumerator; returns null
206  // if enumerator does not refer to a valid device or device is unavailable.
207  // If device was already created, the same object with incremented ref-count is returned.
208  T* CreateDevice() { return static_cast<T*>(DeviceHandle::CreateDevice()); }
209 
210 protected:
212  : DeviceHandle(dev), EnumArgs(args)
213  { }
214 
216 };
217 
218 //-------------------------------------------------------------------------------------
219 // ***** DeviceManager
220 
221 // DeviceManager maintains and provides access to devices supported by OVR, such as
222 // HMDs and sensors. A single instance of DeviceManager is normally created at
223 // program startup, allowing devices to be enumerated and created. DeviceManager is
224 // reference counted and is AddRefed by its created child devices, causing it to
225 // always be the last object that is released.
226 //
227 // Install MessageHandler on DeviceManager to detect when devices are inserted or removed.
228 //
229 // The following code will create the manager and its first available HMDDevice,
230 // and then release it when not needed:
231 //
232 // DeviceManager* manager = DeviceManager::Create();
233 // HMDDevice* hmd = manager->EnumerateDevices<HMDDevice>().CreateDevice();
234 //
235 // if (hmd) hmd->Release();
236 // if (manager) manager->Release();
237 
238 
239 class DeviceManager : public DeviceBase
240 {
241 public:
242 
244  { }
245 
246  // DeviceBase implementation.
247  virtual DeviceType GetType() const { return Device_Manager; }
248  virtual DeviceManager* GetManager() const { return const_cast<DeviceManager*>(this); }
249 
250  // Every DeviceManager has an associated profile manager, which us used to store
251  // user settings that may affect device behavior.
252  virtual ProfileManager* GetProfileManager() const = 0;
253 
254 
255  // EnumerateDevices enumerates all of the available devices of the specified class,
256  // returning an enumerator that references the first device. An empty enumerator is
257  // returned if no devices are available. The following APIs are exposed through
258  // DeviceEnumerator:
259  // DeviceEnumerator::GetType() - Check device type. Returns Device_None
260  // if no device was found/pointed to.
261  // DeviceEnumerator::GetDeviceInfo() - Get more information on device.
262  // DeviceEnumerator::CreateDevice() - Create an instance of device.
263  // DeviceEnumerator::Next() - Move onto next device.
264  template<class D>
265  DeviceEnumerator<D> EnumerateDevices(bool availableOnly = true)
266  {
267  // TBD: A cleaner (but less efficient) alternative is though enumeratorFromHandle.
268  DeviceEnumerator<> e = EnumerateDevicesEx(DeviceEnumerationArgs((DeviceType)D::EnumDeviceType, availableOnly));
269  return *reinterpret_cast<DeviceEnumerator<D>*>(&e);
270  }
271 
272  // EnumerateDevicesEx provides internal implementation for device enumeration, enumerating
273  // devices based on dynamically specified DeviceType in DeviceEnumerationArgs.
274  // End users should call DeumerateDevices<>() instead.
276 
277  // Creates a new DeviceManager. Only one instance of DeviceManager should be created at a time.
278  static DeviceManager* Create();
279 
280  // Static constant for this device type, used in template cast type checks.
282 
283 
284 
285  // Adds a device (DeviceCreateDesc*) into Devices. Returns NULL,
286  // if unsuccessful or device is already in the list.
287  virtual Ptr<DeviceCreateDesc> AddDevice_NeedsLock(const DeviceCreateDesc& createDesc) = 0;
288 
289 protected:
291  { return DeviceEnumerator<>(h, args); }
292 
293  DeviceManager* getThis() { return this; }
294 };
295 
296 
297 
298 //-------------------------------------------------------------------------------------
299 // ***** HMDInfo
300 
301 // This structure describes various aspects of the HMD allowing us to configure rendering.
302 //
303 // Currently included data:
304 // - Physical screen dimensions, resolution, and eye distances.
305 // (some of these will be configurable with a tool in the future).
306 // These arguments allow us to properly setup projection across HMDs.
307 // - DisplayDeviceName for identifying HMD screen; system-specific interpretation.
308 //
309 // TBD:
310 // - Power on/ off?
311 // - Sensor rates and capabilities
312 // - Distortion radius/variables
313 // - Screen update frequency
314 // - Distortion needed flag
315 // - Update modes:
316 // Set update mode: Stereo (both sides together), mono (same in both eyes),
317 // Alternating, Alternating scan-lines.
318 
319 class HMDInfo : public DeviceInfo
320 {
321 public:
322  // Characteristics of the HMD screen and enclosure
329 
330  // Timing & shutter data. All values in seconds.
331  struct ShutterInfo
332  {
334  float VsyncToNextVsync; // 1/framerate
335  float VsyncToFirstScanline; // for global shutter, vsync->shutter open.
336  float FirstScanlineToLastScanline; // for global shutter, will be zero.
337  float PixelSettleTime; // estimated.
338  float PixelPersistence; // Full persistence = 1/framerate.
339  } Shutter;
340 
341  // Desktop coordinate position of the screen (can be negative; may not be present on all platforms)
342  int DesktopX;
343  int DesktopY;
344 
345  // Windows:
346  // "\\\\.\\DISPLAY3", etc. Can be used in EnumDisplaySettings/CreateDC.
348 
349  // MacOS:
351 
352 
353  // Constructor initializes all values to 0s.
354  // To create a "virtualized" HMDInfo, use CreateDebugHMDInfo instead.
359  ScreenSizeInMeters(0.0f),
360  ScreenGapSizeInMeters(0.0f),
363  DisplayId(0)
364  {
365  DesktopX = 0;
366  DesktopY = 0;
367  DisplayDeviceName[0] = 0;
369  Shutter.VsyncToNextVsync = 0.0f;
372  Shutter.PixelSettleTime = 0.0f;
373  Shutter.PixelPersistence = 0.0f;
374  }
375 
376  // Operator = copies local fields only (base class must be correct already)
377  void operator = (const HMDInfo& src)
378  {
379  HmdType = src.HmdType;
385  DesktopX = src.DesktopX;
386  DesktopY = src.DesktopY;
387  Shutter = src.Shutter;
389 
390  DisplayId = src.DisplayId;
391  }
392 
393  bool IsSameDisplay(const HMDInfo& o) const
394  {
395  return DisplayId == o.DisplayId &&
397  o.DisplayDeviceName) == 0;
398  }
399 
400 };
401 
402 
403 // HMDDevice represents an Oculus HMD device unit. An instance of this class
404 // is typically created from the DeviceManager.
405 // After HMD device is created, we its sensor data can be obtained by
406 // first creating a Sensor object and then.
407 
408 // TBD:
409 // - Configure Sensor
410 // - APIs to set On-Screen message, other states?
411 
412 class HMDDevice : public DeviceBase
413 {
414 public:
416  { }
417 
418  // Static constant for this device type, used in template cast type checks.
420 
421  virtual DeviceType GetType() const { return Device_HMD; }
422 
423  // Creates a sensor associated with this HMD.
424  virtual SensorDevice* GetSensor() = 0;
425 
426 
427  // Requests the currently used profile. This profile affects the
428  // settings reported by HMDInfo.
429  virtual Profile* GetProfile() = 0;
430  // Obtains the currently used profile name. This is initialized to the default
431  // profile name, if any; it can then be changed per-device by SetProfileName.
432  virtual const char* GetProfileName() = 0;
433  // Sets the profile user name, changing the data returned by GetProfileInfo.
434  virtual bool SetProfileName(const char* name) = 0;
435 
436 
437  // Disconnects from real HMD device. This HMDDevice remains as 'fake' HMD.
438  // SensorDevice ptr is used to restore the 'fake' HMD (can be NULL).
440 
441  // Returns 'true' if HMD device is a 'fake' HMD (was created this way or
442  // 'Disconnect' method was called).
443  bool IsDisconnected() const;
444 };
445 
446 
447 //-------------------------------------------------------------------------------------
448 // ***** SensorRange & SensorInfo
449 
450 // SensorRange specifies maximum value ranges that SensorDevice hardware is configured
451 // to detect. Although this range doesn't affect the scale of MessageBodyFrame values,
452 // physical motions whose positive or negative magnitude is outside the specified range
453 // may get clamped or misreported. Setting lower values may result in higher precision
454 // tracking.
456 {
457  SensorRange(float maxAcceleration = 0.0f, float maxRotationRate = 0.0f,
458  float maxMagneticField = 0.0f)
459  : MaxAcceleration(maxAcceleration), MaxRotationRate(maxRotationRate),
460  MaxMagneticField(maxMagneticField)
461  { }
462 
463  // Maximum detected acceleration in m/s^2. Up to 8*G equivalent support guaranteed,
464  // where G is ~9.81 m/s^2.
465  // Oculus DK1 HW has thresholds near: 2, 4 (default), 8, 16 G.
467  // Maximum detected angular velocity in rad/s. Up to 8*Pi support guaranteed.
468  // Oculus DK1 HW thresholds near: 1, 2, 4, 8 Pi (default).
470  // Maximum detectable Magnetic field strength in Gauss. Up to 2.5 Gauss support guaranteed.
471  // Oculus DK1 HW thresholds near: 0.88, 1.3, 1.9, 2.5 gauss.
473 };
474 
475 // SensorInfo describes capabilities of the sensor device.
476 class SensorInfo : public DeviceInfo
477 {
478 public:
480  {
481  }
482 
483  // HID Vendor and ProductId of the device.
486  // MaxRanges report maximum sensor range values supported by HW.
488  // Sensor (and display) serial number.
490 
491 private:
492  void operator = (const SensorInfo&) { OVR_ASSERT(0); } // Assignment not allowed.
493 };
494 
495 
496 
498 // Serial Number feature report. (DK1)
500 {
501  static const int SERIAL_NUMBER_SIZE = 12; // Serial Number size = 12 bytes. (Refer 'Tracker Firmware Specification Section 4.9, Pg 18)
502 
504  : CommandId(0)
505  {
507  }
508 
509  SerialReport(UInt16 commandId,
511  : CommandId(commandId)
512  {
513  for (int i=0; i < SERIAL_NUMBER_SIZE; i++)
514  {
515  SerialNumberValue[i] = SNo[i];
516  }
517  }
518 
520  UByte SerialNumberValue[SERIAL_NUMBER_SIZE]; // See 'Tracker Firmware Specification' document for
521  // a description of Serial Report.
522 };
523 
524 
526 //Added Serial Report Implementation.
527 
529 {
530  enum { PacketSize = 15 };
532 
534 
536  {
537  memset(Buffer, 0, sizeof(Buffer));
538  Buffer[0] = 10;
539  }
540 
541  SerialImpl(const SerialReport& settings)
542  :Settings(settings)
543  {
544  Pack();
545  }
546 
547  void Pack()
548  {
549  Buffer[0] = 10;
551  for (int i = 0; i < Settings.SERIAL_NUMBER_SIZE; ++i)
552  Buffer[3 + i] = Settings.SerialNumberValue[i];
553  }
554 
555  void Unpack()
556  {
558  for (int i = 0; i < Settings.SERIAL_NUMBER_SIZE; ++i)
559  Settings.SerialNumberValue[i] = Buffer[3 + i];
560  }
561 
562 };
563 
564 
565 // Tracking settings (DK2).
567 {
569  : CommandId(0), Pattern(0),
570  Enable(0), Autoincrement(0), UseCarrier(0),
571  SyncInput(0), VsyncLock(0), CustomPattern(0),
573  VsyncOffset(0), DutyCycle(0)
574  {}
575 
576  TrackingReport( UInt16 commandId,
577  UByte pattern,
578  bool enable,
579  bool autoincrement,
580  bool useCarrier,
581  bool syncInput,
582  bool vsyncLock,
583  bool customPattern,
584  UInt16 exposureLength,
585  UInt16 frameInterval,
586  UInt16 vsyncOffset,
587  UByte dutyCycle)
588  : CommandId(commandId), Pattern(pattern),
589  Enable(enable), Autoincrement(autoincrement), UseCarrier(useCarrier),
590  SyncInput(syncInput), VsyncLock(vsyncLock), CustomPattern(customPattern),
591  ExposureLength(exposureLength), FrameInterval(frameInterval),
592  VsyncOffset(vsyncOffset), DutyCycle(dutyCycle)
593  { }
594 
596  UByte Pattern; // Tracking LED pattern index.
597  bool Enable; // Enables the tracking LED exposure and updating.
598  bool Autoincrement; // Autoincrement pattern after each exposure.
599  bool UseCarrier; // Modulate tracking LEDs at 85kHz.
600  bool SyncInput; // Trigger LED exposure from wired sync signal.
601  bool VsyncLock; // Trigger LED exposure from panel Vsync.
602  bool CustomPattern; // Use custom LED sequence.
603  UInt16 ExposureLength; // Tracking LED illumination (and exposure) length in microseconds.
604  UInt16 FrameInterval; // LED exposure interval in microseconds when in
605  // 'internal timer' mode (when SyncInput = VsyncLock = false).
606  UInt16 VsyncOffset; // Exposure offset in microseconds from vsync when in
607  // 'vsync lock' mode (when VsyncLock = true).
608  UByte DutyCycle; // Duty cycle of 85kHz modulation when in 'use carrier' mode
609  // (when UseCarrier = true). 128 = 50% duty cycle.
610 };
611 
612 // Display settings (DK2).
614 {
616  {
617  // These are not yet defined.
619  };
620 
622  {
623  // These are not yet defined.
625  };
626 
628  : CommandId(0), Brightness(0),
631  ReadPixel(0), DirectPentile(0),
633  PixelSettle(0), TotalRows(0)
634  {}
635 
636  DisplayReport( UInt16 commandId,
637  UByte brightness,
638  ShutterTypeEnum shutterType,
639  CurrentLimitEnum currentLimit,
640  bool useRolling,
641  bool reverseRolling,
642  bool highBrightness,
643  bool selfRefresh,
644  bool readPixel,
645  bool directPentile,
646  UInt16 persistence,
647  UInt16 lightingOffset,
648  UInt16 pixelSettle,
649  UInt16 totalRows)
650  : CommandId(commandId), Brightness(brightness),
651  ShutterType(shutterType), CurrentLimit(currentLimit), UseRolling(useRolling),
652  ReverseRolling(reverseRolling), HighBrightness(highBrightness), SelfRefresh(selfRefresh),
653  ReadPixel(readPixel), DirectPentile(directPentile),
654  Persistence(persistence), LightingOffset(lightingOffset),
655  PixelSettle(pixelSettle), TotalRows(totalRows)
656  { }
657 
659  UByte Brightness; // See 'DK2 Firmware Specification' document for a description of
660  ShutterTypeEnum ShutterType; // display settings.
666  bool ReadPixel;
672 };
673 
674 // MagCalibration matrix (DK2).
676 {
678  : CommandId(0), Version(0), Calibration()
679  {}
680 
682  UByte version,
683  const Matrix4f& calibration)
684  : CommandId(commandId), Version(version), Calibration(calibration)
685  { }
686 
688  UByte Version; // Version of the calibration procedure used to generate the calibration matrix.
689  Matrix4f Calibration; // Calibration matrix. Note only the first three rows are used by the feature report.
690 };
691 
692 // PositionCalibration values (DK2).
693 // - Sensor interface versions before 5 do not support Normal and Rotation.
695 {
697  {
700  };
701 
703  : CommandId(0), Version(0),
704  Position(0), Normal(0), Angle(0),
706  {}
707 
709  UByte version,
710  const Vector3d& position,
711  const Vector3d& normal,
712  double rotation,
713  UInt16 positionIndex,
714  UInt16 numPositions,
715  PositionTypeEnum positionType)
716  : CommandId(commandId), Version(version),
717  Position(position), Normal(normal), Angle(rotation),
718  PositionIndex(positionIndex), NumPositions(numPositions), PositionType(positionType)
719  {
720  }
721 
723  UByte Version; // The version of the calibration procedure used to generate the stored positions.
724  Vector3d Position; // Position of the LED or inertial tracker in meters. This is relative to the
725  // center of the emitter plane of the display at nominal focus.
726  Vector3d Normal; // Normal of the LED or inertial tracker. This is a signed integer in
727  // meters. The normal is relative to the position.
728  double Angle; // The rotation about the normal. This is in radians.
729  UInt16 PositionIndex; // The current position being read or written to. Autoincrements on reads, gets set
730  // to the written value on writes.
731  UInt16 NumPositions; // The read-only number of items with positions stored. The last position is that of
732  // the inertial tracker, all others are LED positions.
733  PositionTypeEnum PositionType; // The type of the item which has its position reported in the current report
734 };
735 
736 // CustomPattern values (DK2).
738 {
740  : CommandId(0), SequenceLength(0), Sequence(0),
741  LEDIndex(0), NumLEDs(0)
742  {}
743 
745  UByte sequenceLength,
746  UInt32 sequence,
747  UInt16 ledIndex,
748  UInt16 numLEDs)
749  : CommandId(commandId), SequenceLength(sequenceLength), Sequence(sequence),
750  LEDIndex(ledIndex), NumLEDs(numLEDs)
751  { }
752 
754  UByte SequenceLength; // See 'DK2 Firmware Specification' document for a description of
755  UInt32 Sequence; // LED custom patterns.
758 };
759 
760 // KeepAliveMux settings (DK2).
762 {
764  : CommandId(0), INReport(0), Interval(0)
765  {}
766 
768  UByte inReport,
769  UInt16 interval)
770  : CommandId(commandId), INReport(inReport), Interval(interval)
771  { }
772 
774  UByte INReport; // Requested IN report type (1 = DK1, 11 = DK2).
775  UInt16 Interval; // Keep alive period in milliseconds.
776 };
777 
778 // Manufacturing test result (DK2).
780 {
782  : CommandId(0), NumStages(0), Stage(0),
784  {}
785 
787  UByte numStages,
788  UByte stage,
789  UByte version,
790  UInt16 stageLocation,
791  UInt32 stageTime,
792  UInt32 result)
793  : CommandId(commandId), NumStages(numStages), Stage(stage),
794  StageVersion(version), StageLocation(stageLocation), StageTime(stageTime), Result(result)
795  { }
796 
798  UByte NumStages; // See 'DK2 Firmware Specification' document for a description of
799  UByte Stage; // manufacturing test results.
804 };
805 
806 // UUID (DK2).
808 {
809  static const int UUID_SIZE = 20;
810 
812  : CommandId(0)
813  {
814  memset(UUIDValue, 0, sizeof(UUIDValue));
815  }
816 
817  UUIDReport( UInt16 commandId,
818  UByte uuid[UUID_SIZE])
819  : CommandId(commandId)
820  {
821  for (int i=0; i<UUID_SIZE; i++)
822  {
823  UUIDValue[i] = uuid[i];
824  }
825  }
826 
828  UByte UUIDValue[UUID_SIZE]; // See 'DK2 Firmware Specification' document for
829  // a description of UUID.
830 };
831 
832 // Lens Distortion (DK2).
834 {
836  : CommandId(0),
837  NumDistortions(0),
838  DistortionIndex(0),
839  Bitmask(0),
840  LensType(0),
841  Version(0),
842  EyeRelief(0),
843  MaxR(0),
845  {}
846 
848  UByte numDistortions,
849  UByte distortionIndex,
850  UByte bitmask,
851  UInt16 lensType,
852  UInt16 version,
853  UInt16 eyeRelief,
854  UInt16 kCoefficients[11],
855  UInt16 maxR,
856  UInt16 metersPerTanAngleAtCenter,
857  UInt16 chromaticAberration[4])
858  : CommandId(commandId),
859  NumDistortions(numDistortions),
860  DistortionIndex(distortionIndex),
861  Bitmask(bitmask),
862  LensType(lensType),
863  Version(version),
864  EyeRelief(eyeRelief),
865  MaxR(maxR),
866  MetersPerTanAngleAtCenter(metersPerTanAngleAtCenter)
867  {
868  memcpy(KCoefficients, kCoefficients, sizeof(KCoefficients));
869  memcpy(ChromaticAberration, chromaticAberration, sizeof(ChromaticAberration));
870  }
871 
883 };
884 
885 // Temperature calibration result (DK2).
887 {
889  : CommandId(0), Version(0),
890  NumBins(0), Bin(0), NumSamples(0), Sample(0),
892  Time(0), Offset(0)
893  {}
894 
896  UByte version,
897  UByte numBins,
898  UByte bin,
899  UByte numSamples,
900  UByte sample,
901  double targetTemperature,
902  double actualTemperature,
903  UInt32 time,
904  Vector3d offset)
905  : CommandId(commandId), Version(version),
906  NumBins(numBins), Bin(bin), NumSamples(numSamples), Sample(sample),
907  TargetTemperature(targetTemperature), ActualTemperature(actualTemperature),
908  Time(time), Offset(offset)
909  { }
910 
912  UByte Version; // See 'DK2 Firmware Specification' document for a description of
913  UByte NumBins; // temperature calibration data.
919  UInt32 Time; // Better hope nobody tries to use this in 2038
921 };
922 
923 // Gyro autocalibration result (DK2).
925 {
927  {
928  // These are not yet defined.
932  };
933 
936  Offset(0), Temperature(0)
937  {}
938 
940  VersionEnum version,
941  Vector3d offset,
942  double temperature)
943  : CommandId(commandId), Version(version),
944  Offset(offset), Temperature(temperature)
945  {}
946 
950  double Temperature;
951 };
952 
953 
954 
955 //-------------------------------------------------------------------------------------
956 // ***** SensorDevice
957 
958 // SensorDevice is an interface to sensor data.
959 // Install a MessageHandler of SensorDevice instance to receive MessageBodyFrame
960 // notifications.
961 //
962 // TBD: Add Polling API? More HID interfaces?
963 
964 class SensorDevice : public HIDDeviceBase, public DeviceBase
965 {
966 public:
968  { }
969 
970  // Static constant for this device type, used in template cast type checks.
972 
973  virtual DeviceType GetType() const { return Device_Sensor; }
974 
975  virtual UByte GetDeviceInterfaceVersion() = 0;
976 
977 
978  // CoordinateFrame defines whether messages come in the coordinate frame
979  // of the sensor device or HMD, which has a different internal sensor.
980  // Sensors obtained form the HMD will automatically use HMD coordinates.
982  {
985  };
986 
987  virtual void SetCoordinateFrame(CoordinateFrame coordframe) = 0;
988  virtual CoordinateFrame GetCoordinateFrame() const = 0;
989 
990  // Sets report rate (in Hz) of MessageBodyFrame messages (delivered through MessageHandler::OnMessage call).
991  // Currently supported maximum rate is 1000Hz. If the rate is set to 500 or 333 Hz then OnMessage will be
992  // called twice or thrice at the same 'tick'.
993  // If the rate is < 333 then the OnMessage / MessageBodyFrame will be called three
994  // times for each 'tick': the first call will contain averaged values, the second
995  // and third calls will provide with most recent two recorded samples.
996  virtual void SetReportRate(unsigned rateHz) = 0;
997  // Returns currently set report rate, in Hz. If 0 - error occurred.
998  // Note, this value may be different from the one provided for SetReportRate. The return
999  // value will contain the actual rate.
1000  virtual unsigned GetReportRate() const = 0;
1001 
1002  // Sets maximum range settings for the sensor described by SensorRange.
1003  // The function will fail if you try to pass values outside Maximum supported
1004  // by the HW, as described by SensorInfo.
1005  // Pass waitFlag == true to wait for command completion. For waitFlag == true,
1006  // returns true if the range was applied successfully (no HW error).
1007  // For waitFlag = false, return 'true' means that command was enqueued successfully.
1008  virtual bool SetRange(const SensorRange& range, bool waitFlag = false) = 0;
1009 
1010  // Return the current sensor range settings for the device. These may not exactly
1011  // match the values applied through SetRange.
1012  virtual void GetRange(SensorRange* range) const = 0;
1013 
1014  // Return the factory calibration parameters for the IMU
1015  virtual void GetFactoryCalibration(Vector3f* AccelOffset, Vector3f* GyroOffset,
1016  Matrix4f* AccelMatrix, Matrix4f* GyroMatrix,
1017  float* Temperature) = 0;
1018  // Enable/disable onboard IMU calibration
1019  // If set to false, the device will return raw values
1020  virtual void SetOnboardCalibrationEnabled(bool enabled) = 0;
1021  // Return true if the mag is calibrated
1022  virtual bool IsMagCalibrated() { return false; }
1023 
1024  // Get/set feature reports from DK1 added to DK2. See 'Tracker Firmware Specification' document for details.
1025  virtual bool SetSerialReport(const SerialReport&) { return false; }
1026  virtual bool GetSerialReport(SerialReport*) { return false; }
1027 
1028  // Get/set feature reports added to DK2. See 'DK2 Firmware Specification' document for details.
1029  virtual bool SetTrackingReport(const TrackingReport&) { return false; }
1030  virtual bool GetTrackingReport(TrackingReport*) { return false; }
1031 
1032  virtual bool SetDisplayReport(const DisplayReport&) { return false; }
1033  virtual bool GetDisplayReport(DisplayReport*) { return false; }
1034 
1035  virtual bool SetMagCalibrationReport(const MagCalibrationReport&) { return false; }
1036  virtual bool GetMagCalibrationReport(MagCalibrationReport*) { return false; }
1037 
1038  virtual bool SetPositionCalibrationReport(const PositionCalibrationReport&) { return false; }
1040 
1041  virtual bool SetCustomPatternReport(const CustomPatternReport&) { return false; }
1042  virtual bool GetCustomPatternReport(CustomPatternReport*) { return false; }
1043 
1044  virtual bool SetKeepAliveMuxReport(const KeepAliveMuxReport&) { return false; }
1045  virtual bool GetKeepAliveMuxReport(KeepAliveMuxReport*) { return false; }
1046 
1047  virtual bool SetManufacturingReport(const ManufacturingReport&) { return false; }
1048  virtual bool GetManufacturingReport(ManufacturingReport*) { return false; }
1049 
1050  virtual bool SetUUIDReport(const UUIDReport&) { return false; }
1051  virtual bool GetUUIDReport(UUIDReport*) { return false; }
1052 
1053  virtual bool SetTemperatureReport(const TemperatureReport&) { return false; }
1054  virtual bool GetAllTemperatureReports(Array<Array<TemperatureReport> >*) { return false; }
1055 
1056  virtual bool GetGyroOffsetReport(GyroOffsetReport*) { return false; }
1057 
1058  virtual bool SetLensDistortionReport(const LensDistortionReport&) { return false; }
1059  virtual bool GetLensDistortionReport(LensDistortionReport*) { return false; }
1060 };
1061 
1062 //-------------------------------------------------------------------------------------
1063 // ***** LatencyTestConfiguration
1064 // LatencyTestConfiguration specifies configuration information for the Oculus Latency Tester device.
1066 {
1067  LatencyTestConfiguration(const Color& threshold, bool sendSamples = false)
1068  : Threshold(threshold), SendSamples(sendSamples)
1069  {
1070  }
1071 
1072  // The color threshold for triggering a detected display change.
1074  // Flag specifying whether we wish to receive a stream of color values from the sensor.
1076 };
1077 
1078 //-------------------------------------------------------------------------------------
1079 // ***** LatencyTestDisplay
1080 // LatencyTestDisplay sets the mode and contents of the Latency Tester LED display.
1081 // See the 'Latency Tester Specification' document for more details.
1083 {
1085  : Mode(mode), Value(value)
1086  {
1087  }
1088 
1089  UByte Mode; // The display mode that we wish to select.
1090  UInt32 Value; // The value to display.
1091 };
1092 
1093 //-------------------------------------------------------------------------------------
1094 // ***** LatencyTestDevice
1095 
1096 // LatencyTestDevice provides an interface to the Oculus Latency Tester which is used to test 'motion to photon' latency.
1098 {
1099 public:
1101  { }
1102 
1103  // Static constant for this device type, used in template cast type checks.
1105 
1106  virtual DeviceType GetType() const { return Device_LatencyTester; }
1107 
1108  // Specifies configuration information including the threshold for triggering a detected color change,
1109  // and a flag to enable a stream of sensor values (typically used for debugging).
1110  virtual bool SetConfiguration(const LatencyTestConfiguration& configuration, bool waitFlag = false) = 0;
1111 
1112  // Get configuration information from device.
1113  virtual bool GetConfiguration(LatencyTestConfiguration* configuration) = 0;
1114 
1115  // Used to calibrate the latency tester at the start of a test. Display the specified color on the screen
1116  // beneath the latency tester and then call this method. Calibration information is lost
1117  // when power is removed from the device.
1118  virtual bool SetCalibrate(const Color& calibrationColor, bool waitFlag = false) = 0;
1119 
1120  // Triggers the start of a measurement. This starts the millisecond timer on the device and
1121  // causes it to respond with the 'MessageLatencyTestStarted' message.
1122  virtual bool SetStartTest(const Color& targetColor, bool waitFlag = false) = 0;
1123 
1124  // Used to set the value displayed on the LED display panel.
1125  virtual bool SetDisplay(const LatencyTestDisplay& display, bool waitFlag = false) = 0;
1126 
1127  virtual DeviceBase* GetDevice() { return this; }
1128 };
1129 
1130 } // namespace OVR
1131 
1132 
1133 
1134 
1135 #endif
UByte UUIDValue[UUID_SIZE]
Definition: OVR_Device.h:828
virtual bool GetDeviceInfo(DeviceInfo *info) const
DeviceType Type
Definition: OVR_Device.h:152
virtual bool SetCustomPatternReport(const CustomPatternReport &)
Definition: OVR_Device.h:1041
ManufacturingReport(UInt16 commandId, UByte numStages, UByte stage, UByte version, UInt16 stageLocation, UInt32 stageTime, UInt32 result)
Definition: OVR_Device.h:786
KeepAliveMuxReport(UInt16 commandId, UByte inReport, UInt16 interval)
Definition: OVR_Device.h:767
PositionTypeEnum PositionType
Definition: OVR_Device.h:733
virtual bool GetCustomPatternReport(CustomPatternReport *)
Definition: OVR_Device.h:1042
PositionCalibrationReport(UInt16 commandId, UByte version, const Vector3d &position, const Vector3d &normal, double rotation, UInt16 positionIndex, UInt16 numPositions, PositionTypeEnum positionType)
Definition: OVR_Device.h:708
float CenterFromTopInMeters
Definition: OVR_Device.h:327
virtual bool SetManufacturingReport(const ManufacturingReport &)
Definition: OVR_Device.h:1047
const DeviceType InfoClassType
Definition: OVR_Device.h:149
Size< float > ScreenSizeInMeters
Definition: OVR_Device.h:325
void operator=(const DeviceInfo &)
Definition: OVR_Device.h:161
virtual void GetFactoryCalibration(Vector3f *AccelOffset, Vector3f *GyroOffset, Matrix4f *AccelMatrix, Matrix4f *GyroMatrix, float *Temperature)=0
DeviceManager * getThis()
Definition: OVR_Device.h:293
virtual DeviceManager * GetManager() const
Definition: OVR_Device.h:248
virtual unsigned GetReportRate() const =0
virtual DeviceManager * GetManager() const
__BEGIN_NAMESPACE_STD void * memcpy(void *__restrict __dest, const void *__restrict __src, size_t __n) __THROW __nonnull((1
void EncodeUInt16(UByte *buffer, UInt16 val)
Definition: OVR_Alg.h:1017
virtual void AddRef()
TrackingReport(UInt16 commandId, UByte pattern, bool enable, bool autoincrement, bool useCarrier, bool syncInput, bool vsyncLock, bool customPattern, UInt16 exposureLength, UInt16 frameInterval, UInt16 vsyncOffset, UByte dutyCycle)
Definition: OVR_Device.h:576
virtual bool SupportsMessageType(MessageType) const
Definition: OVR_Device.h:80
float MaxRotationRate
Definition: OVR_Device.h:469
virtual UByte GetDeviceInterfaceVersion()=0
unsigned Version
Definition: OVR_Device.h:156
uint16_t UInt16
Definition: OVR_Types.h:251
void operator=(const SensorInfo &)
Definition: OVR_Device.h:492
float MaxMagneticField
Definition: OVR_Device.h:472
virtual bool SetUUIDReport(const UUIDReport &)
Definition: OVR_Device.h:1050
Lock * GetHandlerLock() const
DeviceEnumerationArgs EnumArgs
Definition: OVR_Device.h:215
uint32_t UInt32
Definition: OVR_Types.h:253
virtual DeviceType GetType() const
Definition: OVR_Device.h:973
virtual bool GetTrackingReport(TrackingReport *)
Definition: OVR_Device.h:1030
HmdShutterTypeEnum Type
Definition: OVR_Device.h:333
virtual DeviceType GetType() const
MagCalibrationReport(UInt16 commandId, UByte version, const Matrix4f &calibration)
Definition: OVR_Device.h:681
UInt16 DecodeUInt16(const UByte *buffer)
Definition: OVR_Alg.h:986
ShutterTypeEnum ShutterType
Definition: OVR_Device.h:660
DeviceInfo(DeviceType type)
Definition: OVR_Device.h:159
size_t UPInt
Definition: OVR_Types.h:218
void operator=(const HMDInfo &src)
Definition: OVR_Device.h:377
DeviceEnumerationArgs(DeviceType enumType, bool availableOnly)
Definition: OVR_Device.h:170
virtual bool SetSerialReport(const SerialReport &)
Definition: OVR_Device.h:1025
uint8_t UByte
Definition: OVR_Types.h:249
virtual bool IsMagCalibrated()
Definition: OVR_Device.h:1022
virtual void Release()
virtual bool SetStartTest(const Color &targetColor, bool waitFlag=false)=0
TemperatureReport(UInt16 commandId, UByte version, UByte numBins, UByte bin, UByte numSamples, UByte sample, double targetTemperature, double actualTemperature, UInt32 time, Vector3d offset)
Definition: OVR_Device.h:895
virtual bool SetMagCalibrationReport(const MagCalibrationReport &)
Definition: OVR_Device.h:1035
virtual ~DeviceBase()
Definition: OVR_Device.h:109
virtual CoordinateFrame GetCoordinateFrame() const =0
virtual ProfileManager * GetProfileManager() const =0
virtual bool GetAllPositionCalibrationReports(Array< PositionCalibrationReport > *)
Definition: OVR_Device.h:1039
float ScreenGapSizeInMeters
Definition: OVR_Device.h:326
bool IsDisconnected() const
LatencyTestConfiguration(const Color &threshold, bool sendSamples=false)
Definition: OVR_Device.h:1067
LensDistortionReport(UInt16 commandId, UByte numDistortions, UByte distortionIndex, UByte bitmask, UInt16 lensType, UInt16 version, UInt16 eyeRelief, UInt16 kCoefficients[11], UInt16 maxR, UInt16 metersPerTanAngleAtCenter, UInt16 chromaticAberration[4])
Definition: OVR_Device.h:847
char DisplayDeviceName[32]
Definition: OVR_Device.h:347
SerialImpl(const SerialReport &settings)
Definition: OVR_Device.h:541
float LensSeparationInMeters
Definition: OVR_Device.h:328
virtual bool SetCalibrate(const Color &calibrationColor, bool waitFlag=false)=0
DisplayReport(UInt16 commandId, UByte brightness, ShutterTypeEnum shutterType, CurrentLimitEnum currentLimit, bool useRolling, bool reverseRolling, bool highBrightness, bool selfRefresh, bool readPixel, bool directPentile, UInt16 persistence, UInt16 lightingOffset, UInt16 pixelSettle, UInt16 totalRows)
Definition: OVR_Device.h:636
virtual void OnMessage(const Message &)
Definition: OVR_Device.h:75
virtual bool GetGyroOffsetReport(GyroOffsetReport *)
Definition: OVR_Device.h:1056
virtual void SetReportRate(unsigned rateHz)=0
bool IsSameDisplay(const HMDInfo &o) const
Definition: OVR_Device.h:393
virtual bool SetTrackingReport(const TrackingReport &)
Definition: OVR_Device.h:1029
UByte SerialNumberValue[SERIAL_NUMBER_SIZE]
Definition: OVR_Device.h:520
String ProductName
Definition: OVR_Device.h:154
virtual DeviceEnumerator EnumerateDevicesEx(const DeviceEnumerationArgs &args)=0
DeviceEnumerator< D > EnumerateDevices(bool availableOnly=true)
Definition: OVR_Device.h:265
String SerialNumber
Definition: OVR_Device.h:489
CurrentLimitEnum CurrentLimit
Definition: OVR_Device.h:661
#define OVR_ASSERT(p)
virtual bool GetKeepAliveMuxReport(KeepAliveMuxReport *)
Definition: OVR_Device.h:1045
virtual bool SetKeepAliveMuxReport(const KeepAliveMuxReport &)
Definition: OVR_Device.h:1044
UInt16 CommandId
Definition: OVR_Device.h:827
virtual bool GetManufacturingReport(ManufacturingReport *)
Definition: OVR_Device.h:1048
virtual bool SetDisplay(const LatencyTestDisplay &display, bool waitFlag=false)=0
virtual DeviceType GetType() const
Definition: OVR_Device.h:247
virtual DeviceType GetType() const
Definition: OVR_Device.h:421
virtual bool GetConfiguration(LatencyTestConfiguration *configuration)=0
virtual bool GetUUIDReport(UUIDReport *)
Definition: OVR_Device.h:1051
virtual DeviceBase * GetParent() const
Lock * GetHandlerLock() const
DeviceEnumerator enumeratorFromHandle(const DeviceHandle &h, const DeviceEnumerationArgs &args)
Definition: OVR_Device.h:290
virtual Ptr< DeviceCreateDesc > AddDevice_NeedsLock(const DeviceCreateDesc &createDesc)=0
virtual bool GetDisplayReport(DisplayReport *)
Definition: OVR_Device.h:1033
static DeviceManager * Create()
virtual bool SetTemperatureReport(const TemperatureReport &)
Definition: OVR_Device.h:1053
HmdTypeEnum HmdType
Definition: OVR_Device.h:323
virtual bool GetSerialReport(SerialReport *)
Definition: OVR_Device.h:1026
SensorRange(float maxAcceleration=0.0f, float maxRotationRate=0.0f, float maxMagneticField=0.0f)
Definition: OVR_Device.h:457
float MaxAcceleration
Definition: OVR_Device.h:466
virtual bool SetPositionCalibrationReport(const PositionCalibrationReport &)
Definition: OVR_Device.h:1038
virtual DeviceBase * GetDevice()
Definition: OVR_Device.h:1127
DeviceEnumerator(const DeviceHandle &dev, const DeviceEnumerationArgs &args)
Definition: OVR_Device.h:211
virtual bool SetProfileName(const char *name)=0
static const int SERIAL_NUMBER_SIZE
Definition: OVR_Device.h:501
bool IsHandlerInstalled() const
CustomPatternReport(UInt16 commandId, UByte sequenceLength, UInt32 sequence, UInt16 ledIndex, UInt16 numLEDs)
Definition: OVR_Device.h:744
static const int UUID_SIZE
Definition: OVR_Device.h:809
__BEGIN_NAMESPACE_STD void void __END_NAMESPACE_STD void __BEGIN_NAMESPACE_STD void * memset(void *__s, int __c, size_t __n) __THROW __nonnull((1))
virtual bool SetLensDistortionReport(const LensDistortionReport &)
Definition: OVR_Device.h:1058
virtual DeviceType GetType() const
Definition: OVR_Device.h:1106
virtual DeviceCommon * getDeviceCommon() const =0
virtual void AddMessageHandler(MessageHandler *handler)
bool MatchRule(DeviceType type, bool available) const
Definition: OVR_Device.h:175
GyroOffsetReport(UInt16 commandId, VersionEnum version, Vector3d offset, double temperature)
Definition: OVR_Device.h:939
virtual bool SetDisplayReport(const DisplayReport &)
Definition: OVR_Device.h:1032
virtual SensorDevice * GetSensor()=0
virtual bool SetConfiguration(const LatencyTestConfiguration &configuration, bool waitFlag=false)=0
virtual bool GetMagCalibrationReport(MagCalibrationReport *)
Definition: OVR_Device.h:1036
virtual Profile * GetProfile()=0
struct OVR::HMDInfo::ShutterInfo Shutter
String Manufacturer
Definition: OVR_Device.h:155
bool enumerateNext(const DeviceEnumerationArgs &args)
SerialReport(UInt16 commandId, UByte SNo[SERIAL_NUMBER_SIZE])
Definition: OVR_Device.h:509
Size< int > ResolutionInPixels
Definition: OVR_Device.h:324
virtual void SetCoordinateFrame(CoordinateFrame coordframe)=0
virtual bool SetRange(const SensorRange &range, bool waitFlag=false)=0
virtual void SetOnboardCalibrationEnabled(bool enabled)=0
VersionEnum Version
Definition: OVR_Device.h:948
virtual bool IsConnected()
static int OVR_STDCALL CompareNoCase(const char *a, const char *b)
Definition: OVR_String.cpp:488
SerialReport Settings
Definition: OVR_Device.h:533
LatencyTestDisplay(UByte mode, UInt32 value)
Definition: OVR_Device.h:1084
virtual const char * GetProfileName()=0
HMDDevice * Disconnect(SensorDevice *)
DeviceBase * CreateDevice()
UUIDReport(UInt16 commandId, UByte uuid[UUID_SIZE])
Definition: OVR_Device.h:817
virtual void GetRange(SensorRange *range) const =0
virtual bool GetLensDistortionReport(LensDistortionReport *)
Definition: OVR_Device.h:1059
UInt16 ProductId
Definition: OVR_Device.h:485
virtual bool GetAllTemperatureReports(Array< Array< TemperatureReport > > *)
Definition: OVR_Device.h:1054
SensorRange MaxRanges
Definition: OVR_Device.h:487
UByte Buffer[PacketSize]
Definition: OVR_Device.h:531