protected override void Initialize(string path) { base.Initialize(path); this.SensorInfo = new SensorInfo(oCaps, 0x2833, 0x0001, ""); if (!HidD_SetNumInputBuffers(m_hHandle, 128)) { throw new Exception("Failed 'HidD_SetNumInputBuffers' while initializing device."); } //Sensor Range SensorRangeImpl sr = new SensorRangeImpl(new SensorRange(), 0); if (GetFeature(ref sr.Buffer)) { sr.Unpack(); SensorRange CurrentRange; sr.GetSensorRange(out CurrentRange); // Increase the magnetometer range, since the default value is not enough in practice CurrentRange.MaxMagneticField = 2.5f; SensorRangeImpl sr2 = new SensorRangeImpl(CurrentRange); if (SetFeature(ref sr.Buffer)) { sr.GetSensorRange(out CurrentRange); } } //Set Report Rate SensorConfig scfg = new SensorConfig(); if (GetFeature(ref scfg.Buffer)) { scfg.Unpack(); } int RateHz = 500; if (RateHz > 1000) { RateHz = 1000; } else if (RateHz == 0) { RateHz = 500; } scfg.PacketInterval = (UInt16)((1000 / RateHz) - 1); scfg.KeepAliveIntervalMs = 10000; scfg.Pack(); SetFeature(ref scfg.Buffer); KeepAlivetimer = new Timer(6 * 1000); KeepAlivetimer.Elapsed += new ElapsedEventHandler(timer_Elapsed); KeepAlivetimer.AutoReset = true; KeepAlivetimer.Start(); }
// *** Setup // Attaches this SensorFusion to a sensor device, from which it will receive // notification messages. If a sensor is attached, manual message notification // is not necessary. Calling this function also resets SensorFusion state. public bool AttachToSensor(RiftHeadsetDevice sensor) { // clear the cached device information CachedSensorInfo = sensor.GetDeviceInfo(); // save the device information Reset(); // Automatically load the default mag calibration for this sensor //LoadMagCalibration(); return true; }