forked from vedderb/vesc_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPairingDialog.qml
379 lines (329 loc) · 13.6 KB
/
PairingDialog.qml
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
Copyright 2019 Benjamin Vedder benjamin@vedder.se
This file is part of VESC Tool.
VESC Tool is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VESC Tool is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.7
import QtQuick.Controls 2.10
import QtQuick.Layouts 1.3
import Vedder.vesc.vescinterface 1.0
import Vedder.vesc.commands 1.0
import Vedder.vesc.configparams 1.0
import Vedder.vesc.utility 1.0
Item {
function openDialog() {
dialog.open()
loadUuids()
}
function loadUuids() {
pairModel.clear()
var uuids = VescIf.getPairedUuids()
for (var i = 0;i < uuids.length;i++) {
pairModel.append({"uuid": uuids[i]})
}
}
Dialog {
property ConfigParams mAppConf: VescIf.appConfig()
property Commands mCommands: VescIf.commands()
id: dialog
modal: true
focus: true
width: parent.width - 20 - notchLeft - notchRight
height: parent.height - 60 - notchBot - notchTop
closePolicy: Popup.CloseOnEscape
x: (parent.width - width)/2
y: 50 + notchTop
parent: ApplicationWindow.overlay
padding: 10
Overlay.modal: Rectangle {
color: "#AA000000"
}
ColumnLayout {
anchors.fill: parent
Text {
id: text
Layout.fillWidth: true
color: Utility.getAppHexColor("lightText")
text: qsTr("These are the VESCs paired to this instance of VESC Tool.")
font.bold: true
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
}
ListModel {
id: pairModel
}
ListView {
id: pairList
Layout.fillWidth: true
Layout.fillHeight: true
focus: true
clip: true
spacing: 5
Component {
id: pairDelegate
Rectangle {
property variant modelData: model
width: pairList.width
height: 60
color: "#30000000"
radius: 5
RowLayout {
anchors.fill: parent
spacing: 10
Image {
id: image
fillMode: Image.PreserveAspectFit
mipmap: true
Layout.preferredWidth: 40
Layout.preferredHeight: 40
Layout.alignment: Qt.AlignVCenter
Layout.leftMargin: 10
source: "qrc:/res/icon.svg"
}
Text {
Layout.fillWidth: true
color: Utility.getAppHexColor("lightText")
text: uuid
wrapMode: Text.Wrap
}
Button {
Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: 10
text: "Delete"
onClicked: {
deleteDialog.open()
}
Dialog {
id: deleteDialog
property int indexNow: 0
standardButtons: Dialog.Ok | Dialog.Cancel
modal: true
focus: true
width: parent.width - 20
closePolicy: Popup.CloseOnEscape
title: "Delete paired VESC"
x: 10
y: 10 + parent.height / 2 - height / 2
parent: ApplicationWindow.overlay
Overlay.modal: Rectangle {
color: "#AA000000"
}
Text {
color: Utility.getAppHexColor("lightText")
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
wrapMode: Text.WordWrap
text: "This is going to delete this VESC from the paired list. If that VESC " +
"has the pairing flag set you won't be able to connect to it over BLE " +
"any more. Are you sure?"
}
onAccepted: {
VescIf.deletePairedUuid(uuid)
VescIf.storeSettings()
}
}
}
}
}
}
model: pairModel
delegate: pairDelegate
}
RowLayout {
Layout.fillWidth: true
Button {
Layout.preferredWidth: 50
Layout.fillWidth: true
text: "..."
onClicked: menu.open()
Menu {
id: menu
width: 500
MenuItem {
text: "Add current without pairing"
onTriggered: {
if (VescIf.isPortConnected()) {
VescIf.addPairedUuid(VescIf.getConnectedUuid());
VescIf.storeSettings()
} else {
VescIf.emitMessageDialog("Add UUID",
"You are not connected to the VESC. Connect in order to add it.",
false, false)
}
}
}
MenuItem {
text: "Add from UUID"
onTriggered: {
uuidEnter.open()
}
}
MenuItem {
text: "Unpair connected"
onTriggered: {
if (VescIf.isPortConnected()) {
if (mCommands.isLimitedMode()) {
VescIf.emitMessageDialog("Unpair VESC",
"The fiwmare must be updated to unpair this VESC.",
false, false)
} else {
unpairConnectedDialog.open()
}
} else {
VescIf.emitMessageDialog("Unpair VESC",
"You are not connected to the VESC. Connect in order to unpair it.",
false, false)
}
}
}
}
}
Button {
id: pairConnectedButton
text: "Pair VESC"
Layout.fillWidth: true
onClicked: {
if (VescIf.isPortConnected()) {
if (mCommands.isLimitedMode()) {
VescIf.emitMessageDialog("Pair VESC",
"The fiwmare must be updated to pair this VESC.",
false, false)
} else {
pairConnectedDialog.open()
}
} else {
VescIf.emitMessageDialog("Pair VESC",
"You are not connected to the VESC. Connect in order to pair it.",
false, false)
}
}
}
Button {
text: "Close"
Layout.fillWidth: true
onClicked: {
dialog.close()
}
}
}
}
}
Dialog {
id: pairConnectedDialog
property int indexNow: 0
standardButtons: Dialog.Ok | Dialog.Cancel
modal: true
focus: true
width: parent.width - 20 - notchLeft - notchRight
closePolicy: Popup.CloseOnEscape
title: "Pair connected VESC"
x: (parent.width - width)/2
y: 10 + Math.max((parent.height - height) / 2, 10)
parent: ApplicationWindow.overlay
Overlay.modal: Rectangle {
color: "#AA000000"
}
Text {
color: Utility.getAppHexColor("lightText")
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
wrapMode: Text.WordWrap
text: "This is going to pair the connected VESC with this instance of VESC Tool. VESC Tool instances " +
"that are not paired with this VESC will not be able to connect over bluetooth any more. Continue?"
}
onAccepted: {
VescIf.addPairedUuid(VescIf.getConnectedUuid());
VescIf.storeSettings()
mAppConf.updateParamBool("pairing_done", true, null)
mCommands.setAppConf()
if (Utility.waitSignal(mCommands, "2ackReceived(QString)", 2000)) {
VescIf.emitMessageDialog("Pairing Successful!",
"Pairing is done! Please note the UUID if this VESC (or take a screenshot) in order " +
"to add it to VESC Tool instances that are not paired in the future. The UUID is:\n" +
VescIf.getConnectedUuid(),
true, false)
}
}
}
Dialog {
id: unpairConnectedDialog
property int indexNow: 0
standardButtons: Dialog.Ok | Dialog.Cancel
modal: true
focus: true
width: parent.width - 20 - notchLeft - notchRight
closePolicy: Popup.CloseOnEscape
title: "Unpair connected VESC"
x: (parent.width - width)/2
y: 10 + parent.height / 2 - height / 2
parent: ApplicationWindow.overlay
Overlay.modal: Rectangle {
color: "#AA000000"
}
Text {
color: Utility.getAppHexColor("lightText")
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
wrapMode: Text.WordWrap
text: "This is going to unpair the connected VESC. Continue?"
}
onAccepted: {
VescIf.deletePairedUuid(VescIf.getConnectedUuid());
VescIf.storeSettings()
mAppConf.updateParamBool("pairing_done", false, null)
mCommands.setAppConf()
}
}
Dialog {
id: uuidEnter
standardButtons: Dialog.Ok | Dialog.Cancel
modal: true
focus: true
title: "Add UUID"
width: parent.width - 20 - notchLeft - notchRight
height: 200
closePolicy: Popup.CloseOnEscape
x: (parent.width - width)/2
y: (parent.height - height)/2
parent: ApplicationWindow.overlay
Overlay.modal: Rectangle {
color: "#AA000000"
}
Rectangle {
anchors.fill: parent
height: 20
border.width: 2
border.color: Utility.getAppHexColor("disabledText")
color: Utility.getAppHexColor("lightBackground")
radius: 3
TextInput {
id: stringInput
color: Utility.getAppHexColor("lightText")
anchors.fill: parent
anchors.margins: 7
font.pointSize: 12
focus: true
}
}
onAccepted: {
if (stringInput.text.length > 0) {
VescIf.addPairedUuid(stringInput.text)
}
}
}
Connections {
target: VescIf
function onPairingListUpdated() {
loadUuids()
}
}
}