private void ReportingThreadLoop(x360device device) { byte[] Report = new byte[28]; byte[] Rumble = new byte[8]; while (!Global.IsShuttingDown) { Thread.Sleep(1); SC360Globals.scBus.Parse(device, Report, ControllerID); if (SC360Globals.scBus.Report(Report, Rumble)) { if (Rumble[1] == 0x08) { device.SmallRumble.Value = Rumble[3] / 255d; device.BigRumble.Value = Rumble[4] / 255d; } } } }
public SC360_Device_Plugin(int device, SettingGroup settings) { ControllerID = device; this.settings = settings; this.StatusIcon = new BitmapImage(new Uri(@"pack://application:,,,/SC360;component/Resources/360.ico")); this.DeviceName = "Controller " + ControllerID; x360device myDevice = new x360device(); InputChannels.Add(myDevice.LSx); InputChannels.Add(myDevice.LSy); InputChannels.Add(myDevice.RSx); InputChannels.Add(myDevice.RSy); InputChannels.Add(myDevice.LS); InputChannels.Add(myDevice.RS); InputChannels.Add(myDevice.LT); InputChannels.Add(myDevice.RT); InputChannels.Add(myDevice.LB); InputChannels.Add(myDevice.RB); InputChannels.Add(myDevice.DUp); InputChannels.Add(myDevice.DDown); InputChannels.Add(myDevice.DLeft); InputChannels.Add(myDevice.DRight); InputChannels.Add(myDevice.A); InputChannels.Add(myDevice.B); InputChannels.Add(myDevice.X); InputChannels.Add(myDevice.Y); InputChannels.Add(myDevice.Start); InputChannels.Add(myDevice.Back); InputChannels.Add(myDevice.Guide); OutputChannels.Add(myDevice.SmallRumble); OutputChannels.Add(myDevice.BigRumble); if (SC360Globals.scBus.Open() && SC360Globals.scBus.Start()) { SC360Globals.scBus.Plugin(device); if (settings.getSetting("Low latency mode")) { byte[] Report = new byte[28]; byte[] Rumble = new byte[8]; foreach (DeviceChannel channel in InputChannels) { channel.PropertyChanged += (s, e) => { SC360Globals.scBus.Parse(myDevice, Report, ControllerID); if (SC360Globals.scBus.Report(Report, Rumble)) { // if (Rumble[1] == 0x08) // { // myDevice.SmallRumble.Value = Rumble[3]; // myDevice.BigRumble.Value = Rumble[4]; // } } }; } } else { ReportingThread = new Thread(() => ReportingThreadLoop(myDevice)); ReportingThread.Start(); } } }
internal void Parse(x360device Data, Byte[] Output, int device) { Output[0] = 0x1C; Output[4] = (Byte)(device + firstController); Output[9] = 0x14; for (int i = 10; i < Output.Length; i++) { Output[i] = 0; } if (Data.Back.Value) { Output[10] |= (Byte)(1 << 5); // Back } if (Data.LS.Value) { Output[10] |= (Byte)(1 << 6); // Left Thumb } if (Data.RS.Value) { Output[10] |= (Byte)(1 << 7); // Right Thumb } if (Data.Start.Value) { Output[10] |= (Byte)(1 << 4); // Start } if (Data.DUp.Value) { Output[10] |= (Byte)(1 << 0); // Up } if (Data.DRight.Value) { Output[10] |= (Byte)(1 << 3); // Down } if (Data.DDown.Value) { Output[10] |= (Byte)(1 << 1); // Right } if (Data.DLeft.Value) { Output[10] |= (Byte)(1 << 2); // Left } if (Data.LB.Value) { Output[11] |= (Byte)(1 << 0); // Left Shoulder } if (Data.RB.Value) { Output[11] |= (Byte)(1 << 1); // Right Shoulder } if (Data.Y.Value) { Output[11] |= (Byte)(1 << 7); // Y } if (Data.B.Value) { Output[11] |= (Byte)(1 << 5); // B } if (Data.A.Value) { Output[11] |= (Byte)(1 << 4); // A } if (Data.X.Value) { Output[11] |= (Byte)(1 << 6); // X } if (Data.Guide.Value) { Output[11] |= (Byte)(1 << 2); // Guide } Output[12] = (byte)Math.Floor(Convert.ToDouble(Data.LT.Value) * 255); Output[13] = (byte)Math.Floor(Convert.ToDouble(Data.RT.Value) * 255); Int32 ThumbLX = (int)Math.Floor(Convert.ToDouble(Data.LSx.Value) * 32512); Int32 ThumbLY = (int)Math.Floor(Convert.ToDouble(Data.LSy.Value) * -32512); Int32 ThumbRX = (int)Math.Floor(Convert.ToDouble(Data.RSx.Value) * 32512); Int32 ThumbRY = (int)Math.Floor(Convert.ToDouble(Data.RSy.Value) * -32512); Output[14] = (Byte)((ThumbLX >> 0) & 0xFF); // LX Output[15] = (Byte)((ThumbLX >> 8) & 0xFF); Output[16] = (Byte)((ThumbLY >> 0) & 0xFF); // LY Output[17] = (Byte)((ThumbLY >> 8) & 0xFF); Output[18] = (Byte)((ThumbRX >> 0) & 0xFF); // RX Output[19] = (Byte)((ThumbRX >> 8) & 0xFF); Output[20] = (Byte)((ThumbRY >> 0) & 0xFF); // RY Output[21] = (Byte)((ThumbRY >> 8) & 0xFF); }