oculus1

view libovr/Src/OVR_LatencyTestImpl.h @ 23:0c76f70fb7e9

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 28 Sep 2013 04:13:33 +0300
parents
children
line source
1 /************************************************************************************
3 Filename : OVR_LatencyTestImpl.h
4 Content : Latency Tester specific implementation.
5 Created : March 7, 2013
6 Authors : Lee Cooper
8 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
10 Use of this software is subject to the terms of the Oculus license
11 agreement provided at the time of installation or download, or which
12 otherwise accompanies this software in either electronic or hard copy form.
14 *************************************************************************************/
16 #ifndef OVR_LatencyTestImpl_h
17 #define OVR_LatencyTestImpl_h
19 #include "OVR_HIDDeviceImpl.h"
21 namespace OVR {
23 struct LatencyTestSamplesMessage;
24 struct LatencyTestButtonMessage;
25 struct LatencyTestStartedMessage;
26 struct LatencyTestColorDetectedMessage;
28 //-------------------------------------------------------------------------------------
29 // LatencyTestDeviceFactory enumerates Oculus Latency Tester devices.
30 class LatencyTestDeviceFactory : public DeviceFactory
31 {
32 public:
33 static LatencyTestDeviceFactory Instance;
35 // Enumerates devices, creating and destroying relevant objects in manager.
36 virtual void EnumerateDevices(EnumerateVisitor& visitor);
38 virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId) const;
39 virtual bool DetectHIDDevice(DeviceManager* pdevMgr, const HIDDeviceDesc& desc);
41 protected:
42 DeviceManager* getManager() const { return (DeviceManager*) pManager; }
43 };
46 // Describes a single a Oculus Latency Tester device and supports creating its instance.
47 class LatencyTestDeviceCreateDesc : public HIDDeviceCreateDesc
48 {
49 public:
50 LatencyTestDeviceCreateDesc(DeviceFactory* factory, const HIDDeviceDesc& hidDesc)
51 : HIDDeviceCreateDesc(factory, Device_LatencyTester, hidDesc) { }
53 virtual DeviceCreateDesc* Clone() const
54 {
55 return new LatencyTestDeviceCreateDesc(*this);
56 }
58 virtual DeviceBase* NewDeviceInstance();
60 virtual MatchResult MatchDevice(const DeviceCreateDesc& other,
61 DeviceCreateDesc**) const
62 {
63 if ((other.Type == Device_LatencyTester) && (pFactory == other.pFactory))
64 {
65 const LatencyTestDeviceCreateDesc& s2 = (const LatencyTestDeviceCreateDesc&) other;
66 if (MatchHIDDevice(s2.HIDDesc))
67 return Match_Found;
68 }
69 return Match_None;
70 }
72 virtual bool MatchHIDDevice(const HIDDeviceDesc& hidDesc) const
73 {
74 // should paths comparison be case insensitive?
75 return ((HIDDesc.Path.CompareNoCase(hidDesc.Path) == 0) &&
76 (HIDDesc.SerialNumber == hidDesc.SerialNumber));
77 }
78 virtual bool GetDeviceInfo(DeviceInfo* info) const;
79 };
82 //-------------------------------------------------------------------------------------
83 // ***** OVR::LatencyTestDeviceImpl
85 // Oculus Latency Tester interface.
87 class LatencyTestDeviceImpl : public HIDDeviceImpl<OVR::LatencyTestDevice>
88 {
89 public:
90 LatencyTestDeviceImpl(LatencyTestDeviceCreateDesc* createDesc);
91 ~LatencyTestDeviceImpl();
93 // DeviceCommon interface.
94 virtual bool Initialize(DeviceBase* parent);
95 virtual void Shutdown();
97 // DeviceManagerThread::Notifier interface.
98 virtual void OnInputReport(UByte* pData, UInt32 length);
100 // LatencyTesterDevice interface
101 virtual bool SetConfiguration(const OVR::LatencyTestConfiguration& configuration, bool waitFlag = false);
102 virtual bool GetConfiguration(OVR::LatencyTestConfiguration* configuration);
104 virtual bool SetCalibrate(const Color& calibrationColor, bool waitFlag = false);
106 virtual bool SetStartTest(const Color& targetColor, bool waitFlag = false);
107 virtual bool SetDisplay(const LatencyTestDisplay& display, bool waitFlag = false);
109 protected:
110 bool openDevice(const char** errorFormatString);
111 void closeDevice();
112 void closeDeviceOnIOError();
114 bool initializeRead();
115 bool processReadResult();
117 bool setConfiguration(const OVR::LatencyTestConfiguration& configuration);
118 bool getConfiguration(OVR::LatencyTestConfiguration* configuration);
119 bool setCalibrate(const Color& calibrationColor);
120 bool setStartTest(const Color& targetColor);
121 bool setDisplay(const OVR::LatencyTestDisplay& display);
123 // Called for decoded messages
124 void onLatencyTestSamplesMessage(LatencyTestSamplesMessage* message);
125 void onLatencyTestButtonMessage(LatencyTestButtonMessage* message);
126 void onLatencyTestStartedMessage(LatencyTestStartedMessage* message);
127 void onLatencyTestColorDetectedMessage(LatencyTestColorDetectedMessage* message);
129 };
131 } // namespace OVR
133 #endif // OVR_LatencyTestImpl_h