-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodMain.vb
More file actions
228 lines (200 loc) · 9.74 KB
/
modMain.vb
File metadata and controls
228 lines (200 loc) · 9.74 KB
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
Module modMain
Public iniFile As String = Application.StartupPath & "\settings.ini"
Public ini As New IniReader(iniFile)
Public iCheckBoxItems As Integer = 0 'number of checkboxItems (readed from optionsconfig.xml
Public iPidItems As Integer = 10 'number if Pid items (const definition)
Public iSoftwareVersion As Integer = 0
Public sLogFolder As String = ""
Public sConfigFolder As String = ""
Public sFirmwareFolder As String = ""
Public sWayPointFolder As String = ""
Public iMapProviderSelectedIndex As Integer = 0
Public iMapZoom As Integer = 0
Public cliLoadSleep As Integer = 10
Public sBoxNames As String()
Public iBoxIdents As Integer()
Public sUID As String = "???"
Public AUX_CHANNELS As Integer = 0
Public isAUX_CHANNEL_update As Boolean = False
Public cfgBoxWidth As Integer = 0 '4 old Baseflight version / 8 with AUX Channel enhancment
Public boxAUX_CHANNELS As Integer = 0
Public mw_params As mw_settings
Public mw_gui As baseflight_data_gui
Public Const PIDRoll As Integer = 0
Public Const PIDPitch As Integer = 1
Public Const PIDYaw As Integer = 2
Public Const PIDAltitude As Integer = 3
Public Const PIDPosHold As Integer = 4
Public Const PIDPosHoldRate As Integer = 5
Public Const PIDNavigationRate As Integer = 6
Public Const PIDLevel As Integer = 7
Public Const PIDMag As Integer = 8
Public Const PIDVelocity As Integer = 9
Public isStartup As Boolean = True
Public dtOnlineHelp As New DataTable
Public Sub readDTOnlineHelp()
If System.IO.Directory.Exists(Application.StartupPath & "\OnlineHelp") = False Then
System.IO.Directory.CreateDirectory(Application.StartupPath & "\OnlineHelp")
End If
If System.IO.File.Exists(Application.StartupPath & "\OnlineHelp\help.xml") Then
dtOnlineHelp.Clear()
dtOnlineHelp.ReadXml(Application.StartupPath & "\OnlineHelp\help.xml")
Else
If dtOnlineHelp.Columns.Count = 0 Then
Dim col As DataColumn
col = New DataColumn("Item", GetType(System.String))
dtOnlineHelp.Columns.Add(col)
col = New DataColumn("Type", GetType(System.Int32))
dtOnlineHelp.Columns.Add(col)
col = New DataColumn("Language", GetType(System.String))
dtOnlineHelp.Columns.Add(col)
col = New DataColumn("URL", GetType(System.String))
dtOnlineHelp.Columns.Add(col)
col = New DataColumn("Description", GetType(System.String))
dtOnlineHelp.Columns.Add(col)
dtOnlineHelp.TableName = "OnlineHelp"
saveOnlineHelp()
End If
End If
End Sub
Public Sub addEmptyRow(ByVal item As String, ByVal Type As Integer, ByVal _Language As String)
Dim newrow As DataRow = dtOnlineHelp.NewRow
newrow("Item") = item
newrow("Type") = Type
newrow("Language") = _Language
newrow("Description") = ""
newrow("URL") = ""
dtOnlineHelp.Rows.Add(newrow)
End Sub
Public Sub saveOnlineHelp()
Try
dtOnlineHelp.WriteXml(Application.StartupPath & "\OnlineHelp\help.xml", XmlWriteMode.WriteSchema)
Catch ex As Exception
End Try
End Sub
Public Sub DownloadHelpXML()
frmMain.Cursor = Cursors.WaitCursor
Application.DoEvents()
Try
' Make a WebClient.
Dim web_client As Net.WebClient = New Net.WebClient
'Backup
System.IO.File.Copy(Application.StartupPath & "\OnlineHelp\help.xml", Application.StartupPath & "\OnlineHelp\help.bak", True)
' Download the file.
web_client.DownloadFile("http://www.klick-punkte.info/download/help.xml", Application.StartupPath & "\OnlineHelp\help.xml")
readDTOnlineHelp()
MessageBox.Show("Done")
Catch ex As Exception
MessageBox.Show(ex.Message, "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
frmMain.Cursor = Cursors.Default
End Sub
Public Sub readGUISettings()
If System.IO.File.Exists(iniFile) = False Then
writeGUISettings()
End If
guiDefaultPort = ini.ReadString("COM", "DefaultPort", "COM3")
guiDefaultSerialSpeed = ini.ReadString("COM", "DefaultSerialSpeed", "115200")
USBTimeout = ini.ReadInteger("COM", "USBTimeout", 15)
BluetoothTimeout = ini.ReadInteger("COM", "BluetoothTimeout", 30)
cliEntry = ini.ReadString("CLI", "StartCLI", cliEntry)
ExitPASSGPS = ini.ReadString("GUI", "ExitPASSGPS", ExitPASSGPS)
StartFWUpdate = ini.ReadString("GUI", "StartFWUpdate", StartFWUpdate)
'write back to by sure it's in the INI file
ini.Write("CLI", "StartCLI", cliEntry)
ini.Write("GUI", "ExitPASSGPS", ExitPASSGPS)
ini.Write("GUI", "StartFWUpdate", StartFWUpdate)
comTimeOut = ini.ReadString("COM", "ComTimeout", "500")
Timeout = ini.ReadString("COM", "FCTimeout", "10")
guiDefaultRate = ini.ReadString("GUI", "DefaultRate", "10 Hz")
sLogFolder = ini.ReadString("GUI", "LogFolder", Application.StartupPath & "\Logfiles")
sConfigFolder = ini.ReadString("GUI", "ConfigFolder", Application.StartupPath & "\Configfiles")
sFirmwareFolder = ini.ReadString("GUI", "FirmwareFolder", Application.StartupPath & "\Firmwarefiles")
sWayPointFolder = ini.ReadString("GUI", "WayPointFolder", Application.StartupPath & "\WayPoints")
iMapProviderSelectedIndex = ini.ReadInteger("GUI", "MapProvider", 1)
iMapZoom = ini.ReadInteger("GUI", "MapZoom", 19)
cliLoadSleep = ini.ReadInteger("CLI", "LoadSleep", 10)
Language = ini.ReadString("Help", "Language", "DE")
End Sub
Public Sub writeGUISettings()
ini.Write("COM", "DefaultPort", guiDefaultPort)
ini.Write("COM", "DefaultSerialSpeed", guiDefaultSerialSpeed)
ini.Write("GUI", "DefaultRate", guiDefaultRate)
ini.Write("CLI", "StartCLI", cliEntry)
ini.Write("GUI", "ExitPASSGPS", ExitPASSGPS)
ini.Write("GUI", "StartFWUpdate", StartFWUpdate)
End Sub
Public Sub versionCheck()
Try
If System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() Then
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.klick-punkte.info/download/BaseflightGUI2.txt")
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim reader As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim isNew As Boolean = False
Dim newestversion As String = reader.ReadToEnd()
Dim currentversion As String = Application.ProductVersion
Dim newI() As String = newestversion.Split(".")
Dim curI() As String = currentversion.Split(".")
If CInt(newI(0)) >= CInt(curI(0)) Then
If CInt(newI(0)) > CInt(curI(0)) Then
isNew = True
Else
If CInt(newI(1)) >= CInt(curI(1)) Then
If CInt(newI(1)) > CInt(curI(1)) Then
isNew = True
Else
If CInt(newI(2)) >= CInt(curI(2)) Then
If CInt(newI(2)) > CInt(curI(2)) Then
isNew = True
Else
If CInt(newI(3)) > CInt(curI(3)) Then
isNew = True
End If
End If
Else
'Current Version is newer
End If
End If
Else
'Current Version is newer
End If
End If
Else
'Current Version is newer
End If
If isNew = True Then
Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim res As MsgBoxResult
msg = "You have a old version. Do you want to download the new one?" + vbNewLine + "Current: " + currentversion + _
vbNewLine + "Newest: " + newestversion
style = MsgBoxStyle.YesNo Or MsgBoxStyle.Information
title = Application.ProductName + " - Updates"
res = MsgBox(msg, style, title)
If res = MsgBoxResult.Yes Then
Process.Start("http://www.klick-punkte.info/download/BaseflightGUI2.zip")
Else
'nothing
End If
End If
End If
Catch ex As Exception
End Try
End Sub
Public Function GetMotherboardSerialNumber() As String
Dim searcher As New System.Management.ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard")
For Each obj As System.Management.ManagementObject In searcher.Get
Return obj.Properties("SerialNumber").Value.ToString
Next
Return String.Empty
End Function
Public Function myMessageBox()
Dim result As DialogResult = DialogResult.Cancel
result = frmMessageBox.ShowDialog
Return result
End Function
Public Sub sleep(ByVal value As Integer)
System.Threading.Thread.Sleep(value)
End Sub
End Module