-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
210 lines (181 loc) · 6.23 KB
/
MainWindow.xaml.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
using NITHlibrary.Tools.Ports;
using NITHtester.Elements;
using NITHtester.Modules;
using NITHtester.Setups;
using System.Windows;
using System.Windows.Controls;
namespace NITHtester
{
/// <summary>
/// Interaction logic for the instrument window
/// </summary>
public partial class MainWindow : Window
{
private bool isSetup = false;
private ISetup Setup;
public MainWindow()
{
InitializeComponent();
}
public List<ComboBox> GaugesList { get; set; }
private SupportedPortTypes PortType { get; set; } = SupportedPortTypes.USB;
private void btnConnect_Click(object sender, RoutedEventArgs e)
{
if (IsConnected())
{
DisconnectAll();
}
else
{
switch (PortType)
{
case SupportedPortTypes.USB:
Rack.USBreceiver.Connect();
break;
case SupportedPortTypes.UDP:
Rack.UDPreceiver.Connect();
break;
}
}
UpdateIndicators();
}
private void btnPause_Click(object sender, RoutedEventArgs e)
{
Rack.Paused = !Rack.Paused;
if (Rack.Paused)
{
Rack.RenderingModule.StopRendering();
}
else
{
Rack.RenderingModule.StartRendering();
}
UpdateIndicators();
}
private void btnUSBPortMinus_Click(object sender, RoutedEventArgs e)
{
DisconnectAll();
Rack.USBreceiver.Port--;
UpdateIndicators();
}
private void btnUSBPortPlus_Click(object sender, RoutedEventArgs e)
{
DisconnectAll();
Rack.USBreceiver.Port++;
UpdateIndicators();
}
private void btnUSBPortScan_Click(object sender, RoutedEventArgs e)
{
if (PortType == SupportedPortTypes.USB)
{
Rack.PortDetector.Scan();
}
}
private void DisconnectAll()
{
Rack.USBreceiver?.Disconnect();
Rack.UDPreceiver?.Disconnect();
}
private void InitializeGauges()
{
Rack.BindableGauge1 = new BindableGauge(prbGauge1, lstGauge1, txtMinGauge1, txtMaxGauge1, txtOffGauge1, chkProp1, txtFilterAlpha1);
Rack.BindableGauge2 = new BindableGauge(prbGauge2, lstGauge2, txtMinGauge2, txtMaxGauge2, txtOffGauge2, chkProp2, txtFilterAlpha2);
Rack.BindableGauge3 = new BindableGauge(prbGauge3, lstGauge3, txtMinGauge3, txtMaxGauge3, txtOffGauge3, chkProp3, txtFilterAlpha3);
Rack.BindableGauge4 = new BindableGauge(prbGauge4, lstGauge4, txtMinGauge4, txtMaxGauge4, txtOffGauge4, chkProp4, txtFilterAlpha4);
Rack.BindableGauge5 = new BindableGauge(prbGauge5, lstGauge5, txtMinGauge5, txtMaxGauge5, txtOffGauge5, chkProp5, txtFilterAlpha5);
Rack.BindableGauges = new List<BindableGauge>
{
Rack.BindableGauge1,
Rack.BindableGauge2,
Rack.BindableGauge3,
Rack.BindableGauge4,
Rack.BindableGauge5,
};
}
private void InitializeHeadTrackerPlotter()
{
Rack.HeadTrackerPlotter = new HeadTrackerPlotter(
cnvHeadTrackerPlot,
chkHTenabled,
txtHTyawMultiplier,
txtHTpitchMultiplier,
txtHTrollMultiplier,
btnHTcalibrate,
txtHTrawPosition,
txtHTrawAccel,
cbxHTargBind,
dotPitchYaw,
dotPitchRoll,
txtHTfilterAlpha);
}
private bool IsConnected()
{
bool connected = false;
switch (PortType)
{
case SupportedPortTypes.USB:
connected = Rack.USBreceiver.IsConnected;
break;
case SupportedPortTypes.UDP:
connected = Rack.UDPreceiver.IsConnected;
break;
}
return connected;
}
private void rbtUDP_Checked(object sender, RoutedEventArgs e)
{
DisconnectAll();
PortType = SupportedPortTypes.UDP;
}
private void rbtUSB_Checked(object sender, RoutedEventArgs e)
{
DisconnectAll();
PortType = SupportedPortTypes.USB;
}
private void TxtUDPPort_OnTextChanged(object sender, TextChangedEventArgs e)
{
if (isSetup)
{
try
{
if (IsConnected())
{
Rack.UDPreceiver.Disconnect();
}
Rack.UDPreceiver.Port = int.Parse(txtUDPPort.Text);
}
catch
{
// Ignore, just don't crash
}
}
}
private void UpdateIndicators()
{
txtUSBPort.Text = Rack.USBreceiver.Port.ToString();
txtUDPPort.Text = Rack.UDPreceiver.Port.ToString();
switch (PortType)
{
case SupportedPortTypes.USB:
indConnection.Fill = Rack.USBreceiver.IsConnected ? Rack.YES_BRUSH : Rack.NO_BRUSH;
break;
case SupportedPortTypes.UDP:
indConnection.Fill = Rack.UDPreceiver.IsConnected ? Rack.YES_BRUSH : Rack.NO_BRUSH;
break;
}
btnPause.Content = Rack.Paused ? "▶ Play" : "|| Pause";
}
/// <summary>
/// This method will be called when the window finished loading. A good moment to call a setup
/// </summary>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Setup = new DefaultSetup(this);
Setup.Setup();
isSetup = true;
InitializeGauges();
InitializeHeadTrackerPlotter();
UpdateIndicators();
}
}
}