internal DsPacket(Byte[] Native) { Byte[] Local = new Byte[6]; Array.Copy(Native, (Int32)DsOffset.Address, Local, 0, Local.Length); m_Detail = new DsDetail( (DsPadId)Native[(Int32)DsOffset.Pad], (DsState)Native[(Int32)DsOffset.State], (DsModel)Native[(Int32)DsOffset.Model], Local, (DsConnection)Native[(Int32)DsOffset.Connection], (DsBattery)Native[(Int32)DsOffset.Battery] ); m_Packet = (Int32)(Native[4] << 0 | Native[5] << 8 | Native[6] << 16 | Native[7] << 24); m_Native = Native; switch (m_Detail.Model) { case DsModel.DS3: m_Ds3Button = (Ds3Button)((Native[10] << 0) | (Native[11] << 8) | (Native[12] << 16) | (Native[13] << 24)); break; case DsModel.DS4: m_Ds4Button = (Ds4Button)((Native[13] << 0) | (Native[14] << 8) | ((Native[15] & 0x03) << 16)); break; } }
internal DsPacket Load(byte[] Native) { Array.Copy(Native, (int)DsOffset.Address, m_Local, 0, m_Local.Length); m_Detail.Load( (DsPadId)Native[(int)DsOffset.Pad], (DsState)Native[(int)DsOffset.State], (DsModel)Native[(int)DsOffset.Model], m_Local, (DsConnection)Native[(int)DsOffset.Connection], (DsBattery)Native[(int)DsOffset.Battery] ); m_Packet = Native[4] << 0 | Native[5] << 8 | Native[6] << 16 | Native[7] << 24; Array.Copy(Native, m_Native, m_Native.Length); switch (m_Detail.Model) { case DsModel.DS3: m_Ds3Button = (Ds3Button)((Native[10] << 0) | (Native[11] << 8) | (Native[12] << 16) | (Native[13] << 24)); break; case DsModel.DS4: m_Ds4Button = (Ds4Button)((Native[13] << 0) | (Native[14] << 8) | ((Native[15] & 0x03) << 16)); break; } return(this); }
internal void Remapped() { switch (m_Detail.Model) { case DsModel.DS3: m_Ds3Button = (Ds3Button)((Native[10] << 0) | (Native[11] << 8) | (Native[12] << 16) | (Native[13] << 24)); break; } }
public Boolean Button(Ds3Button Flag) { if (m_Detail.Model != DsModel.DS3) { throw new InvalidEnumArgumentException(); } return(m_Ds3Button.HasFlag(Flag)); }
protected override void Parse(Byte[] Report) { if (Report[0] != 0x01) { return; } m_Packet++; m_ReportArgs.Report[2] = m_BatteryStatus = Report[30]; m_ReportArgs.Report[4] = (Byte)(m_Packet >> 0 & 0xFF); m_ReportArgs.Report[5] = (Byte)(m_Packet >> 8 & 0xFF); m_ReportArgs.Report[6] = (Byte)(m_Packet >> 16 & 0xFF); m_ReportArgs.Report[7] = (Byte)(m_Packet >> 24 & 0xFF); Ds3Button Buttons = (Ds3Button)((Report[2] << 0) | (Report[3] << 8) | (Report[4] << 16) | (Report[5] << 24)); Boolean Trigger = false; if ((Buttons & Ds3Button.L1) == Ds3Button.L1 && (Buttons & Ds3Button.R1) == Ds3Button.R1 && (Buttons & Ds3Button.PS) == Ds3Button.PS ) { Trigger = true; Report[4] ^= 0x1; } for (int Index = 8; Index < 57; Index++) { m_ReportArgs.Report[Index] = Report[Index - 8]; } if (Trigger && !m_IsDisconnect) { m_IsDisconnect = true; m_Disconnect = DateTime.Now; } else if (!Trigger && m_IsDisconnect) { m_IsDisconnect = false; } Publish(); }
public Ds3ButtonMap(Ds3Button Name, Ds3Button Value) { m_Name = Name; m_Value = Value; }
public virtual Boolean RemapDs3(Profile Map, Byte[] Input, Byte[] Output) { Boolean Mapped = false; try { Array.Copy(Input, Output, Input.Length); // Map Buttons Ds3Button In = (Ds3Button)(UInt32)((Input[10] << 0) | (Input[11] << 8) | (Input[12] << 16) | (Input[13] << 24)); Ds3Button Out = In; foreach (Ds3Button Item in Map.Ds3Button.Keys) { if ((Out & Item) != Ds3Button.None) { Out ^= Item; } } foreach (Ds3Button Item in Map.Ds3Button.Keys) { if ((In & Item) != Ds3Button.None) { Out |= Map.Ds3Button[Item]; } } Output[10] = (Byte)((UInt32)Out >> 0 & 0xFF); Output[11] = (Byte)((UInt32)Out >> 8 & 0xFF); Output[12] = (Byte)((UInt32)Out >> 16 & 0xFF); Output[13] = (Byte)((UInt32)Out >> 24 & 0xFF); // Map Axis foreach (Ds3Axis Item in Map.Ds3Axis.Keys) { switch (Item) { case Ds3Axis.LX: case Ds3Axis.LY: case Ds3Axis.RX: case Ds3Axis.RY: Output[(UInt32)Item] = 127; // Centred break; default: Output[(UInt32)Item] = 0; break; } } foreach (Ds3Axis Item in Map.Ds3Axis.Keys) { if (Map.Ds3Axis[Item] != Ds3Axis.None) { Output[(UInt32)Map.Ds3Axis[Item]] = Input[(UInt32)Item]; } } // Fix up Button-Axis Relations foreach (Ds3Button Key in Ds3ButtonAxis.Keys) { if ((Out & Key) != Ds3Button.None && Output[(UInt32)Ds3ButtonAxis[Key]] == 0) { Output[(UInt32)Ds3ButtonAxis[Key]] = 0xFF; } } Mapped = true; } catch { } return(Mapped); }
public virtual Boolean Construct(ref XmlDocument Map) { Boolean Constructed = true; try { XmlNode Node; XmlDocument Doc = new XmlDocument(); Node = Doc.CreateXmlDeclaration("1.0", "utf-8", String.Empty); Doc.AppendChild(Node); Node = Doc.CreateComment(String.Format(" ScpMapper Configuration Data. {0} ", DateTime.Now)); Doc.AppendChild(Node); Node = Doc.CreateNode(XmlNodeType.Element, "ScpMapper", null); { CreateTextNode(Doc, Node, "Description", "SCP Mapping File"); CreateTextNode(Doc, Node, "Version", Assembly.GetExecutingAssembly().GetName().Version.ToString()); XmlNode Mapping = Doc.CreateNode(XmlNodeType.Element, "Mapping", null); { foreach (Profile Item in m_Mapper.Values) { if (Item.Default) { CreateTextNode(Doc, Node, "Active", Item.Name); } XmlNode Profile = Doc.CreateNode(XmlNodeType.Element, "Profile", null); { CreateTextNode(Doc, Profile, "Name", Item.Name); CreateTextNode(Doc, Profile, "Type", Item.Type); CreateTextNode(Doc, Profile, "Value", Item.Qualifier); XmlNode Ds3 = Doc.CreateNode(XmlNodeType.Element, DsModel.DS3.ToString(), null); { XmlNode Button = Doc.CreateNode(XmlNodeType.Element, "Button", null); { foreach (Ds3Button Ds3Button in Item.Ds3Button.Keys) { CreateTextNode(Doc, Button, Ds3Button.ToString(), Item.Ds3Button[Ds3Button].ToString()); } } Ds3.AppendChild(Button); XmlNode Axis = Doc.CreateNode(XmlNodeType.Element, "Axis", null); { foreach (Ds3Axis Ds3Axis in Item.Ds3Axis.Keys) { CreateTextNode(Doc, Axis, Ds3Axis.ToString(), Item.Ds3Axis[Ds3Axis].ToString()); } } Ds3.AppendChild(Axis); } Profile.AppendChild(Ds3); XmlNode Ds4 = Doc.CreateNode(XmlNodeType.Element, DsModel.DS4.ToString(), null); { XmlNode Button = Doc.CreateNode(XmlNodeType.Element, "Button", null); { foreach (Ds4Button Ds4Button in Item.Ds4Button.Keys) { CreateTextNode(Doc, Button, Ds4Button.ToString(), Item.Ds4Button[Ds4Button].ToString()); } } Ds4.AppendChild(Button); XmlNode Axis = Doc.CreateNode(XmlNodeType.Element, "Axis", null); { foreach (Ds4Axis Ds4Axis in Item.Ds4Axis.Keys) { CreateTextNode(Doc, Axis, Ds4Axis.ToString(), Item.Ds4Axis[Ds4Axis].ToString()); } } Ds4.AppendChild(Axis); } Profile.AppendChild(Ds4); } Mapping.AppendChild(Profile); } } Node.AppendChild(Mapping); } Doc.AppendChild(Node); Map = Doc; } catch { Constructed = false; } return(Constructed); }
public virtual Boolean Initialize(XmlDocument Map) { try { m_Remapping = false; m_Mapper.Clear(); XmlNode Node = Map.SelectSingleNode("/ScpMapper"); m_Description = Node.SelectSingleNode("Description").FirstChild.Value; m_Version = Node.SelectSingleNode("Version").FirstChild.Value; m_Active = Node.SelectSingleNode("Active").FirstChild.Value; foreach (XmlNode ProfileNode in Node.SelectNodes("Mapping/Profile")) { String Name = ProfileNode.SelectSingleNode("Name").FirstChild.Value; String Type = ProfileNode.SelectSingleNode("Type").FirstChild.Value; String Qualifier = String.Empty; try { XmlNode QualifierNode = ProfileNode.SelectSingleNode("Value"); if (QualifierNode.HasChildNodes) { Qualifier = QualifierNode.FirstChild.Value; } } catch { } Profile Profile = new Profile(Name == m_Active, Name, Type, Qualifier); try { foreach (XmlNode Mapping in ProfileNode.SelectSingleNode("DS3/Button")) { foreach (XmlNode Item in Mapping.ChildNodes) { Ds3Button Target = (Ds3Button)Enum.Parse(typeof(Ds3Button), Item.ParentNode.Name); Ds3Button Mapped = (Ds3Button)Enum.Parse(typeof(Ds3Button), Item.Value); Profile.Ds3Button[Target] = Mapped; } } } catch { } try { foreach (XmlNode Mapping in ProfileNode.SelectSingleNode("DS3/Axis")) { foreach (XmlNode Item in Mapping.ChildNodes) { Ds3Axis Target = (Ds3Axis)Enum.Parse(typeof(Ds3Axis), Item.ParentNode.Name); Ds3Axis Mapped = (Ds3Axis)Enum.Parse(typeof(Ds3Axis), Item.Value); Profile.Ds3Axis[Target] = Mapped; } } } catch { } try { foreach (XmlNode Mapping in ProfileNode.SelectSingleNode("DS4/Button")) { foreach (XmlNode Item in Mapping.ChildNodes) { Ds4Button Target = (Ds4Button)Enum.Parse(typeof(Ds4Button), Item.ParentNode.Name); Ds4Button Mapped = (Ds4Button)Enum.Parse(typeof(Ds4Button), Item.Value); Profile.Ds4Button[Target] = Mapped; } } } catch { } try { foreach (XmlNode Mapping in ProfileNode.SelectSingleNode("DS4/Axis")) { foreach (XmlNode Item in Mapping.ChildNodes) { Ds4Axis Target = (Ds4Axis)Enum.Parse(typeof(Ds4Axis), Item.ParentNode.Name); Ds4Axis Mapped = (Ds4Axis)Enum.Parse(typeof(Ds4Axis), Item.Value); Profile.Ds4Axis[Target] = Mapped; } } } catch { } m_Mapper[Profile.Name] = Profile; } Int32 Mappings = m_Mapper[m_Active].Ds3Button.Count + m_Mapper[m_Active].Ds3Axis.Count + m_Mapper[m_Active].Ds4Button.Count + m_Mapper[m_Active].Ds4Axis.Count; LogDebug(String.Format("## Mapper.Initialize() - Profiles [{0}] Active [{1}] Mappings [{2}]", m_Mapper.Count, m_Active, Mappings)); m_Remapping = true; } catch { } return(m_Remapping); }
public DSButton(Ds3Button parDs3Button, Ds4Button parDs4Button) { m_DS3 = parDs3Button; m_DS4 = parDs4Button; }
public override void Parse(Byte[] Report) { if (Report[10] == 0xFF) { return; } m_PlugStatus = Report[38]; m_BatteryStatus = Report[39]; m_CableStatus = Report[40]; if (m_Packet == 0) { Rumble(0, 0); } m_Packet++; m_ReportArgs.Report[2] = m_BatteryStatus; m_ReportArgs.Report[4] = (Byte)(m_Packet >> 0 & 0xFF); m_ReportArgs.Report[5] = (Byte)(m_Packet >> 8 & 0xFF); m_ReportArgs.Report[6] = (Byte)(m_Packet >> 16 & 0xFF); m_ReportArgs.Report[7] = (Byte)(m_Packet >> 24 & 0xFF); Ds3Button Buttons = (Ds3Button)((Report[11] << 0) | (Report[12] << 8) | (Report[13] << 16) | (Report[14] << 24)); Boolean Trigger = false, Active = false; // Quick Disconnect if ((Buttons & Ds3Button.L1) == Ds3Button.L1 && (Buttons & Ds3Button.R1) == Ds3Button.R1 && (Buttons & Ds3Button.PS) == Ds3Button.PS ) { Trigger = true; Report[13] ^= 0x1; } for (Int32 Index = 8; Index < 57; Index++) { m_ReportArgs.Report[Index] = Report[Index + 1]; } // Buttons for (Int32 Index = 11; Index < 15 && !Active; Index++) { if (Report[Index] != 0) { Active = true; } } // Axis for (Int32 Index = 15; Index < 19 && !Active; Index++) { if (Report[Index] < 117 || Report[Index] > 137) { Active = true; } } // Triggers & Pressure for (Int32 Index = 23; Index < 35 && !Active; Index++) { if (Report[Index] != 0) { Active = true; } } if (Active) { 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; } Publish(); }
internal DsPacket Load(byte[] Native) { Buffer.BlockCopy(Native, (int)DsOffset.Address, m_Local, 0, m_Local.Length); m_Detail.Load( (DsPadId)Native[(int)DsOffset.Pad], (DsState)Native[(int)DsOffset.State], (DsModel)Native[(int)DsOffset.Model], m_Local, (DsConnection)Native[(int)DsOffset.Connection], (DsBattery)Native[(int)DsOffset.Battery] ); m_Packet = Native[4] << 0 | Native[5] << 8 | Native[6] << 16 | Native[7] << 24; Array.Copy(Native, m_Native, m_Native.Length); switch (m_Detail.Model) { case DsModel.DS3: m_Ds3Button = (Ds3Button)((Native[10] << 0) | (Native[11] << 8) | (Native[12] << 16) | (Native[13] << 24)); break; case DsModel.DS4: m_Ds4Button = (Ds4Button)((Native[13] << 0) | (Native[14] << 8) | ((Native[15] & 0x03) << 16)); break; } return this; }
public bool Button(Ds3Button Flag) { if (m_Detail.Model != DsModel.DS3) throw new InvalidEnumArgumentException(); return m_Ds3Button.HasFlag(Flag); }
internal void Remapped() { switch (m_Detail.Model) { case DsModel.DS3: m_Ds3Button = (Ds3Button)((Native[10] << 0) | (Native[11] << 8) | (Native[12] << 16) | (Native[13] << 24)); break; case DsModel.DS4: m_Ds4Button = (Ds4Button)((Native[13] << 0) | (Native[14] << 8) | ((Native[15] & 0x03) << 16)); break; } }
public virtual Int32 Parse(Byte[] Input, Byte[] Output, DsModel Type = DsModel.DS3) { Int32 Serial = IndexToSerial(Input[0]); for (Int32 Index = 0; Index < ReportSize; Index++) { Output[Index] = 0x00; } Output[0] = 0x1C; Output[4] = (Byte)((Serial >> 0) & 0xFF); Output[5] = (Byte)((Serial >> 8) & 0xFF); Output[6] = (Byte)((Serial >> 16) & 0xFF); Output[7] = (Byte)((Serial >> 24) & 0xFF); Output[9] = 0x14; X360Button XButton = X360Button.None; if (Input[1] == 0x02) // Pad is active { switch (Type) { case DsModel.DS3: { Ds3Button Buttons = (Ds3Button)((Input[10] << 0) | (Input[11] << 8) | (Input[12] << 16) | (Input[13] << 24)); if (Buttons.HasFlag(Ds3Button.Select)) { XButton |= X360Button.Back; } if (Buttons.HasFlag(Ds3Button.Start)) { XButton |= X360Button.Start; } if (Buttons.HasFlag(Ds3Button.Up)) { XButton |= X360Button.Up; } if (Buttons.HasFlag(Ds3Button.Right)) { XButton |= X360Button.Right; } if (Buttons.HasFlag(Ds3Button.Down)) { XButton |= X360Button.Down; } if (Buttons.HasFlag(Ds3Button.Left)) { XButton |= X360Button.Left; } if (Buttons.HasFlag(Ds3Button.L1)) { XButton |= X360Button.LB; } if (Buttons.HasFlag(Ds3Button.R1)) { XButton |= X360Button.RB; } if (Buttons.HasFlag(Ds3Button.Triangle)) { XButton |= X360Button.Y; } if (Buttons.HasFlag(Ds3Button.Circle)) { XButton |= X360Button.B; } if (Buttons.HasFlag(Ds3Button.Cross)) { XButton |= X360Button.A; } if (Buttons.HasFlag(Ds3Button.Square)) { XButton |= X360Button.X; } if (Buttons.HasFlag(Ds3Button.PS)) { XButton |= X360Button.Guide; } if (Buttons.HasFlag(Ds3Button.L3)) { XButton |= X360Button.LS; } if (Buttons.HasFlag(Ds3Button.R3)) { XButton |= X360Button.RS; } Output[(UInt32)X360Axis.BT_Lo] = (Byte)((UInt32)XButton >> 0 & 0xFF); Output[(UInt32)X360Axis.BT_Hi] = (Byte)((UInt32)XButton >> 8 & 0xFF); Output[(UInt32)X360Axis.LT] = Input[(UInt32)Ds3Axis.L2]; Output[(UInt32)X360Axis.RT] = Input[(UInt32)Ds3Axis.R2]; if (!DeadZone(Global.DeadZoneL, Input[(UInt32)Ds3Axis.LX], Input[(UInt32)Ds3Axis.LY])) // Left Stick DeadZone { Int32 ThumbLX = +Scale(Input[(UInt32)Ds3Axis.LX], Global.FlipLX); Int32 ThumbLY = -Scale(Input[(UInt32)Ds3Axis.LY], Global.FlipLY); Output[(UInt32)X360Axis.LX_Lo] = (Byte)((ThumbLX >> 0) & 0xFF); // LX Output[(UInt32)X360Axis.LX_Hi] = (Byte)((ThumbLX >> 8) & 0xFF); Output[(UInt32)X360Axis.LY_Lo] = (Byte)((ThumbLY >> 0) & 0xFF); // LY Output[(UInt32)X360Axis.LY_Hi] = (Byte)((ThumbLY >> 8) & 0xFF); } if (!DeadZone(Global.DeadZoneR, Input[(UInt32)Ds3Axis.RX], Input[(UInt32)Ds3Axis.RY])) // Right Stick DeadZone { Int32 ThumbRX = +Scale(Input[(UInt32)Ds3Axis.RX], Global.FlipRX); Int32 ThumbRY = -Scale(Input[(UInt32)Ds3Axis.RY], Global.FlipRY); Output[(UInt32)X360Axis.RX_Lo] = (Byte)((ThumbRX >> 0) & 0xFF); // RX Output[(UInt32)X360Axis.RX_Hi] = (Byte)((ThumbRX >> 8) & 0xFF); Output[(UInt32)X360Axis.RY_Lo] = (Byte)((ThumbRY >> 0) & 0xFF); // RY Output[(UInt32)X360Axis.RY_Hi] = (Byte)((ThumbRY >> 8) & 0xFF); } } break; case DsModel.DS4: { Ds4Button Buttons = (Ds4Button)((Input[13] << 0) | (Input[14] << 8) | (Input[15] << 16)); if (Buttons.HasFlag(Ds4Button.Share)) { XButton |= X360Button.Back; } if (Buttons.HasFlag(Ds4Button.Options)) { XButton |= X360Button.Start; } if (Buttons.HasFlag(Ds4Button.Up)) { XButton |= X360Button.Up; } if (Buttons.HasFlag(Ds4Button.Right)) { XButton |= X360Button.Right; } if (Buttons.HasFlag(Ds4Button.Down)) { XButton |= X360Button.Down; } if (Buttons.HasFlag(Ds4Button.Left)) { XButton |= X360Button.Left; } if (Buttons.HasFlag(Ds4Button.L1)) { XButton |= X360Button.LB; } if (Buttons.HasFlag(Ds4Button.R1)) { XButton |= X360Button.RB; } if (Buttons.HasFlag(Ds4Button.Triangle)) { XButton |= X360Button.Y; } if (Buttons.HasFlag(Ds4Button.Circle)) { XButton |= X360Button.B; } if (Buttons.HasFlag(Ds4Button.Cross)) { XButton |= X360Button.A; } if (Buttons.HasFlag(Ds4Button.Square)) { XButton |= X360Button.X; } if (Buttons.HasFlag(Ds4Button.PS)) { XButton |= X360Button.Guide; } if (Buttons.HasFlag(Ds4Button.L3)) { XButton |= X360Button.LS; } if (Buttons.HasFlag(Ds4Button.R3)) { XButton |= X360Button.RS; } Output[(UInt32)X360Axis.BT_Lo] = (Byte)((UInt32)XButton >> 0 & 0xFF); Output[(UInt32)X360Axis.BT_Hi] = (Byte)((UInt32)XButton >> 8 & 0xFF); Output[(UInt32)X360Axis.LT] = Input[(UInt32)Ds4Axis.L2]; Output[(UInt32)X360Axis.RT] = Input[(UInt32)Ds4Axis.R2]; if (!DeadZone(Global.DeadZoneL, Input[(UInt32)Ds4Axis.LX], Input[(UInt32)Ds4Axis.LY])) // Left Stick DeadZone { Int32 ThumbLX = +Scale(Input[(UInt32)Ds4Axis.LX], Global.FlipLX); Int32 ThumbLY = -Scale(Input[(UInt32)Ds4Axis.LY], Global.FlipLY); Output[(UInt32)X360Axis.LX_Lo] = (Byte)((ThumbLX >> 0) & 0xFF); // LX Output[(UInt32)X360Axis.LX_Hi] = (Byte)((ThumbLX >> 8) & 0xFF); Output[(UInt32)X360Axis.LY_Lo] = (Byte)((ThumbLY >> 0) & 0xFF); // LY Output[(UInt32)X360Axis.LY_Hi] = (Byte)((ThumbLY >> 8) & 0xFF); } if (!DeadZone(Global.DeadZoneR, Input[(UInt32)Ds4Axis.RX], Input[(UInt32)Ds4Axis.RY])) // Right Stick DeadZone { Int32 ThumbRX = +Scale(Input[(UInt32)Ds4Axis.RX], Global.FlipRX); Int32 ThumbRY = -Scale(Input[(UInt32)Ds4Axis.RY], Global.FlipRY); Output[(UInt32)X360Axis.RX_Lo] = (Byte)((ThumbRX >> 0) & 0xFF); // RX Output[(UInt32)X360Axis.RX_Hi] = (Byte)((ThumbRX >> 8) & 0xFF); Output[(UInt32)X360Axis.RY_Lo] = (Byte)((ThumbRY >> 0) & 0xFF); // RY Output[(UInt32)X360Axis.RY_Hi] = (Byte)((ThumbRY >> 8) & 0xFF); } } break; } } return(Input[0]); }