OSVR-Core
Oculus_DK2.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_Oculus_DK2_h_GUID_EA07F823_BC38_47B0_F60A_E525110E2C1C
26 #define INCLUDED_Oculus_DK2_h_GUID_EA07F823_BC38_47B0_F60A_E525110E2C1C
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 #include <vrpn_HumanInterface.h>
33 #include <vrpn_Shared.h>
34 #include <opencv2/core/core.hpp> // for basic OpenCV types
35 
36 // Standard includes
37 #include <vector>
38 
39 namespace osvr {
40 namespace oculus_dk2 {
41 
42  // This is the information included with each Inertial Measurement Unit
43  // (IMU) report from a DK2.
44  typedef struct {
45  int accel[3];
46  int gyro[3];
47  vrpn_uint16 timestamp;
48  } OCULUS_IMU_REPORT;
49 
50  // The HID device on the DK2. This is used to control the LEDs and
51  // also to report values from the IMU.
52  class Oculus_DK2_HID : public vrpn_HidInterface {
53  public:
54  Oculus_DK2_HID(double keepAliveSeconds =
55  9 //< How often to re-trigger the LED flashing
56  );
57  virtual ~Oculus_DK2_HID();
58 
61  std::vector<OCULUS_IMU_REPORT> poll();
62 
63  private:
64  vrpn_HidAcceptor *m_filter;
65  double m_keepAliveSeconds;
66  struct timeval m_lastKeepAlive;
67 
68  // Reports from the IMU.
69  std::vector<OCULUS_IMU_REPORT> m_reports;
70 
71  // Send an LED control feature report. The enable flag tells
72  // whether to turn on the LEDs (true) or not.
73  void
74  writeLEDControl(bool enable = true, vrpn_uint16 exposureLength = 350,
75  vrpn_uint16 frameInterval = 16666,
76  vrpn_uint16 vSyncOffset = 0,
77  vrpn_uint8 dutyCycle = 127 //< 255 = 100% brightness
78  ,
79  vrpn_uint8 pattern = 1, bool autoIncrement = true,
80  bool useCarrier = true, bool syncInput = false,
81  bool vSyncLock = false, bool customPattern = false,
82  vrpn_uint16 commandId = 0 //< Should always be zero
83  );
84 
85  // Send a KeepAlive feature report to the DK2. This needs to be sent
86  // every keepAliveSeconds to keep the LEDs going.
87  void writeKeepAlive(
88  bool keepLEDs = true //< Keep LEDs going, or only IMU?
89  ,
90  vrpn_uint16 interval = 10000 //< KeepAlive time in milliseconds
91  ,
92  vrpn_uint16 commandId = 0 //< Should always be zero
93  );
94 
95  // Handle incoming data reports, which in this case are reports
96  // from the Inertial Measurement Unit (IMU).
97  // TODO: Implement the actual parsing and storing of this
98  // information.
99  void on_data_received(size_t bytes, vrpn_uint8 *buffer);
100  };
101 
102  // Function to convert a bogus-formatted image from OpenCV from the
103  // HDK (which happens because the unit claims to be reporting YUV format
104  // when in fact it is reporting grayscale format) into the correct
105  // image. This function returns a grayscale-format image at double
106  // the resolution of the input image.
107  // TODO: The implementation of this function currently only uses half
108  // of the values that are available, doubling them horizontally to fill
109  // in all of the pixels.
110  extern cv::Mat unscramble_image(const cv::Mat &image);
111 
112 } // namespace oculus_dk2
113 } // namespace osvr
114 
115 #endif // INCLUDED_Oculus_DK2_h_GUID_EA07F823_BC38_47B0_F60A_E525110E2C1C
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
std::vector< OCULUS_IMU_REPORT > poll()
Return the latest IMU report(s).
Definition: Oculus_DK2.cpp:55