-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathXmlMapper.cs
223 lines (176 loc) · 6.78 KB
/
XmlMapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Reflection;
namespace ScpControl
{
public partial class XmlMapper : Component
{
public event EventHandler<DebugEventArgs> Debug = null;
protected virtual void LogDebug(String Data)
{
DebugEventArgs args = new DebugEventArgs(Data);
if (Debug != null)
{
Debug(this, args);
}
}
protected Profile m_Empty = new Profile(true, DsMatch.None.ToString(), DsMatch.Global.ToString(), String.Empty);
protected ProfileMap m_Mapper = new ProfileMap();
protected Ds3ButtonAxisMap Ds3ButtonAxis = new Ds3ButtonAxisMap();
protected volatile Boolean m_Remapping = false;
protected volatile String m_Active = String.Empty, m_Version = String.Empty, m_Description = String.Empty;
protected Profile Find(String Mac, Int32 PadId)
{
Profile Found = m_Empty;
String Pad = ((DsPadId) PadId).ToString();
DsMatch Current = DsMatch.None, Target = DsMatch.None;
foreach(Profile Item in m_Mapper.Values)
{
Target = Item.Usage(Pad, Mac);
if (Target > Current)
{
Found = Item; Current = Target;
}
}
return Found;
}
public XmlMapper()
{
InitializeComponent();
Ds3ButtonAxis[Ds3Button.L1 ] = Ds3Axis.L1;
Ds3ButtonAxis[Ds3Button.L2 ] = Ds3Axis.L2;
Ds3ButtonAxis[Ds3Button.R1 ] = Ds3Axis.R1;
Ds3ButtonAxis[Ds3Button.R2 ] = Ds3Axis.R2;
Ds3ButtonAxis[Ds3Button.Triangle] = Ds3Axis.Triangle;
Ds3ButtonAxis[Ds3Button.Circle ] = Ds3Axis.Circle;
Ds3ButtonAxis[Ds3Button.Cross ] = Ds3Axis.Cross;
Ds3ButtonAxis[Ds3Button.Square ] = Ds3Axis.Square;
Ds3ButtonAxis[Ds3Button.Up ] = Ds3Axis.Up;
Ds3ButtonAxis[Ds3Button.Right ] = Ds3Axis.Right;
Ds3ButtonAxis[Ds3Button.Down ] = Ds3Axis.Down;
Ds3ButtonAxis[Ds3Button.Left ] = Ds3Axis.Left;
}
public XmlMapper(IContainer container)
{
container.Add(this);
InitializeComponent();
Ds3ButtonAxis[Ds3Button.L1 ] = Ds3Axis.L1;
Ds3ButtonAxis[Ds3Button.L2 ] = Ds3Axis.L2;
Ds3ButtonAxis[Ds3Button.R1 ] = Ds3Axis.R1;
Ds3ButtonAxis[Ds3Button.R2 ] = Ds3Axis.R2;
Ds3ButtonAxis[Ds3Button.Triangle] = Ds3Axis.Triangle;
Ds3ButtonAxis[Ds3Button.Circle ] = Ds3Axis.Circle;
Ds3ButtonAxis[Ds3Button.Cross ] = Ds3Axis.Cross;
Ds3ButtonAxis[Ds3Button.Square ] = Ds3Axis.Square;
Ds3ButtonAxis[Ds3Button.Up ] = Ds3Axis.Up;
Ds3ButtonAxis[Ds3Button.Right ] = Ds3Axis.Right;
Ds3ButtonAxis[Ds3Button.Down ] = Ds3Axis.Down;
Ds3ButtonAxis[Ds3Button.Left ] = Ds3Axis.Left;
}
public virtual Boolean Initialize()
{
return false; //TODO: Clean this up
}
public virtual Boolean Shutdown()
{
m_Remapping = false;
LogDebug("## Mapper.Shutdown()");
return true;
}
public virtual Boolean Construct()
{
Boolean Constructed = true;
return Constructed;
}
public virtual Boolean Remap(DsModel Type, Int32 Pad, String Mac, Byte[] Input, Byte[] Output)
{
Boolean Mapped = false;
try
{
if (m_Remapping)
{
switch (Type)
{
case DsModel.DS3: Mapped = RemapDs3(Find(Mac, Pad), Input, Output); break;
}
}
}
catch { }
return Mapped;
}
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 String[] Profiles
{
get
{
Int32 Index = 0;
String[] List = new String[m_Mapper.Count];
foreach (String Item in m_Mapper.Keys)
{
List[Index++] = Item;
}
return List;
}
}
public virtual String Active
{
get { return m_Active; }
}
public virtual ProfileMap Map
{
get { return m_Mapper; }
}
}
}