-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmSet.vb
More file actions
273 lines (255 loc) · 10.4 KB
/
frmSet.vb
File metadata and controls
273 lines (255 loc) · 10.4 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
Public Class frmSet
'# set *
'Current settings:
'deadband = 10 0 32 0
'yawdeadband = 15 0 100 0
'alt_hold_throttle_neutral = 50 1 250 0
'midrc = 1500 1200 1700 2
'rc_rate = 100 0 250 0
'rc_expo = 80 0 100 0
'thr_mid = 50 0 100 0
'thr_expo = 0 0 250 0
'roll_pitch_rate = 0 0 100 0
'yawrate = 0 0 100 0
'd_level = 20 0 200 0
'auxChannels = 8 4 14 0
'SONAR_Pinout = 1 0 1 0
'LED_Type = 2 0 3 0
'LED_pinout = 1 0 1 0
'LED_ControlChannel = 6 1 12 0
'LED_ARMED = 1 0 1 0
'LED_Toggle_Delay = 20 0 65535 2
'LED_Pattern1 = 16711935 0 2147483647 4
'LED_Pattern2 = 16711935 0 2147483647 4
'LED_Pattern3 = 16711935 0 2147483647 4
'#
Private Sub frmSet_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
isCLI = False
createDTSet()
readDTSet()
Catch ex As Exception
frmError.lastCommand = "initTPMap()"
frmError.myEx = ex
If frmError.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
System.Windows.Forms.Application.Exit()
End If
End Try
End Sub
Private Sub cmdCancel_Click(sender As Object, e As EventArgs) Handles cmdCancel.Click
isCLI = True
DialogResult = Windows.Forms.DialogResult.Cancel
End Sub
Private Sub cmdSet_Click(sender As Object, e As EventArgs) Handles cmdSet.Click
isCLI = True
writeSet()
DialogResult = Windows.Forms.DialogResult.OK
End Sub
Dim dtSet As New DataTable
Dim bsSet As New BindingSource
Private Sub createDTSet()
Try
If dtSet.Columns.Count > 0 Then Exit Sub
Dim col As DataColumn
col = New DataColumn("Item", GetType(System.String))
dtSet.Columns.Add(col)
col = New DataColumn("Value", GetType(System.String))
dtSet.Columns.Add(col)
col = New DataColumn("Min", GetType(System.String))
dtSet.Columns.Add(col)
col = New DataColumn("Max", GetType(System.String))
dtSet.Columns.Add(col)
col = New DataColumn("Type", GetType(System.String))
dtSet.Columns.Add(col)
col = New DataColumn("URL", GetType(System.String))
dtSet.Columns.Add(col)
col = New DataColumn("Description", GetType(System.String))
dtSet.Columns.Add(col)
dgSet.AutoGenerateColumns = False
bsSet.DataSource = dtSet
dgSet.DataSource = bsSet
Me.colItem.DataPropertyName = "Item"
Me.colValue.DataPropertyName = "Value"
Me.colMin.DataPropertyName = "Min"
Me.colMax.DataPropertyName = "Max"
Me.colType.DataPropertyName = "Type"
Me.colDescription.DataPropertyName = "Description"
Me.colURL.DataPropertyName = "URL"
Catch ex As Exception
frmError.lastCommand = "initTPMap()"
frmError.myEx = ex
If frmError.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
System.Windows.Forms.Application.Exit()
End If
End Try
End Sub
Private Sub readDTSet()
Try
Dim setReady As Boolean = False
Dim result As String = ""
dtSet.Clear()
serialPort.ReadExisting()
serialPort.Write("SET *" & vbCr & vbLf)
sleep(150)
Do While setReady = False
Do While serialPort.BytesToRead > 0
result = result & Chr(serialPort.ReadByte)
Loop
If result.Substring(result.Length - 3, 3).Contains("#") = True Then
setReady = True
End If
sleep(150)
Loop
'# set *
'Current settings:
result = result.Replace("#", "").Trim
result = result.Replace("SET *", "").Trim
result = result.Replace("Current settings:", "").Trim
result = result.Replace(" ", " ").Trim
Dim setList() As String = Nothing
setList = result.Split(vbCrLf)
For i As Integer = 0 To setList.Length - 1
Dim line As String = setList(i).Trim
If line <> "" Then
Dim items() As String = line.Split(" ")
If items.Length > 2 Then
Dim newrow As DataRow = dtSet.NewRow
newrow("Item") = items(0)
newrow("Value") = items(2)
If items.Length > 3 Then
newrow("Min") = items(3)
newrow("Max") = items(4)
'VAR_UINT8,
'VAR_INT8,
'VAR_UINT16,
'VAR_INT16,
'VAR_UINT32,
'VAR_FLOAT
If items.Length > 5 Then
Select Case items(5)
Case 0
newrow("Type") = "UINT8"
Case 1
newrow("Type") = "INT8"
Case 2
newrow("Type") = "UINT16"
Case 3
newrow("Type") = "INT16"
Case 4
newrow("Type") = "UINT32"
Case 5
newrow("Type") = "FLOAT"
Case Else
newrow("Type") = "unknown"
End Select
Else
If items(2).Contains(".") Then
newrow("Type") = "FLOAT"
Else
newrow("Type") = "unknown"
End If
End If
newrow("Description") = getDescription(items(0).Trim, HelpType.cliSet)
newrow("URL") = getURL(items(0).Trim)
dtSet.Rows.Add(newrow)
Else
'Stop
End If
End If
End If
Next
dtSet.AcceptChanges()
If isNewOnlineItem = True Then
saveOnlineHelp()
isNewOnlineItem = False
End If
Catch ex As Exception
frmError.lastCommand = "initTPMap()"
frmError.myEx = ex
If frmError.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
System.Windows.Forms.Application.Exit()
End If
End Try
End Sub
Private Function getURL(ByRef Item As String) As String
Dim result As String = ""
Dim dr() As DataRow = dtOnlineHelp.Select("Item like '" & Item & "' and Type = " & HelpType.cliSet & " and Language = '" & Language & "'")
If dr.Length = 0 Then
addEmptyRow(Item, 1, Language)
isNewOnlineItem = True
Else
Try
result = dr(0)("URL")
Catch ex As Exception
dr(0)("URL") = ""
End Try
End If
Return result
End Function
Public Sub writeSet()
For Each dr As DataRow In dtSet.Rows
If dr.RowState = DataRowState.Modified Then
Dim command As String = "SET " & dr("Item") & " = " & dr("Value")
serialPort.Write(command & vbCr & vbLf)
System.Threading.Thread.Sleep(200)
End If
Next
End Sub
Dim oldValue As Double
Private Sub dgSet_CellBeginEdit(sender As Object, e As DataGridViewCellCancelEventArgs) Handles dgSet.CellBeginEdit
oldValue = dgSet.Item("colValue", e.RowIndex).Value
End Sub
Private Sub dgSet_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgSet.CellEndEdit
Dim isError As Boolean = False
If IsNumeric(dgSet.Item("colValue", e.RowIndex).Value) Then
Dim value As Double = dgSet.Item("colValue", e.RowIndex).Value
Dim min As Double = dgSet.Item("colMin", e.RowIndex).Value
Dim max As Double = dgSet.Item("colMax", e.RowIndex).Value
If min <= value And value <= max Then
'Every think is fine
Else
isError = True
End If
Else
isError = True
End If
If isError = True Then
If dgSet.Item("colValue", e.RowIndex).Value = "FLOAT" Then
dgSet.Item("colValue", e.RowIndex).Value = oldValue
Else
dgSet.Item("colValue", e.RowIndex).Value = CInt(oldValue)
End If
End If
End Sub
Private Sub dgSet_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgSet.CellMouseClick
If e.RowIndex > -1 Then
If e.ColumnIndex = 6 Then
Dim url As String = ""
url = Me.dgSet.Item("colURL", e.RowIndex).Value
If url <> "" Then
Process.Start(url)
End If
End If
End If
End Sub
Private Sub cmdGPS_Click(sender As Object, e As EventArgs) Handles cmdGPS.Click
bsSet.Filter = "Item LIKE 'gps_%'"
End Sub
Private Sub cmdSONAR_Click(sender As Object, e As EventArgs) Handles cmdSONAR.Click
bsSet.Filter = "item LIKE 'snr_%'"
End Sub
Private Sub cmdALL_Click(sender As Object, e As EventArgs) Handles cmdALL.Click
bsSet.Filter = ""
End Sub
Private Sub cmdLED_Click(sender As Object, e As EventArgs) Handles cmdLED.Click
bsSet.Filter = "Item LIKE 'LED%'"
End Sub
Private Sub cmdGimbal_Click(sender As Object, e As EventArgs) Handles cmdGimbal.Click
End Sub
Private Sub cmdPID_Click(sender As Object, e As EventArgs) Handles cmdPID.Click
bsSet.Filter = "Item LIKE 'P_%' or Item LIKE 'I_%' or Item LIKE 'D_%'"
End Sub
Private Sub cmdAutoland_Click(sender As Object, e As EventArgs) Handles cmdAutoland.Click
bsSet.Filter = "item LIKE 'al_%'"
End Sub
End Class