87 SampleCount = buffer[1];
96 int iterationCount = (SampleCount > 2) ? 3 : SampleCount;
98 for (
int i = 0; i < iterationCount; i++)
100 UnpackSensor(buffer + 8 + 16 * i, &Samples[i].AccelX, &Samples[i].AccelY, &Samples[i].AccelZ);
101 UnpackSensor(buffer + 16 + 16 * i, &Samples[i].GyroX, &Samples[i].GyroY, &Samples[i].GyroZ);
122 : CommandId(0), DistortionType(Base_None)
181 void operator = (
const SensorEnumerator&) { }
187 : pFactory(factory), ExternalVisitor(externalVisitor) { }
191 return pFactory->MatchVendorProduct(vendorId, productId);
202 ExternalVisitor.Visit(createDesc);
207 ExternalVisitor.Visit(createDesc);
231 SensorEnumerator sensorEnumerator(
this, visitor);
307 NextKeepAliveTickSeconds(0),
320 #ifdef OVR_OS_ANDROID
321 pPhoneSensors = PhoneSensors::Create();
400 LogText(
"OVR::SensorDevice - Lost connection to '%s'\n",
getHIDDesc()->Path.ToCStr());
414 bool processed =
false;
431 double keepAliveDelta = 3.0;
557 else if (rateHz == 0)
627 bool convertHMDToSensor =
false)
630 float ax = (float)sample.
AccelX;
631 float ay = (
float)sample.
AccelY;
632 float az = (float)sample.
AccelZ;
635 return val * 0.0001f;
641 bool convertHMDToSensor =
false)
643 float mx = (float)update.
MagX;
644 float my = (
float)update.
MagY;
645 float mz = (float)update.
MagZ;
655 bool convertHMDToSensor =
false)
658 float gx = (float)sample.
GyroX;
659 float gy = (
float)sample.
GyroY;
660 float gz = (float)sample.
GyroZ;
663 return val * 0.0001f;
695 const double timeUnit = (1.0 / 1000.0);
696 double scaledTimeUnit = timeUnit;
703 double absoluteTimeSeconds = 0.0;
708 unsigned timestampDelta;
724 double deviceTime = (
FullTimestamp + timestampAdjust) * timeUnit;
760 double deviceTime = (
FullTimestamp + timestampAdjust) * timeUnit;
771 #ifdef OVR_OS_ANDROID
774 convertHMDToSensor =
false;
789 sensors.
TimeDelta = (float)scaledTimeUnit;
792 for (
UByte i = 0; i < iterations; i++)
794 sensors.
AbsoluteTimeSeconds = absoluteTimeSeconds - ( iterations - 1 - i ) * scaledTimeUnit;
799 #ifdef OVR_OS_ANDROID
805 sensors.
TimeDelta = (float)scaledTimeUnit;
820 #ifdef OVR_OS_ANDROID
828 #ifdef OVR_OS_ANDROID
830 void SensorDeviceImpl::replaceWithPhoneMag(
Vector3f* val)
834 pPhoneSensors->SetMagSource(PhoneSensors::MagnetometerSource_Native);
837 pPhoneSensors->GetLatestMagValue(&magPhone);
840 magPhone *= 10000.0f/1000000.0f;
862 const char* calibrationName =
"default";
875 time_t now = time(0);
876 localtime_s(&caltime, &now);
877 strftime(time_str, 64,
"%Y-%m-%d %H:%M:%S", &caltime);
880 time_t now = time(0);
881 caltime = localtime(&now);
882 strftime(time_str, 64,
"%Y-%m-%d %H:%M:%S", caltime);
896 Matrix4f oldcalmat; oldcalmat.
M[0][3] = center.
x; oldcalmat.
M[1][3] = center.
y; oldcalmat.
M[2][3] = center.
z;
901 path +=
"/Devices.json";
907 JSON* version = root->GetFirstItem();
908 if (version && version->
Name ==
"Oculus Device Profile Version")
928 device = root->GetFirstItem();
929 device = root->GetNextItem(device);
933 if (device->
Name ==
"Device")
941 if (item->
Name ==
"MagCalibration")
944 if (name && name->
Value == calibrationName)
969 device = root->GetNextItem(device);
975 root->AddStringItem(
"Oculus Device Profile Version",
"1.0");
987 root->AddItem(
"Device", device);
991 device->
AddItem(
"MagCalibration", calibration);
992 return root->Save(path);
1007 const char* calibrationName =
"default";
1010 path +=
"/Devices.json";
1018 JSON* version = root->GetFirstItem();
1019 if (version && version->
Name ==
"Oculus Device Profile Version")
1030 JSON* device = root->GetNextItem(version);
1034 if (device->
Name ==
"Device")
1044 if (autoyaw && autoyaw->
dValue == 0)
1050 if (item->
Name ==
"MagCalibration")
1052 JSON* calibration = item;
1054 if (name && name->
Value == calibrationName)
1062 if (major > data->
Version && major <= 2)
1072 const char* caltime_str = caltime->
Value.
ToCStr();
1075 memset(&ct, 0,
sizeof(tm));
1079 localtime_s(&nowtime, &now);
1080 ct.tm_isdst = nowtime.tm_isdst;
1081 sscanf_s(caltime_str,
"%d-%d-%d %d:%d:%d",
1082 &ct.tm_year, &ct.tm_mon, &ct.tm_mday,
1083 &ct.tm_hour, &ct.tm_min, &ct.tm_sec);
1085 struct tm* nowtime = localtime(&now);
1086 ct.tm_isdst = nowtime->tm_isdst;
1087 sscanf(caltime_str,
"%d-%d-%d %d:%d:%d",
1088 &ct.tm_year, &ct.tm_mon, &ct.tm_mday,
1089 &ct.tm_hour, &ct.tm_min, &ct.tm_sec);
1115 device = root->GetNextItem(device);
virtual bool GetDeviceInfo(DeviceInfo *info) const
Matrix4f GyroCalibrationMatrix
Vector3f AccelCalibrationOffset
bool PushCall(R(C::*fn)(), bool wait=false)
void LogText(const char *fmt,...) OVR_LOG_VAARG_ATTRIBUTE(1
void onTrackerMessage(TrackerMessage *message)
Vector3f MagFromBodyFrameUpdate(const Tracker2Sensors &update)
bool decodeTrackerMessage(TrackerMessage *message, UByte *buffer, int size)
double ScaleTimeUnit(double deviceClockDelta)
const DeviceType InfoClassType
virtual bool MatchVendorProduct(UInt16 vendorId, UInt16 productId) const
virtual bool Initialize(DeviceBase *parent)
float DecodeFloat(const UByte *buffer)
virtual void GetRange(SensorRange *range) const
DeviceManagerImpl * GetManagerImpl()
SensorTimeFilter TimeFilter
bool setSerialReport(const SerialReport &data)
virtual bool GetDeviceInfo(DeviceInfo *info) const
virtual unsigned GetReportRate() const
SensorDeviceImpl(SensorDeviceCreateDesc *createDesc)
virtual ThreadCommandQueue * GetThreadQueue()=0
Ptr< DeviceCreateDesc > pCreateDesc
UInt32 DecodeUInt32(const UByte *buffer)
virtual void AddMessageHandler(MessageHandler *handler)
virtual bool DetectHIDDevice(DeviceManager *pdevMgr, const HIDDeviceDesc &desc)
bool GetSerialReport(SerialReport *data)
Matrix4f AccelCalibrationMatrix
virtual DeviceBase * NewDeviceInstance()
virtual void SetReportRate(unsigned rateHz)
virtual double OnTicks(double tickSeconds)
static SensorDeviceFactory & GetInstance()
UInt16 DecodeUInt16(const UByte *buffer)
float CalibrationTemperature
bool SetFeatureReport(UByte *data, UInt32 length)
virtual bool Enumerate(HIDEnumerateVisitor *enumVisitor)=0
static void EnumerateHMDFromSensorDisplayInfo(const SensorDisplayInfoImpl &displayInfo, DeviceFactory::EnumerateVisitor &visitor)
Void setReportRate(unsigned rateHz)
static Matrix4 FromString(const char *src)
String GetBaseOVRPath(bool create_dir)
float OutsideLensSurfaceToScreen[2]
virtual bool SetMagCalibrationReport(const MagCalibrationReport &data)
Vector3f AccelFromBodyFrameUpdate(const Tracker2Sensors &update, UByte sampleNumber)
double SampleToSystemTime(double sampleDeviceTime, double systemTime, double prevResult, const char *debugTag="")
TrackerMessageType Decode(const UByte *buffer, int size)
bool setRange(const SensorRange &range)
void GetSensorRange(SensorRange *r)
virtual void OnInputReport(UByte *pData, UInt32 length)
Vector3f GyroCalibrationOffset
virtual void SetOnboardCalibrationEnabled(bool enabled)
const char * ToCStr() const
CoordinateFrame HWCoordinates
Vector3f LastRotationRate
virtual void GetFactoryCalibration(Vector3f *AccelOffset, Vector3f *GyroOffset, Matrix4f *AccelMatrix, Matrix4f *GyroMatrix, float *Temperature)
bool getSerialReport(SerialReport *data)
static SensorRange GetMaxSensorRange()
virtual bool IsMagCalibrated()
static JSON * Load(const char *path, const char **perror=0)
virtual CoordinateFrame GetCoordinateFrame() const
static JSON * CreateObject()
void SetSensorCoordinates(bool sensorCoordinates)
virtual void EnumerateDevices(EnumerateVisitor &visitor)
void AddItem(const char *string, JSON *item)
HIDDeviceDesc * getHIDDesc() const
MessageHandlerRef HandlerRef
virtual HIDDeviceManager * GetHIDDeviceManager() const
bool GetFeatureReport(UByte *data, UInt32 length)
JSON * GetNextItem(JSON *item)
DeviceManagerImpl * GetManagerImpl() const
virtual Ptr< DeviceCreateDesc > AddDevice_NeedsLock(const DeviceCreateDesc &createDesc)=0
virtual void SetCoordinateFrame(CoordinateFrame coordframe)
Vector3f EulerFromBodyFrameUpdate(const Tracker2Sensors &update, UByte sampleNumber)
void AddNumberItem(const char *name, double n)
CoordinateFrame Coordinates
virtual void openDevice()
void AddStringItem(const char *name, const char *s)
double NextKeepAliveTickSeconds
HIDDevice * GetInternalDevice() const
__BEGIN_NAMESPACE_STD void void __END_NAMESPACE_STD void __BEGIN_NAMESPACE_STD void * memset(void *__s, int __c, size_t __n) __THROW __nonnull((1))
void UnpackSensor(const UByte *buffer, SInt32 *x, SInt32 *y, SInt32 *z)
bool IsUsingSensorCoordinates() const
void closeDeviceOnError()
static double OVR_STDCALL GetSeconds()
const int MAX_DEVICE_PROFILE_MAJOR_VERSION
virtual void AddMessageHandler(MessageHandler *handler)
Vector3f LastMagneticField
Void setCoordinateFrame(CoordinateFrame coordframe)
virtual bool SetFeatureReport(UByte *data, UInt32 length)=0
void ToString(char *dest, UPInt destsize) const
virtual bool SetRange(const SensorRange &range, bool waitFlag)
Void setOnboardCalibrationEnabled(bool enabled)
double AbsoluteTimeSeconds
bool SetSerialReport(const SerialReport &data)
void Call(const Message &msg)
SInt16 DecodeSInt16(const UByte *buffer)
Vector3< float > Vector3f
JSON * GetItemByName(const char *name)
virtual bool GetMagCalibrationReport(MagCalibrationReport *data)
Vector3f LastAcceleration
Vector3< T > Transform(const Vector3< T > &v) const
bool PushCallAndWaitResult(R(C::*fn)(), R *ret)
virtual bool GetFeatureReport(UByte *data, UInt32 length)=0