protected override void ParseHidReport(byte[] report) { if (report[0] != 0x01) { return; } HidReport.Core.HidReport inputReport = new HidReport.Core.HidReport(); #region HID Report translation // no battery state since the Gamepad is Usb-powered inputReport.BatteryStatus = DsBattery.None; // packet counter inputReport.PacketCounter = ++PacketCounter; inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[5], 5)); inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[5], 6)); inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[5], 4)); inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[5], 7)); // TODO: implement! #endregion OnHidReportReceived(inputReport); }
protected override void ParseHidReport(byte[] report) { PacketCounter++; var inputReport = new HidReport.Core.HidReport(); #region HID Report translation // no battery state since the Gamepad is Usb-powered inputReport.BatteryStatus = DsBattery.None; // packet counter inputReport.PacketCounter = PacketCounter; // circle inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[1], 2)); inputReport.Set(AxesEnum.Circle, report[13]); // cross inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[1], 1)); inputReport.Set(AxesEnum.Cross, report[14]); // triangle inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[1], 3)); inputReport.Set(AxesEnum.Triangle, report[12]); // square inputReport.Set(ButtonsEnum.Square, IsBitSet(report[1], 0)); inputReport.Set(AxesEnum.Square, report[15]); // select inputReport.Set(ButtonsEnum.Select, IsBitSet(report[2], 0)); // start inputReport.Set(ButtonsEnum.Start, IsBitSet(report[2], 1)); #endregion OnHidReportReceived(inputReport); }
protected override void ParseHidReport(byte[] report) { if (report[5] != 0x00) { return; } PacketCounter++; var inputReport = new HidReport.Core.HidReport(); #region HID Report translation // no battery state since the Gamepad is Usb-powered inputReport.BatteryStatus = DsBattery.None; // packet counter inputReport.PacketCounter = PacketCounter; inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[6], 4)); inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[6], 5)); inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[6], 6)); inputReport.Set(ButtonsEnum.Square, IsBitSet(report[6], 7)); inputReport.Set(ButtonsEnum.Select, IsBitSet(report[7], 4)); inputReport.Set(ButtonsEnum.Start, IsBitSet(report[7], 5)); inputReport.Set(ButtonsEnum.Up, (report[4] == 0x00)); inputReport.Set(ButtonsEnum.Right, (report[3] == 0xFF)); inputReport.Set(ButtonsEnum.Down, (report[4] == 0xFF)); inputReport.Set(ButtonsEnum.Left, (report[3] == 0x00)); inputReport.Set(ButtonsEnum.L1, IsBitSet(report[7], 0)); inputReport.Set(ButtonsEnum.R1, IsBitSet(report[7], 1)); inputReport.Set(ButtonsEnum.L2, IsBitSet(report[7], 2)); inputReport.Set(ButtonsEnum.R2, IsBitSet(report[7], 3)); inputReport.Set(ButtonsEnum.L3, IsBitSet(report[7], 6)); inputReport.Set(ButtonsEnum.R3, IsBitSet(report[7], 7)); // TODO: the PS-button is dead according to the report: // http://forums.pcsx2.net/attachment.php?aid=57420 #endregion OnHidReportReceived(inputReport); }
protected override void ParseHidReport(byte[] report) { if (report[1] != 0x01) { return; } PacketCounter++; var inputReport = new HidReport.Core.HidReport(); #region HID Report translation // no battery state since the Gamepad is Usb-powered inputReport.BatteryStatus = DsBattery.None; // packet counter inputReport.PacketCounter = PacketCounter; inputReport.Set(ButtonsEnum.Select, IsBitSet(report[7], 4)); // Select inputReport.Set(ButtonsEnum.Start, IsBitSet(report[7], 5)); // Start inputReport.Set(ButtonsEnum.L1, IsBitSet(report[7], 0)); // L1 (button) inputReport.Set(ButtonsEnum.R1, IsBitSet(report[7], 2)); // R1 (button) inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[6], 4)); // Triangle (button) inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[6], 5)); // Circle (button) inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[6], 6)); // Cross (button) inputReport.Set(ButtonsEnum.Square, IsBitSet(report[6], 7)); // Square (button) inputReport.Set(ButtonsEnum.Right, (report[4] == 0xFF)); // D-Pad right inputReport.Set(ButtonsEnum.Left, (report[4] == 0x00)); // D-Pad left inputReport.Set(ButtonsEnum.Up, (report[5] == 0x00)); // D-Pad up inputReport.Set(ButtonsEnum.Down, (report[5] == 0xFF)); // D-Pad down // This device has no thumb sticks, center axes inputReport.Set(AxesEnum.Lx, 0x80); inputReport.Set(AxesEnum.Ly, 0x80); inputReport.Set(AxesEnum.Rx, 0x80); inputReport.Set(AxesEnum.Ry, 0x80); #endregion OnHidReportReceived(inputReport); }
protected override void ParseHidReport(byte[] report) { if (report[2] != 0x00) { return; } var inputReport = new HidReport.Core.HidReport(); #region HID Report translation // no battery state since the Gamepad is Usb-powered inputReport.BatteryStatus = DsBattery.None; // packet counter inputReport.PacketCounter = ++PacketCounter; // control buttons inputReport.Set(ButtonsEnum.Select, IsBitSet(report[6], 4)); inputReport.Set(ButtonsEnum.Start, IsBitSet(report[6], 5)); // Left shoulder inputReport.Set(ButtonsEnum.L1, IsBitSet(report[6], 0)); // Right shoulder inputReport.Set(ButtonsEnum.R1, IsBitSet(report[6], 1)); // Left trigger inputReport.Set(ButtonsEnum.L2, IsBitSet(report[6], 2)); // Right trigger inputReport.Set(ButtonsEnum.R2, IsBitSet(report[6], 3)); // Triangle inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[5], 4)); // Circle inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[5], 5)); // Cross inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[5], 6)); // Square inputReport.Set(ButtonsEnum.Square, IsBitSet(report[5], 7)); // Left thumb inputReport.Set(ButtonsEnum.L3, IsBitSet(report[6], 6)); // Right thumb inputReport.Set(ButtonsEnum.R3, IsBitSet(report[6], 7)); var dPad = (byte)(report[5] & ~0xF0); // D-Pad HidParsers.ParseDPad(dPad, inputReport); // Left thumb stick inputReport.Set(AxesEnum.Lx, report[0]); inputReport.Set(AxesEnum.Ly, report[1]); // Right thumb stick inputReport.Set(AxesEnum.Rx, report[3]); inputReport.Set(AxesEnum.Ry, report[4]); #endregion OnHidReportReceived(inputReport); }
public static void ParseDPad(uint val, HidReport.Core.HidReport inputReport) { switch (val) { case 0: inputReport.Set(ButtonsEnum.Up); break; case 1: inputReport.Set(ButtonsEnum.Up); inputReport.Set(ButtonsEnum.Right); break; case 2: inputReport.Set(ButtonsEnum.Right); break; case 3: inputReport.Set(ButtonsEnum.Right); inputReport.Set(ButtonsEnum.Down); break; case 4: inputReport.Set(ButtonsEnum.Down); break; case 5: inputReport.Set(ButtonsEnum.Down); inputReport.Set(ButtonsEnum.Left); break; case 6: inputReport.Set(ButtonsEnum.Left); break; case 7: inputReport.Set(ButtonsEnum.Left); inputReport.Set(ButtonsEnum.Up); break; } }
public static void ParseDs3(byte[] report, HidReport.Core.HidReport inputReport) { inputReport.BatteryStatus = (DsBattery)report[38]; inputReport.Set(ButtonsEnum.Select, IsBitSet(report[10], 0)); inputReport.Set(ButtonsEnum.L3, IsBitSet(report[10], 1)); inputReport.Set(ButtonsEnum.R3, IsBitSet(report[10], 2)); inputReport.Set(ButtonsEnum.Start, IsBitSet(report[10], 3)); inputReport.Set(ButtonsEnum.Up, IsBitSet(report[10], 4)); inputReport.Set(ButtonsEnum.Right, IsBitSet(report[10], 5)); inputReport.Set(ButtonsEnum.Down, IsBitSet(report[10], 6)); inputReport.Set(ButtonsEnum.Left, IsBitSet(report[10], 7)); inputReport.Set(ButtonsEnum.L2, IsBitSet(report[11], 0)); inputReport.Set(ButtonsEnum.R2, IsBitSet(report[11], 1)); inputReport.Set(ButtonsEnum.L1, IsBitSet(report[11], 2)); inputReport.Set(ButtonsEnum.R1, IsBitSet(report[11], 3)); inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[11], 4)); inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[11], 5)); inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[11], 6)); inputReport.Set(ButtonsEnum.Square, IsBitSet(report[11], 7)); inputReport.Set(ButtonsEnum.Ps, IsBitSet(report[12], 0)); //13 inputReport.Set(AxesEnum.Lx, report[14]); inputReport.Set(AxesEnum.Ly, report[15]); inputReport.Set(AxesEnum.Rx, report[16]); inputReport.Set(AxesEnum.Ry, report[17]); inputReport.Set(AxesEnum.Up, report[22]); inputReport.Set(AxesEnum.Right, report[23]); inputReport.Set(AxesEnum.Down, report[24]); inputReport.Set(AxesEnum.Left, report[25]); inputReport.Set(AxesEnum.L2, report[26]); inputReport.Set(AxesEnum.R2, report[27]); inputReport.Set(AxesEnum.L1, report[28]); inputReport.Set(AxesEnum.R1, report[29]); inputReport.Set(AxesEnum.Triangle, report[30]); inputReport.Set(AxesEnum.Circle, report[31]); inputReport.Set(AxesEnum.Cross, report[32]); inputReport.Set(AxesEnum.Square, report[33]); int accelerometerX = (report[49] << 8) | (report[50] << 0); //0-1023 Debug.Assert(accelerometerX >= 0); Debug.Assert(accelerometerX <= 1023); int accelerometerY = (report[51] << 8) | (report[52] << 0); //0-1023 Debug.Assert(accelerometerY >= 0); Debug.Assert(accelerometerY <= 1023); int accelerometerZ = (report[53] << 8) | (report[54] << 0); //0-1023 Debug.Assert(accelerometerZ >= 0); Debug.Assert(accelerometerZ <= 1023); int gyrometerX = (report[55] << 8) | (report[56] << 0); //0-1023 Debug.Assert(gyrometerX >= 0); Debug.Assert(gyrometerX <= 1023); accelerometerX -= 512; accelerometerY -= 512; accelerometerZ -= 512; gyrometerX -= 498; const int g1Value = 115; int forceVectror = (int) Math.Sqrt(accelerometerX * accelerometerX + accelerometerY * accelerometerY + accelerometerZ * accelerometerZ); // http://www.instructables.com/id/Accelerometer-Gyro-Tutorial/ //TODO: use Kalman filter double yaw = 0; double pitch = (Math.Atan2(accelerometerZ, accelerometerY) + Math.PI / 2) / Math.PI * 180; double roll = (Math.Atan2(accelerometerZ, accelerometerX) + Math.PI / 2) / Math.PI * 180; accelerometerX -= (accelerometerX * g1Value) / forceVectror; accelerometerY -= (accelerometerY * g1Value) / forceVectror; accelerometerZ -= (accelerometerZ * g1Value) / forceVectror; //Debug.Print($"Ax {accelerometerX:+0000;-0000} Ay {accelerometerY:+0000;-0000} Az {accelerometerZ:+0000;-0000} Pitch {pitch} Roll {roll} Gx {gyrometerX:+0000;-0000}"); inputReport.MotionMutable = new DsAccelerometer() { X = (short)(accelerometerX), Y = (short)(accelerometerY), Z = (short)(accelerometerZ), }; inputReport.OrientationMutable = new DsGyroscope() { Yaw = (short)(yaw), Pitch = (short)(pitch), Roll = (short)(roll) }; }
//input public static void ParseDs4(byte[] report, HidReport.Core.HidReport inputReport) { inputReport.BatteryStatus = (DsBattery)((byte)((report[38] + 2) / 2)); var val = (uint)report[13] & 0xF; ParseDPad(val, inputReport); inputReport.Set(ButtonsEnum.Square, IsBitSet(report[13], 4)); inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[13], 5)); inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[13], 6)); inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[13], 7)); inputReport.Set(ButtonsEnum.L1, IsBitSet(report[14], 0)); inputReport.Set(ButtonsEnum.R1, IsBitSet(report[14], 1)); inputReport.Set(ButtonsEnum.L2, IsBitSet(report[14], 2)); inputReport.Set(ButtonsEnum.R2, IsBitSet(report[14], 3)); inputReport.Set(ButtonsEnum.Share, IsBitSet(report[14], 4)); inputReport.Set(ButtonsEnum.Options, IsBitSet(report[14], 5)); inputReport.Set(ButtonsEnum.L3, IsBitSet(report[14], 6)); inputReport.Set(ButtonsEnum.R3, IsBitSet(report[14], 7)); inputReport.Set(ButtonsEnum.Ps, IsBitSet(report[15], 0)); inputReport.Set(ButtonsEnum.Touchpad, IsBitSet(report[15], 1)); inputReport.Set(AxesEnum.Lx, report[9]); inputReport.Set(AxesEnum.Ly, report[10]); inputReport.Set(AxesEnum.Rx, report[11]); inputReport.Set(AxesEnum.Ry, report[12]); inputReport.Set(AxesEnum.L2, report[16]); inputReport.Set(AxesEnum.R2, report[17]); inputReport.MotionMutable = new DsAccelerometer() { Y = (short)((report[22] << 8) | report[21]), X = (short)-((report[24] << 8) | report[23]), Z = (short)-((report[26] << 8) | report[25]) }; inputReport.OrientationMutable = new DsGyroscope() { Roll = (short)-((report[28] << 8) | report[27]), Yaw = (short)((report[30] << 8) | report[29]), Pitch = (short)((report[32] << 8) | report[31]) }; inputReport.TrackPadTouch0Mutable = new DsTrackPadTouch() { Id = report[43] & 0x7f, IsActive = report[43] >> 7 == 0, X = ((report[45] & 0x0f) << 8) | report[44], Y = report[46] << 4 | ((report[45] & 0xf0) >> 4) }; inputReport.TrackPadTouch1Mutable = new DsTrackPadTouch() { Id = report[47] & 0x7f, IsActive = report[47] >> 7 == 0, X = ((report[49] & 0x0f) << 8) | report[48], Y = report[50] << 4 | ((report[49] & 0xf0) >> 4) }; }
protected override void ParseHidReport(byte[] report) { if (report[26] != 0x02) { return; } PacketCounter++; var inputReport = new HidReport.Core.HidReport(); #region HID Report translation // battery inputReport.BatteryStatus = (DsBattery)report[30]; // packet counter inputReport.PacketCounter = PacketCounter; // control buttons inputReport.Set(ButtonsEnum.Ps, IsBitSet(report[1], 4)); inputReport.Set(ButtonsEnum.Select, IsBitSet(report[1], 0)); inputReport.Set(ButtonsEnum.Start, IsBitSet(report[1], 1)); // Left shoulder inputReport.Set(ButtonsEnum.L1, IsBitSet(report[0], 4)); inputReport.Set(AxesEnum.L1, report[15]); // Right shoulder inputReport.Set(ButtonsEnum.R1, IsBitSet(report[0], 5)); inputReport.Set(AxesEnum.R1, report[16]); // Left trigger inputReport.Set(ButtonsEnum.L2, IsBitSet(report[0], 6)); inputReport.Set(AxesEnum.L2, report[17]); // Right trigger inputReport.Set(ButtonsEnum.R2, IsBitSet(report[0], 7)); inputReport.Set(AxesEnum.R2, report[18]); // Triangle inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[0], 3)); inputReport.Set(AxesEnum.Triangle, report[11]); // Circle inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[0], 2)); inputReport.Set(AxesEnum.Circle, report[12]); // Cross inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[0], 1)); inputReport.Set(AxesEnum.Cross, report[13]); // Square inputReport.Set(ButtonsEnum.Square, IsBitSet(report[0], 0)); inputReport.Set(AxesEnum.Square, report[14]); // Left thumb inputReport.Set(ButtonsEnum.L3, IsBitSet(report[1], 2)); // Right thumb inputReport.Set(ButtonsEnum.R3, IsBitSet(report[1], 3)); // D-Pad if (report[2] != 0x0F) { HidParsers.ParseDPad(report[2], inputReport); } // Left thumb stick inputReport.Set(AxesEnum.Lx, report[3]); inputReport.Set(AxesEnum.Ly, report[4]); // Right thumb stick inputReport.Set(AxesEnum.Rx, report[5]); inputReport.Set(AxesEnum.Ry, report[6]); #endregion OnHidReportReceived(inputReport); }
protected override void ParseHidReport(byte[] report) { if (report[7] != 0x00) { return; } if (PacketCounter++ + 1 < PacketCounter) { Log.WarnFormat("Packet counter rolled over ({0}), resetting to 0", PacketCounter); PacketCounter = 0; } var inputReport = new HidReport.Core.HidReport(); #region HID Report translation // no battery state since the Gamepad is Usb-powered inputReport.BatteryStatus = DsBattery.None; // packet counter inputReport.PacketCounter = PacketCounter; inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[5], 5)); inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[5], 6)); inputReport.Set(ButtonsEnum.Select, IsBitSet(report[6], 4)); inputReport.Set(ButtonsEnum.Start, IsBitSet(report[6], 5)); var dPad = (byte)(report[5] & ~0xF0); HidParsers.ParseDPad(dPad, inputReport); inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[5], 4)); inputReport.Set(ButtonsEnum.Square, IsBitSet(report[5], 7)); inputReport.Set(ButtonsEnum.L1, IsBitSet(report[6], 0)); inputReport.Set(ButtonsEnum.R1, IsBitSet(report[6], 1)); inputReport.Set(ButtonsEnum.L2, IsBitSet(report[6], 2)); inputReport.Set(ButtonsEnum.R2, IsBitSet(report[6], 3)); inputReport.Set(ButtonsEnum.L3, IsBitSet(report[6], 6)); inputReport.Set(ButtonsEnum.R3, IsBitSet(report[6], 7)); inputReport.Set(AxesEnum.Lx, report[3]); inputReport.Set(AxesEnum.Ly, report[4]); inputReport.Set(AxesEnum.Rx, report[1]); inputReport.Set(AxesEnum.Ry, report[2]); #endregion OnHidReportReceived(inputReport); }
protected override void ParseHidReport(byte[] report) { if (report[8] != 0xC0 && report[8] != 0x40) { return; } PacketCounter++; var inputReport = new HidReport.Core.HidReport(); #region HID Report translation // no battery state since the Gamepad is Usb-powered inputReport.BatteryStatus = DsBattery.None; // packet counter inputReport.PacketCounter = PacketCounter; // reset buttons // buttons equaly reported in both modes inputReport.Set(ButtonsEnum.Circle, IsBitSet(report[6], 5)); inputReport.Set(ButtonsEnum.Cross, IsBitSet(report[6], 6)); inputReport.Set(ButtonsEnum.Triangle, IsBitSet(report[6], 4)); inputReport.Set(ButtonsEnum.Square, IsBitSet(report[6], 7)); inputReport.Set(ButtonsEnum.Select, IsBitSet(report[7], 4)); inputReport.Set(ButtonsEnum.Start, IsBitSet(report[7], 5)); inputReport.Set(ButtonsEnum.L1, IsBitSet(report[7], 0)); inputReport.Set(ButtonsEnum.R1, IsBitSet(report[7], 1)); inputReport.Set(ButtonsEnum.L2, IsBitSet(report[7], 2)); inputReport.Set(ButtonsEnum.R2, IsBitSet(report[7], 3)); inputReport.Set(ButtonsEnum.L3, IsBitSet(report[7], 6)); inputReport.Set(ButtonsEnum.R3, IsBitSet(report[7], 7)); // detect mode it's running in switch (report[8]) { case 0xC0: // mode 1 { inputReport.Set(ButtonsEnum.Up, (report[2] == 0x00)); inputReport.Set(ButtonsEnum.Right, (report[1] == 0xFF)); inputReport.Set(ButtonsEnum.Down, (report[2] == 0xFF)); inputReport.Set(ButtonsEnum.Left, (report[1] == 0x00)); // mode 1 doesn't report the thumb sticks inputReport.Set(AxesEnum.Lx, 0x80); inputReport.Set(AxesEnum.Ly, 0x80); inputReport.Set(AxesEnum.Rx, 0x80); inputReport.Set(AxesEnum.Ry, 0x80); } break; case 0x40: // mode 2 { var dPad = (byte)(report[6] & ~0xF0); HidParsers.ParseDPad(dPad, inputReport); inputReport.Set(AxesEnum.Lx, report[1]); inputReport.Set(AxesEnum.Ly, report[2]); inputReport.Set(AxesEnum.Rx, report[4]); inputReport.Set(AxesEnum.Ry, report[5]); } break; } #endregion OnHidReportReceived(inputReport); }