/// <summary> /// Interprets a HID report sent by a DualShock 3 device. /// </summary> /// <param name="report">The HID report as byte array.</param> protected override void ParseHidReport(byte[] report) { // report ID must be 1 if (report[0] != 0x01) { return; } AccurateTime currentTime = AccurateTime.Now; PacketCounter++; var inputReport = NewHidReport(); // set battery level Battery = (DsBattery)report[30]; // set packet counter inputReport.PacketCounter = PacketCounter; // convert accel/gyro values if (_cal != null) { _cal.ApplyCalToInReport(report); } // copy controller data to report packet Buffer.BlockCopy(report, 0, inputReport.RawBytes, 8, 49); // DS3 does not have timestamp in reports, so just give system time inputReport.Timestamp = (long)Math.Round(currentTime.ToSeconds() * 1000000); //convert from s to us var trigger = false; // detect Quick Disconnect combo (L1, R1 and PS buttons pressed at the same time) if (inputReport[Ds3Button.L1].IsPressed && inputReport[Ds3Button.R1].IsPressed && inputReport[Ds3Button.Ps].IsPressed) { trigger = true; // unset PS button inputReport.RawBytes[12] ^= 0x01; } if (trigger && !IsShutdown) { IsShutdown = true; m_Disconnect = DateTime.Now; } else if (!trigger && IsShutdown) { IsShutdown = false; } OnHidReportReceived(inputReport); }
/// <summary> /// Interprets a HID report sent by a DualShock 3 device. /// </summary> /// <param name="report">The HID report as byte array.</param> public override void ParseHidReport(byte[] report) { if (report[10] == 0xFF) { return; } AccurateTime currentTime = AccurateTime.Now; m_PlugStatus = report[38]; Battery = (DsBattery)report[39]; m_CableStatus = report[40]; if (m_Packet == 0) { Rumble(0, 0); } m_Packet++; var inputReport = NewHidReport(); inputReport.PacketCounter = m_Packet; // convert accel/gyro values if (_cal != null) { _cal.ApplyCalToInReport(report, 9); } // copy controller data to report packet Buffer.BlockCopy(report, 9, inputReport.RawBytes, 8, 49); // DS3 does not have timestamp in reports, so just give system time inputReport.Timestamp = (long)Math.Round(currentTime.ToSeconds() * 1000000); //convert from s to us var trigger = false; // Quick Disconnect if (inputReport[Ds3Button.L1].IsPressed && inputReport[Ds3Button.R1].IsPressed && inputReport[Ds3Button.Ps].IsPressed) { trigger = true; // unset PS button inputReport.Unset(Ds3Button.Ps); } if (inputReport.IsPadActive) { m_IsIdle = false; } else if (!m_IsIdle) { m_IsIdle = true; m_Idle = DateTime.Now; } if (trigger && !m_IsDisconnect) { m_IsDisconnect = true; m_Disconnect = DateTime.Now; } else if (!trigger && m_IsDisconnect) { m_IsDisconnect = false; } OnHidReportReceived(inputReport); }