1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/************************************************************************************
Filename : OVR_SensorImpl_Common.h
Content : Source common to SensorImpl and Sensor2Impl.
Created : January 21, 2014
Authors : Lee Cooper
Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
you may not use the Oculus VR Rift SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
http://www.oculusvr.com/licenses/LICENSE-3.1
Unless required by applicable law or agreed to in writing, the Oculus VR SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*************************************************************************************/
#ifndef OVR_SensorImpl_Common_h
#define OVR_SensorImpl_Common_h
#include "Kernel/OVR_System.h"
#include "OVR_Device.h"
namespace OVR
{
void UnpackSensor(const UByte* buffer, SInt32* x, SInt32* y, SInt32* z);
void PackSensor(UByte* buffer, SInt32 x, SInt32 y, SInt32 z);
// Sensor HW only accepts specific maximum range values, used to maximize
// the 16-bit sensor outputs. Use these ramps to specify and report appropriate values.
const UInt16 AccelRangeRamp[] = { 2, 4, 8, 16 };
const UInt16 GyroRangeRamp[] = { 250, 500, 1000, 2000 };
const UInt16 MagRangeRamp[] = { 880, 1300, 1900, 2500 };
UInt16 SelectSensorRampValue(const UInt16* ramp, unsigned count,
float val, float factor, const char* label);
// SensorScaleImpl provides buffer packing logic for the Sensor Range
// record that can be applied to DK1 sensor through Get/SetFeature. We expose this
// through SensorRange class, which has different units.
struct SensorRangeImpl
{
enum { PacketSize = 8 };
UByte Buffer[PacketSize];
UInt16 CommandId;
UInt16 AccelScale;
UInt16 GyroScale;
UInt16 MagScale;
SensorRangeImpl(const SensorRange& r, UInt16 commandId = 0);
void SetSensorRange(const SensorRange& r, UInt16 commandId = 0);
void GetSensorRange(SensorRange* r);
static SensorRange GetMaxSensorRange();
void Pack();
void Unpack();
};
struct SensorConfigImpl
{
enum { PacketSize = 7 };
UByte Buffer[PacketSize];
// Flag values for Flags.
enum {
Flag_RawMode = 0x01,
Flag_CalibrationTest = 0x02, // Internal test mode
Flag_UseCalibration = 0x04,
Flag_AutoCalibration = 0x08,
Flag_MotionKeepAlive = 0x10,
Flag_CommandKeepAlive = 0x20,
Flag_SensorCoordinates = 0x40
};
UInt16 CommandId;
UByte Flags;
UInt16 PacketInterval; // LDC - This should be a UByte. Fix when you have time to test it.
UInt16 SampleRate;
SensorConfigImpl();
void SetSensorCoordinates(bool sensorCoordinates);
bool IsUsingSensorCoordinates() const;
void Pack();
void Unpack();
};
struct SensorFactoryCalibrationImpl
{
enum { PacketSize = 69 };
UByte Buffer[PacketSize];
Vector3f AccelOffset;
Vector3f GyroOffset;
Matrix4f AccelMatrix;
Matrix4f GyroMatrix;
float Temperature;
SensorFactoryCalibrationImpl();
void Pack(); // Not yet implemented.
void Unpack();
};
// SensorKeepAlive - feature report that needs to be sent at regular intervals for sensor
// to receive commands.
struct SensorKeepAliveImpl
{
enum { PacketSize = 5 };
UByte Buffer[PacketSize];
UInt16 CommandId;
UInt16 KeepAliveIntervalMs;
SensorKeepAliveImpl(UInt16 interval = 0, UInt16 commandId = 0);
void Pack();
void Unpack();
};
struct TrackerSample
{
SInt32 AccelX, AccelY, AccelZ;
SInt32 GyroX, GyroY, GyroZ;
};
enum LastCommandIdFlags
{
LastCommandId_Shutter = 1,
LastCommandId_LEDs = 2
};
} // namespace OVR
#endif // OVR_SensorImpl_Common_h
|