-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup_wizard.cs
188 lines (158 loc) · 6.71 KB
/
setup_wizard.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
namespace MultiWiiWinGUI
{
public partial class setup_wizard : Form
{
private int iActualPage = 0; //Start from here
private const int iLastPage = 4; //Finish Page
private GUI_settings Settings;
const string sGuiSettingsFilename = "gui_settings.xml";
public setup_wizard()
{
InitializeComponent();
}
private void setup_scan_Ports()
{
cb_SerialPort.Items.Clear();
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
cb_SerialPort.Items.Add(port);
}
// select 1st item if any - avoid error when no com ports found
if (cb_SerialPort.Items.Count > 0)
cb_SerialPort.SelectedIndex = 0;
}
private void setup_wizard_Load(object sender, EventArgs e)
{
if (iActualPage == 0) { b_prev.Enabled = false; }
Settings = new GUI_settings();
//Set default values and fill out gui controls
Settings.bEnableLogging = false;
Settings.iSoftwareVersion = 21;
Settings.sCaptureFolder = Directory.GetCurrentDirectory() + "\\Captures";
Settings.sLogFolder = Directory.GetCurrentDirectory() + "\\Logs";
Settings.sSettingsFolder = Directory.GetCurrentDirectory() + "\\Settings";
Settings.sPreferedSerialSpeed = "115200";
// scan for serial ports on startup - maybe not needed as better scan on entering page 3
//setup_scan_Ports();
// add serial speeds
string[] sSerialSpeeds = { "115200", "57600", "38400", "19200", "9600" };
foreach (string speed in sSerialSpeeds)
{
cb_SerialSpeed.Items.Add(speed);
}
cb_SerialSpeed.SelectedItem = Settings.sPreferedSerialSpeed;
l_Log_folder.Text = Settings.sLogFolder;
l_Captures_folder.Text = Settings.sCaptureFolder;
l_Settings_folder.Text = Settings.sSettingsFolder;
//Set log enties checkboxes
cb_Log1.Checked = Settings.logGraw;
cb_Log2.Checked = Settings.logGatt;
cb_Log3.Checked = Settings.logGmag;
cb_Log4.Checked = Settings.logGrcc;
cb_Log5.Checked = Settings.logGrcx;
cb_Log6.Checked = Settings.logGmot;
cb_Log7.Checked = Settings.logGsrv;
cb_Log8.Checked = Settings.logGnav;
cb_Log9.Checked = Settings.logGpar;
cb_Log10.Checked = Settings.logGdbg;
}
private void b_finish_cancel_Click(object sender, EventArgs e)
{
//We reached the last page, so all parameters should be valid
if (panelWizard.SelectedIndex == iLastPage)
{
//Fill out the Settings class with control contents.
Settings.sLogFolder = l_Log_folder.Text;
Settings.sSettingsFolder = l_Settings_folder.Text;
Settings.sCaptureFolder = l_Captures_folder.Text;
Settings.sPreferedSerialSpeed = cb_SerialSpeed.SelectedItem.ToString();
Settings.sPreferedComPort = cb_SerialPort.Text;
Settings.iSoftwareVersion = 21;
Settings.bEnableLogging = cb_LogEnabled.Checked;
Settings.logGraw = cb_Log1.Checked;
Settings.logGatt = cb_Log2.Checked;
Settings.logGmag = cb_Log3.Checked;
Settings.logGrcc = cb_Log4.Checked;
Settings.logGrcx = cb_Log5.Checked;
Settings.logGmot = cb_Log6.Checked;
Settings.logGsrv = cb_Log7.Checked;
Settings.logGnav = cb_Log8.Checked;
Settings.logGpar = cb_Log9.Checked;
Settings.logGdbg = cb_Log10.Checked;
}
//Write out the Settings struct
//if not at the Finish page, don't copy control values, so default values will remain valid
//No check for successfull writing... :) If it's not successfull the gui will exit at the next step anyway
Settings.save_to_xml(sGuiSettingsFilename);
this.Close();
}
private void b_prev_Click(object sender, EventArgs e)
{
if (iActualPage > 0)
{
iActualPage--;
panelWizard.SelectedIndex = iActualPage;
b_next.Enabled = true;
b_finish_cancel.Text = "Cancel";
if (iActualPage == 0) { b_prev.Enabled = false; }
}
}
private void b_next_Click(object sender, EventArgs e)
{
if (iActualPage < iLastPage)
{
iActualPage++;
if (String.Compare(panelWizard.TabPages[iActualPage].Name,"tabSerial") == 0 )
{
// Rewritten to use tab.name to identify serial port tab
// re-scan for serial ports
setup_scan_Ports();
}
panelWizard.SelectedIndex = iActualPage;
b_prev.Enabled = true;
if (iActualPage == iLastPage) { b_next.Enabled = false; b_finish_cancel.Text = "Finish"; }
}
}
private void b_select_settings_folder_Click(object sender, EventArgs e)
{
FolderBrowserDialog fb = new FolderBrowserDialog();
fb.SelectedPath = l_Settings_folder.Text;
if (fb.ShowDialog() == DialogResult.OK)
{
l_Settings_folder.Text = fb.SelectedPath;
}
fb.Dispose();
}
private void b_select_log_folder_Click(object sender, EventArgs e)
{
FolderBrowserDialog fb = new FolderBrowserDialog();
fb.SelectedPath = l_Log_folder.Text;
if (fb.ShowDialog() == DialogResult.OK)
{
l_Log_folder.Text = fb.SelectedPath;
}
fb.Dispose();
}
private void b_select_captures_folder_Click(object sender, EventArgs e)
{
FolderBrowserDialog fb = new FolderBrowserDialog();
fb.SelectedPath = l_Captures_folder.Text;
if (fb.ShowDialog() == DialogResult.OK)
{
l_Captures_folder.Text = fb.SelectedPath;
}
fb.Dispose();
}
}
}