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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace grapher
{
public partial class RawAcceleration : Form
{
#region Constructor
public RawAcceleration()
{
InitializeComponent();
ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15);
AccelerationType = 5;
Sensitivity = new VectorXY(1);
Rotation = 0;
Weight = new VectorXY(1);
Cap = new VectorXY(0);
Offset = 0;
Acceleration = 0;
LimitOrExponent = 1.01;
Midpoint = 0;
UpdateGraph();
this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues();
this.AccelerationChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01;
this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001;
this.AccelerationChart.ChartAreas[0].CursorY.Interval = 0.001;
this.AccelerationChart.ChartAreas[0].CursorX.AutoScroll = true;
this.AccelerationChart.ChartAreas[0].CursorY.AutoScroll = true;
this.AccelerationChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
this.AccelerationChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true;
this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true;
}
#endregion Constructor
#region Properties
public ManagedAccel ManagedAcceleration { get; set; }
private int AccelerationType { get; set; }
private VectorXY Sensitivity { get; set; }
private double Rotation { get; set; }
private VectorXY Weight { get; set; }
private VectorXY Cap { get; set; }
private double Offset { get; set; }
private double Acceleration { get; set; }
private double LimitOrExponent { get; set; }
private double Midpoint { get; set; }
#endregion Properties
#region Methods
public static double Magnitude(int x, int y)
{
return Math.Sqrt(x * x + y * y);
}
public static double Magnitude(double x, double y)
{
return Math.Sqrt(x * x + y * y);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void UpdateGraph()
{
var orderedPoints = new SortedDictionary<double, double>();
for (int i = 0; i < 100; i++)
{
for (int j = 0; j <= i; j++)
{
var output = ManagedAcceleration.Accelerate(i, j, 1);
var inMagnitude = Magnitude(i,j);
var outMagnitude = Magnitude(output.Item1, output.Item2);
var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.X;
if (!orderedPoints.ContainsKey(inMagnitude))
{
orderedPoints.Add(inMagnitude, ratio);
}
}
}
var series = this.AccelerationChart.Series.FirstOrDefault();
series.Points.Clear();
foreach (var point in orderedPoints)
{
series.Points.AddXY(point.Key, point.Value);
}
}
private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data)
{
bool validEntry = false;
data = 0.0;
if (e.KeyCode == Keys.Enter)
{
try
{
data = Convert.ToDouble(((TextBox)sender).Text);
validEntry = true;
}
catch
{
}
e.Handled = true;
e.SuppressKeyPress = true;
}
return validEntry;
}
private void writeButton_Click(object sender, EventArgs e)
{
ManagedAcceleration.UpdateAccel(
AccelerationType,
Sensitivity.X,
Sensitivity.Y,
Weight.X,
Weight.Y,
Cap.X,
Cap.Y,
Offset,
Acceleration,
LimitOrExponent,
Midpoint);
ManagedAcceleration.WriteToDriver();
UpdateGraph();
}
private void sensitivityBox_KeyDown(object sender, KeyEventArgs e)
{
if (TryHandleWithEnter(e, sender, out double data))
{
Sensitivity.SetBoth(data);
}
}
private void accelerationBox_KeyDown(object sender, KeyEventArgs e)
{
if (TryHandleWithEnter(e, sender, out double data))
{
Acceleration = data;
}
}
private void rotationBox_KeyDown(object sender, KeyEventArgs e)
{
if (TryHandleWithEnter(e, sender, out double data))
{
Rotation = data;
}
}
private void capBox_KeyDown(object sender, KeyEventArgs e)
{
if (TryHandleWithEnter(e, sender, out double data))
{
Cap.SetBoth(data);
}
}
private void offsetBox_KeyDown(object sender, KeyEventArgs e)
{
if (TryHandleWithEnter(e, sender, out double data))
{
Offset = data;
}
}
private void limitBox_KeyDown(object sender, KeyEventArgs e)
{
if (TryHandleWithEnter(e, sender, out double data))
{
LimitOrExponent = data;
}
}
private void midpointBox_KeyDown(object sender, KeyEventArgs e)
{
if (TryHandleWithEnter(e, sender, out double data))
{
Midpoint = data;
}
}
#endregion Methods
public class VectorXY
{
public VectorXY(double x)
{
X = x;
Y = x;
}
public VectorXY(double x, double y)
{
X = x;
Y = y;
}
public double X { get; set; }
public double Y { get; set; }
public void SetBoth(double value)
{
X = value;
Y = value;
}
}
}
}
|