/************************************************************************************ Filename : OVR_Sensor2ImplUtil.h Content : DK2 sensor device feature report utils. Created : January 27, 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_Sensor2ImplUtil_h #define OVR_Sensor2ImplUtil_h #include "OVR_Device.h" #include "OVR_SensorImpl_Common.h" #include "Kernel/OVR_Alg.h" namespace OVR { using namespace Alg; // Tracking feature report. struct TrackingImpl { enum { PacketSize = 13 }; UByte Buffer[PacketSize]; TrackingReport Settings; TrackingImpl() { for (int i=0; i> 4) & 0x02); Settings.UseRolling = (Buffer[4] & 0x40) != 0; Settings.ReverseRolling = (Buffer[4] & 0x80) != 0; Settings.HighBrightness = (Buffer[5] & 0x01) != 0; Settings.SelfRefresh = (Buffer[5] & 0x02) != 0; Settings.ReadPixel = (Buffer[5] & 0x04) != 0; Settings.DirectPentile = (Buffer[5] & 0x08) != 0; Settings.Persistence = DecodeUInt16(Buffer+8); Settings.LightingOffset = DecodeUInt16(Buffer+10); Settings.PixelSettle = DecodeUInt16(Buffer+12); Settings.TotalRows = DecodeUInt16(Buffer+14); } }; // MagCalibration feature report. struct MagCalibrationImpl { enum { PacketSize = 52 }; UByte Buffer[PacketSize]; MagCalibrationReport Settings; MagCalibrationImpl() { memset(Buffer, 0, sizeof(Buffer)); Buffer[0] = 14; } MagCalibrationImpl(const MagCalibrationReport& settings) : Settings(settings) { Pack(); } void Pack() { Buffer[0] = 14; EncodeUInt16(Buffer+1, Settings.CommandId); Buffer[3] = Settings.Version; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) { SInt32 value = SInt32(Settings.Calibration.M[i][j] * 1e4f); EncodeSInt32(Buffer + 4 + 4 * (4 * i + j), value); } } void Unpack() { Settings.CommandId = DecodeUInt16(Buffer+1); Settings.Version = Buffer[3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) { SInt32 value = DecodeSInt32(Buffer + 4 + 4 * (4 * i + j)); Settings.Calibration.M[i][j] = (float)value * 1e-4f; } } }; //------------------------------------------------------------------------------------- // PositionCalibration feature report. // - Sensor interface versions before 5 do not support Normal and Rotation. struct PositionCalibrationImpl { enum { PacketSize = 30 }; UByte Buffer[PacketSize]; PositionCalibrationReport Settings; PositionCalibrationImpl() { for (int i=0; i> 8); Buffer[3] = UByte(Settings.Version); Vector3d offset = Settings.Offset * 1e4; PackSensor(Buffer + 4, (SInt32) offset.x, (SInt32) offset.y, (SInt32) offset.z); EncodeSInt16(Buffer + 16, SInt16(Settings.Temperature * 1e2)); } void Unpack() { Settings.CommandId = DecodeUInt16(Buffer + 1); Settings.Version = GyroOffsetReport::VersionEnum(Buffer[3]); SInt32 x, y, z; UnpackSensor(Buffer + 4, &x, &y, &z); Settings.Offset = Vector3d(x, y, z) * 1e-4f; Settings.Temperature = DecodeSInt16(Buffer + 16) * 1e-2; } }; } // namespace OVR #endif // OVR_Sensor2ImplUtil_h