forked from vedderb/vesc_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupwizardapp.cpp
812 lines (665 loc) · 26.1 KB
/
setupwizardapp.cpp
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
/*
Copyright 2016 - 2019 Benjamin Vedder [email protected]
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/>.
*/
#include "setupwizardapp.h"
#include <QVBoxLayout>
#include <QMessageBox>
#include <QProgressDialog>
#include "utility.h"
#include "setupwizardapp.h"
SetupWizardApp::SetupWizardApp(VescInterface *vesc, QWidget *parent)
: QWizard(parent)
{
mVesc = vesc;
mVesc->commands()->setSendCan(false);
setPage(Page_Intro, new AppIntroPage(vesc));
setPage(Page_Connection, new AppConnectionPage(vesc));
setPage(Page_Firmware, new AppFirmwarePage(vesc));
setPage(Page_Multi, new AppMultiPage(vesc));
setPage(Page_General, new AppGeneralPage(vesc));
setPage(Page_Nunchuk, new AppNunchukPage(vesc));
setPage(Page_Ppm_Map, new AppPpmMapPage(vesc));
setPage(Page_Ppm, new AppPpmPage(vesc));
setPage(Page_Adc_Map, new AppAdcMapPage(vesc));
setPage(Page_Adc, new AppAdcPage(vesc));
setPage(Page_Conclusion, new AppConclusionPage(vesc));
setStartId(Page_Intro);
setWizardStyle(ModernStyle);
QPixmap icon_logo = QIcon(Utility::getIcon(":/res/icon.svg")).pixmap(QSize(this->devicePixelRatioF() * 48, this->devicePixelRatioF() * 48));
icon_logo.setDevicePixelRatio(this->devicePixelRatioF());
setPixmap(QWizard::LogoPixmap, icon_logo);
resize(800, 450);
setWindowTitle(tr("App Setup Wizard"));
mSideLabel = new AspectImgLabel(Qt::Vertical);
mSideLabel->setPixmap(Utility::getIcon("logo_vertical.png"));
mSideLabel->setScaledContents(true);
setSideWidget(mSideLabel);
connect(this, SIGNAL(currentIdChanged(int)),
this, SLOT(idChanged(int)));
connect(this, SIGNAL(rejected()), this, SLOT(ended()));
connect(this, SIGNAL(accepted()), this, SLOT(ended()));
}
void SetupWizardApp::idChanged(int id)
{
if (id == Page_Intro || id == Page_Conclusion) {
setSideWidget(mSideLabel);
mSideLabel->setVisible(true);
} else {
setSideWidget(nullptr);
}
}
void SetupWizardApp::ended()
{
mVesc->commands()->getAppConf();
}
AppIntroPage::AppIntroPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("VESC® Input Setup Wizard"));
mLabel = new QLabel(tr("This wizard will help you choose what type of input to use "
"for your VESC®, and set up the apps according to your input."
"<br><br>"
"To get more information about the parameters and tools in the "
"wizard, click on the questionmark next to them."));
mLabel->setWordWrap(true);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mLabel);
setLayout(layout);
}
int AppIntroPage::nextId() const
{
if (mVesc->isPortConnected()) {
if ((mVesc->commands()->isLimitedMode() &&
!mVesc->commands()->getLimitedCompatibilityCommands().contains(int(COMM_GET_APPCONF))) ||
!mResetInputOk) {
return SetupWizardApp::Page_Firmware;
} else {
if (mVesc->getCanDevsLast().size() == 0) {
return SetupWizardApp::Page_General;
} else {
return SetupWizardApp::Page_Multi;
}
}
} else {
return SetupWizardApp::Page_Connection;
}
}
bool AppIntroPage::validatePage()
{
bool res = false;
if (!mVesc->isPortConnected()) {
QMessageBox::StandardButton reply;
reply = QMessageBox::information(this,
tr("Connection"),
tr("You are not connected to the VESC. Would you like to try to "
"automatically connect?<br><br>"
""
"<i>Notice that the USB cable must be plugged in and that the VESC "
"must be powered for the connection to work.</i>"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (reply == QMessageBox::Yes) {
Utility::autoconnectBlockingWithProgress(mVesc, this);
res = true;
}
} else {
mVesc->commands()->getAppConf();
QProgressDialog dialog("Scanning CAN-Bus...", QString(), 0, 0, this);
dialog.setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
dialog.setWindowModality(Qt::WindowModal);
dialog.setAttribute(Qt::WA_DeleteOnClose);
dialog.show();
setEnabled(false);
auto devs = mVesc->scanCan();
mResetInputOk = Utility::resetInputCan(mVesc, devs);
setEnabled(true);
}
return !res;
}
AppConnectionPage::AppConnectionPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("Connect VESC"));
setSubTitle(tr("The VESC has to be connected in order to use this "
"wizard. Please connect using one of the available "
"interfaces."));
mPageConnection = new PageConnection;
mPageConnection->setVesc(mVesc);
connect(mVesc, SIGNAL(fwRxChanged(bool,bool)),
this, SIGNAL(completeChanged()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mPageConnection);
setLayout(layout);
}
int AppConnectionPage::nextId() const
{
if (mVesc->commands()->isLimitedMode() &&
!mVesc->commands()->getLimitedCompatibilityCommands().contains(int(COMM_GET_APPCONF))) {
return SetupWizardApp::Page_Firmware;
} else {
return SetupWizardApp::Page_Multi;
}
}
bool AppConnectionPage::isComplete() const
{
return mVesc->fwRx();
}
AppFirmwarePage::AppFirmwarePage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("Update Firmware"));
setSubTitle(tr("You need to update the firmware on the VESC in order "
"to use it with this version of VESC Tool."));
mLabel = new QLabel(tr("Your VESC (or one of the VESCs on the CAN-bus) has old firmware, "
"and needs to be updated. After that, "
"the motor configuration has to be done again."));
mLabel->setWordWrap(true);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mLabel);
setLayout(layout);
}
int AppFirmwarePage::nextId() const
{
return -1;
}
AppMultiPage::AppMultiPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("Multiple VESCs"));
setSubTitle(tr("Found multiple VESCs on the CAN-bus, choose "
"which one the input is connected to."));
mCanFwdList = new QListWidget;
mCanFwdList->setIconSize(QSize(50, 50));
mCanFwdList->setWordWrap(true);
mCanFwdList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
registerField("CanFwd", this, "canFwd", SIGNAL(canFwdChanged));
connect(mCanFwdList, SIGNAL(currentRowChanged(int)),
this, SIGNAL(canFwdChanged()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mCanFwdList);
setLayout(layout);
}
void AppMultiPage::initializePage()
{
mCanFwdList->clear();
FW_RX_PARAMS params;
Utility::getFwVersionBlocking(mVesc, ¶ms);
if (params.hwType == HW_TYPE_VESC) {
QListWidgetItem *item = new QListWidgetItem;
item->setText(tr("This VESC (ID: %1)").
arg(mVesc->appConfig()->getParamInt("controller_id")));
item->setIcon(Utility::getIcon("icons/Connected-96.png"));
item->setData(Qt::UserRole, -1);
mCanFwdList->addItem(item);
}
bool canLastFwd = mVesc->commands()->getSendCan();
int canLastId = mVesc->commands()->getCanSendId();
mVesc->ignoreCanChange(true);
for (int dev: mVesc->getCanDevsLast()) {
mVesc->commands()->setSendCan(true, dev);
FW_RX_PARAMS params;
Utility::getFwVersionBlocking(mVesc, ¶ms);
if (params.hwType != HW_TYPE_VESC) {
continue;
}
QListWidgetItem *item = new QListWidgetItem;
item->setText(tr("VESC with ID: %1").arg(dev));
item->setIcon(Utility::getIcon("icons/can_off.png"));
item->setData(Qt::UserRole, dev);
mCanFwdList->addItem(item);
}
mCanFwdList->setCurrentItem(nullptr);
mVesc->commands()->setSendCan(canLastFwd, canLastId);
mVesc->ignoreCanChange(false);
}
int AppMultiPage::nextId() const
{
return SetupWizardApp::Page_General;
}
bool AppMultiPage::validatePage()
{
if (field("CanFwd").toInt() >= 0) {
mVesc->commands()->setSendCan(true, field("CanFwd").toInt());
} else {
mVesc->commands()->setSendCan(false);
}
mVesc->commands()->getAppConf();
Utility::waitSignal(mVesc->appConfig(), SIGNAL(updated()), 2000);
return true;
}
void AppMultiPage::cleanupPage()
{
// Do nothing here, but override so that fields are not reset.
}
int AppMultiPage::getCanFwd()
{
QListWidgetItem *item = mCanFwdList->currentItem();
int canFwd = 0;
if (item) {
canFwd = item->data(Qt::UserRole).toInt();
}
return canFwd;
}
AppGeneralPage::AppGeneralPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("Choose App"));
setSubTitle(tr("Choose what type of input you want to control this VESC with."));
mInputList = new QListWidget;
QListWidgetItem *item = new QListWidgetItem;
item->setText(tr("PPM input, such as conventional RC receivers."));
item->setIcon(QIcon("://res/images/rc_rx.jpg"));
item->setData(Qt::UserRole, SetupWizardApp::Input_Ppm);
mInputList->addItem(item);
item = new QListWidgetItem;
item->setText(tr("NRF controller."));
item->setIcon(QIcon("://res/images/vedder_nunchuk.jpg"));
item->setData(Qt::UserRole, SetupWizardApp::Input_NunchukNrf);
mInputList->addItem(item);
item = new QListWidgetItem;
item->setText(tr("ADC input, such as conventional ebike throttles."));
item->setIcon(QIcon("://res/images/ebike_throttle.jpg"));
item->setData(Qt::UserRole, SetupWizardApp::Input_Adc);
mInputList->addItem(item);
item = new QListWidgetItem;
item->setText(tr("Wireless nyko kama nunchuk."));
item->setIcon(QIcon("://res/images/nunchuk.jpg"));
item->setData(Qt::UserRole, SetupWizardApp::Input_Nunchuk);
mInputList->addItem(item);
mInputList->setIconSize(QSize(60, 60));
mInputList->setCurrentItem(nullptr);
registerField("Input", this, "inputType", SIGNAL(inputTypeChanged));
connect(mInputList, SIGNAL(currentRowChanged(int)),
this, SIGNAL(inputTypeChanged()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mInputList);
setLayout(layout);
}
int AppGeneralPage::nextId() const
{
switch (field("Input").toInt()) {
case SetupWizardApp::Input_Nunchuk:
case SetupWizardApp::Input_NunchukNrf:
return SetupWizardApp::Page_Nunchuk;
case SetupWizardApp::Input_Ppm:
return SetupWizardApp::Page_Ppm_Map;
case SetupWizardApp::Input_Adc:
return SetupWizardApp::Page_Adc_Map;
default:
break;
}
return SetupWizardApp::Page_Conclusion;
}
bool AppGeneralPage::validatePage()
{
return true;
}
void AppGeneralPage::cleanupPage()
{
// Do nothing here, but override so that fields are not reset.
}
int AppGeneralPage::getInputType()
{
QListWidgetItem *item = mInputList->currentItem();
int input = 0;
if (item) {
input = item->data(Qt::UserRole).toInt();
}
return input;
}
AppNunchukPage::AppNunchukPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("Nunchuk Configuration"));
mParamTab = new ParamTable;
mNrfPair = new NrfPair;
mTimer = new QTimer(this);
mWriteButton = new QPushButton(tr(" | Write Configuration To Vesc"));
mWriteButton->setIcon(Utility::getIcon("icons/app_down.png"));
mWriteButton->setIconSize(QSize(24, 24));
mNrfPair->setVesc(mVesc);
mDisplay = new DisplayPercentage;
mDisplay->setMinimumHeight(30);
mDisplay->setDual(true);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mParamTab);
layout->addWidget(mWriteButton);
layout->addWidget(mDisplay);
layout->addWidget(mNrfPair);
setLayout(layout);
connect(mVesc->commands(), SIGNAL(decodedChukReceived(double)),
this, SLOT(decodedChukReceived(double)));
connect(mTimer, SIGNAL(timeout()), this, SLOT(timerSlot()));
connect(mWriteButton, SIGNAL(clicked(bool)),
mVesc->commands(), SLOT(setAppConf()));
}
int AppNunchukPage::nextId() const
{
return SetupWizardApp::Page_Conclusion;
}
bool AppNunchukPage::validatePage()
{
mVesc->commands()->setAppConf();
return true;
}
void AppNunchukPage::initializePage()
{
mParamTab->setRowCount(0);
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.ctrl_type");
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.ramp_time_pos");
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.ramp_time_neg");
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.stick_erpm_per_s_in_cc");
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.hyst");
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.use_smart_rev");
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.smart_rev_max_duty");
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.smart_rev_ramp_time");
mParamTab->addRowSeparator(tr("Multiple VESCs over CAN-bus"));
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.tc");
mParamTab->addParamRow(mVesc->appConfig(), "app_chuk_conf.tc_max_diff");
mVesc->appConfig()->updateParamBool("app_chuk_conf.multi_esc", true);
if (field("Input").toInt() == SetupWizardApp::Input_Nunchuk) {
setSubTitle(tr("Configure your nyko kama nunchuk."));
mNrfPair->setVisible(false);
mVesc->appConfig()->updateParamEnum("app_to_use", 6);
mVesc->commands()->setAppConf();
Utility::waitSignal(mVesc->commands(), SIGNAL(ackReceived(QString)), 2000);
// TODO: Figure out why setting the conf twice is required...
mVesc->commands()->setAppConf();
Utility::waitSignal(mVesc->commands(), SIGNAL(ackReceived(QString)), 2000);
} else {
setSubTitle(tr("Pair and configure your NRF nunchuk."));
mNrfPair->setVisible(true);
// mVesc->appConfig()->updateParamEnum("app_to_use", 7);
mVesc->appConfig()->updateParamEnum("app_to_use", 3); // Assume permanent NRF or NRF51 on UART
mVesc->commands()->setAppConf();
Utility::waitSignal(mVesc->commands(), SIGNAL(ackReceived(QString)), 2000);
// TODO: Figure out why setting the conf twice is required...
mVesc->commands()->setAppConf();
Utility::waitSignal(mVesc->commands(), SIGNAL(ackReceived(QString)), 2000);
QMessageBox::information(this,
tr("NRF Pairing"),
tr("You are about to start pairing your NRF nunchuk. After clicking OK "
"you can use any of the buttons on the nunchuk to finish the pairing "
"process. Notice that the nunchuk has to be switched off for the "
"pairing to succeed. After the pairing is done you might need to use "
"one of the nunchuk buttons again to switch the nunchuk on before you "
"can use it."
"<br><br>"
"<font color=\"red\">Warning: </font>"
"After the pairing is done the nunchuk will become activated, so if "
"you move the joystick the motor will start spinning. Make sure that "
"nothing is in the way."));
mNrfPair->startPairing();
}
mTimer->start(40);
}
void AppNunchukPage::decodedChukReceived(double value)
{
double p = value * 100.0;
mDisplay->setValue(p);
mDisplay->setText(tr("%1 %").
arg(p, 0, 'f', 1));
}
void AppNunchukPage::timerSlot()
{
mVesc->commands()->getDecodedChuk();
}
AppPpmMapPage::AppPpmMapPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("PPM Mapping"));
setSubTitle(tr("Map your PPM receiver."));
mParamTab = new ParamTable;
mPpmMap = new PpmMap;
mTimer = new QTimer(this);
mPpmMap->setVesc(mVesc);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mParamTab);
layout->addWidget(mPpmMap);
setLayout(layout);
connect(mTimer, SIGNAL(timeout()), this, SLOT(timerSlot()));
connect(mVesc->appConfig(), SIGNAL(paramChangedDouble(QObject*,QString,double)),
this, SLOT(paramChangedDouble(QObject*,QString,double)));
}
int AppPpmMapPage::nextId() const
{
return SetupWizardApp::Page_Ppm;
}
bool AppPpmMapPage::validatePage()
{
mVesc->commands()->setAppConf();
return true;
}
void AppPpmMapPage::initializePage()
{
mParamTab->setRowCount(0);
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.pulse_start");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.pulse_end");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.pulse_center");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.hyst");
mVesc->appConfig()->updateParamEnum("app_ppm_conf.ctrl_type", 0);
mVesc->appConfig()->updateParamEnum("app_to_use", 4);
mVesc->commands()->setAppConf();
Utility::waitSignal(mVesc->commands(), SIGNAL(ackReceived(QString)), 2000);
// TODO: Figure out why setting the conf twice is required...
mVesc->commands()->setAppConf();
Utility::waitSignal(mVesc->commands(), SIGNAL(ackReceived(QString)), 2000);
mTimer->start(40);
}
void AppPpmMapPage::paramChangedDouble(QObject *src, QString name, double newParam)
{
(void)src;
(void)newParam;
if (name == "app_ppm_conf.pulse_start" ||
name == "app_ppm_conf.pulse_end" ||
name == "app_ppm_conf.pulse_center" ||
name == "app_ppm_conf.hyst") {
mVesc->commands()->setAppConf();
}
}
void AppPpmMapPage::timerSlot()
{
mVesc->commands()->getDecodedPpm();
}
AppPpmPage::AppPpmPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("PPM Configuration"));
setSubTitle(tr("Configure your PPM receiver."));
mParamTab = new ParamTable;
mWriteButton = new QPushButton(tr(" | Write Configuration To Vesc"));
mWriteButton->setIcon(Utility::getIcon("icons/app_down.png"));
mWriteButton->setIconSize(QSize(24, 24));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mParamTab);
layout->addWidget(mWriteButton);
setLayout(layout);
connect(mWriteButton, SIGNAL(clicked(bool)),
mVesc->commands(), SLOT(setAppConf()));
}
int AppPpmPage::nextId() const
{
return SetupWizardApp::Page_Conclusion;
}
bool AppPpmPage::validatePage()
{
mVesc->commands()->setAppConf();
return true;
}
void AppPpmPage::initializePage()
{
mParamTab->setRowCount(0);
mParamTab->addRowSeparator(tr("General"));
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.ctrl_type");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.median_filter");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.safe_start");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.ramp_time_pos");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.ramp_time_neg");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.pid_max_erpm");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.max_erpm_for_dir");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.smart_rev_max_duty");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.smart_rev_ramp_time");
mParamTab->addRowSeparator(tr("Multiple VESCs over CAN-bus"));
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.tc");
mParamTab->addParamRow(mVesc->appConfig(), "app_ppm_conf.tc_max_diff");
mVesc->appConfig()->updateParamBool("app_ppm_conf.multi_esc", true);
mVesc->appConfig()->updateParamEnum("app_ppm_conf.ctrl_type", 3);
mVesc->commands()->setAppConf();
}
AppAdcMapPage::AppAdcMapPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("ADC Mapping"));
setSubTitle(tr("Map your analog throttle."));
mParamTab = new ParamTable;
mAdcMap = new AdcMap;
mTimer = new QTimer(this);
mAdcMap->setVesc(mVesc);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mParamTab);
layout->addWidget(mAdcMap);
setLayout(layout);
connect(mTimer, SIGNAL(timeout()), this, SLOT(timerSlot()));
connect(mVesc->appConfig(), SIGNAL(paramChangedDouble(QObject*,QString,double)),
this, SLOT(paramChangedDouble(QObject*,QString,double)));
connect(mVesc->appConfig(), SIGNAL(paramChangedBool(QObject*,QString,bool)),
this, SLOT(paramChangedBool(QObject*,QString,bool)));
}
int AppAdcMapPage::nextId() const
{
return SetupWizardApp::Page_Adc;
}
bool AppAdcMapPage::validatePage()
{
mVesc->commands()->setAppConf();
return true;
}
void AppAdcMapPage::initializePage()
{
mParamTab->setRowCount(0);
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.voltage_start");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.voltage_end");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.voltage_center");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.voltage_inverted");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.voltage2_start");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.voltage2_end");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.voltage2_inverted");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.hyst");
mVesc->appConfig()->updateParamEnum("app_to_use", 5);
mVesc->appConfig()->updateParamEnum("app_adc_conf.ctrl_type", 0);
mVesc->commands()->setAppConf();
Utility::waitSignal(mVesc->commands(), SIGNAL(ackReceived(QString)), 2000);
// TODO: Figure out why setting the conf twice is required...
mVesc->commands()->setAppConf();
Utility::waitSignal(mVesc->commands(), SIGNAL(ackReceived(QString)), 2000);
mTimer->start(40);
}
void AppAdcMapPage::paramChangedDouble(QObject *src, QString name, double newParam)
{
(void)src;
(void)newParam;
if (name == "app_adc_conf.voltage_start" ||
name == "app_adc_conf.voltage_end" ||
name == "app_adc_conf.voltage_center" ||
name == "app_adc_conf.voltage2_start" ||
name == "app_adc_conf.voltage2_end" ||
name == "app_adc_conf.hyst") {
mVesc->commands()->setAppConf();
}
}
void AppAdcMapPage::paramChangedBool(QObject *src, QString name, bool newParam)
{
(void)src;
(void)newParam;
if (name == "app_adc_conf.voltage_inverted" ||
name == "app_adc_conf.voltage2_inverted") {
mVesc->commands()->setAppConf();
}
}
void AppAdcMapPage::timerSlot()
{
mVesc->commands()->getDecodedAdc();
}
AppAdcPage::AppAdcPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("ADC Configuration"));
setSubTitle(tr("Configure your analog throttle."));
mParamTab = new ParamTable;
mWriteButton = new QPushButton(tr(" | Write Configuration To Vesc"));
mWriteButton->setIcon(Utility::getIcon("icons/app_down.png"));
mWriteButton->setIconSize(QSize(24, 24));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mParamTab);
layout->addWidget(mWriteButton);
setLayout(layout);
connect(mWriteButton, SIGNAL(clicked(bool)),
mVesc->commands(), SLOT(setAppConf()));
}
int AppAdcPage::nextId() const
{
return SetupWizardApp::Page_Conclusion;
}
bool AppAdcPage::validatePage()
{
mVesc->commands()->setAppConf();
return true;
}
void AppAdcPage::initializePage()
{
mParamTab->setRowCount(0);
mParamTab->addRowSeparator(tr("General"));
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.ctrl_type");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.use_filter");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.safe_start");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.cc_button_inverted");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.rev_button_inverted");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.ramp_time_pos");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.ramp_time_neg");
mParamTab->addRowSeparator(tr("Multiple VESCs over CAN-bus"));
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.tc");
mParamTab->addParamRow(mVesc->appConfig(), "app_adc_conf.tc_max_diff");
mVesc->appConfig()->updateParamBool("app_adc_conf.multi_esc", true);
mVesc->appConfig()->updateParamEnum("app_adc_conf.ctrl_type", 1);
mVesc->commands()->setAppConf();
}
AppConclusionPage::AppConclusionPage(VescInterface *vesc, QWidget *parent)
: QWizardPage(parent)
{
mVesc = vesc;
setTitle(tr("Conclusion"));
mLabel = new QLabel;
mLabel->setWordWrap(true);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mLabel);
setLayout(layout);
}
int AppConclusionPage::nextId() const
{
return -1;
}
void AppConclusionPage::initializePage()
{
mLabel->setText(tr("You have finished the app setup. At this point "
"everything should be ready to run."));
}