-
Notifications
You must be signed in to change notification settings - Fork 1
/
HearingAidvMainWindow.cpp
5296 lines (4704 loc) · 201 KB
/
HearingAidvMainWindow.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
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************************
** Copyright 2023 Hangzhou Zhicun (Witmem) Technology Co., Ltd. All rights reserved. **
** **
** This program 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. **
** **
** This program 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 "HearingAidvMainWindow.h"
#include "ui_HearingAidvMainWindow.h"
#include "CustomTabStyle.h"
#include "WDRCItemWidget.h"
#include "EQItemWidget.h"
#include "ChangeTabOrder.h"
#include <QMetaType>
#include <QDebug>
CHearingAidvMainWindow::CHearingAidvMainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::CHearingAidvMainWindow)
{
ui->setupUi(this);
m_pSerialWork = SerialWork::instance();
ui->DeviceModeNumLeftMicBox->setObjectName("MicLeft");
ui->DeviceModeNumRightMicBox->setObjectName("Right");
initConnects();
initWDRCUi(WDRC_CHANNGL_COUNT);
initCharts();
initEQUi();
initUi();
initNoiseUi();
initOther();
initSerialDialog();
on_IsFileFullSizecheckBox_clicked(false);
initCalibrationValue();
initUiReadJsonData();
initTabFocusOrder();
ui->WDRCwriteArg->hide();
ui->WDRCReadArg->hide();
ui->RestoreSerialBtn->hide();
ui->tabWidget->setCurrentIndex(0);
ui->errorMsgShowLabel->setText("无操作");
ui->errorMsgShowLabel->setStyleSheet("");
ui->isSuccessStatusShowWidget->setStyleSheet("border-radius:8px;background-color:gray;");
setVolumeKeyModeShow();
m_btnStatusMap.insert(ui->modeTypeBtn_0,ui->modeTypeBtn_0->isChecked());
m_btnStatusMap.insert(ui->modeTypeBtn_1,ui->modeTypeBtn_1->isChecked());
m_btnStatusMap.insert(ui->modeTypeBtn_2,ui->modeTypeBtn_2->isChecked());
m_btnStatusMap.insert(ui->modeTypeBtn_3,ui->modeTypeBtn_3->isChecked());
ui->comboBoxFre->hide();
#ifndef DEVELOPER_VERSION
int index = ui->tabWidget->indexOf(ui->tab_Flash);
if (index != -1) {
ui->tabWidget->removeTab(index);
}
#endif
}
CHearingAidvMainWindow::~CHearingAidvMainWindow()
{
if(m_pArrySectionalData256){
delete m_pArrySectionalData256;
m_pArrySectionalData256 = nullptr;
}
delete ui;
}
void CHearingAidvMainWindow::initUi()
{
initBtnStatus();
m_pArrySectionalData256= new uchar[1024];
initProcessProgressBar();
ui->FlashReadFileNameLE->hide();
ui->FlashFileReadBtn->hide();
ui->modeTypeBtn_3->hide();
ui->tabWidget->setTabPosition(QTabWidget::West);
ui->tabWidget->tabBar()->setStyle(new CustomTabStyle);
ui->FlashReadAddressLE->setMaxLength(11);
ui->FlashFromAddressLE->setMaxLength(11);
ui->FlashEraseAddressLE->setMaxLength(11);
ui->FLashCopySrcAddressLE->setMaxLength(11);
ui->FlashVerifyAddressLE->setMaxLength(11);
ui->FlashCopyDestAddrLE->setMaxLength(11);
ui->soundPresLE->setMaxLength(3);
ui->soundFrequencyLE->setMaxLength(5);
ui->soundNumsLE->setMaxLength(3);
ui->soundContinueLE->setMaxLength(6);
ui->soundCycleLE->setMaxLength(6);
QRegExp regx("^0|[1-9][01]?|^[1-9]{2}$|^[1][0-9]{2}$|^[2][0-4][0-9]$|^[2][5][0-5]$");
ui->soundNumsLE->setValidator(new QRegExpValidator(regx));
ui->configFilePathEdit->setValidator(new QRegExpValidator(regx));
QRegExp regx140("^(0|140|[1-9][0-3]?[0-9]?|[1-9]?)$");
ui->soundPresLE->setValidator(new QRegExpValidator(regx140));
QRegExp regxNext("^(20000|[2-9][0-9]{1,3}|1[0-9]{1,4})$");
ui->soundFrequencyLE->setValidator(new QRegExpValidator(regxNext));
QRegExp regxTail("^(0|[1-9]\\d{0,3}|[1-5]\\d{4}|6[0-4]\\d{3}|655[0-3][0-5])$");
ui->soundContinueLE->setValidator(new QRegExpValidator(regxTail));
ui->soundCycleLE->setValidator(new QRegExpValidator(regxTail));
ui->WDRCRTLineEdit->setValidator(new QRegExpValidator(regxTail));
ui->WDRCATLineEdit->setValidator(new QRegExpValidator(regxTail));
QRegExp regArg("^-128|0|-?([1-9]|[1-9]\\d|1[01]\\d|12[0-7])$");
ui->pickupLeftChannelDGAEdit->setValidator(new QRegExpValidator(regArg));
ui->pickupRightChannelDGAEdit->setValidator(new QRegExpValidator(regArg));
ui->pickupLeftChannelPGAEdit->setValidator(new QRegExpValidator(regArg));
ui->pickupRightChannelPGAEdit->setValidator(new QRegExpValidator(regArg));
ui->playbackArgLeftChannelDGAEdilt->setValidator(new QRegExpValidator(regArg));
ui->playbackArgRightChannelDGAEdilt->setValidator(new QRegExpValidator(regArg));
ui->NRNLICalibrationLeftLineEdit->setValidator(new QRegExpValidator(regArg));
ui->NRNLICalibrationRightLineEdit->setValidator(new QRegExpValidator(regArg));
QRegExp regxNum("^(?!0)\\d{1,9}$|^[1-3]\\d{9}$|^4([0-1]\\d{8}|2([0-8]\\d{7}|9([0-4]\\d{6}|95([0-4]\\d{5}|5([0-2]\\d{4}|3([0-5]\\d{3}|6([0-6]\\d{2}|7([0-2]\\d|3[0-5]))))))))$");
ui->FlashReadLenthLE->setValidator(new QRegExpValidator(regxNum));
ui->FlashFromLenthLE->setValidator(new QRegExpValidator(regxNum));
ui->FlashVerifyLenthLE->setValidator(new QRegExpValidator(regxNum));
ui->FlashCopyLenthLE->setValidator(new QRegExpValidator(regxNum));
ui->FlashReadLenthLE->setMaxLength(10);
ui->FlashFromLenthLE->setMaxLength(10);
ui->FlashVerifyLenthLE->setMaxLength(10);
ui->FlashCopyLenthLE->setMaxLength(10);
QString strWriteDesc = "请选择一个文件";
ui->FlashFromFileNameLE->setPlaceholderText(strWriteDesc);
ui->configFilePathEdit->setPlaceholderText(strWriteDesc);
ui->AlgArgUpdataFilePathlineEdit_1->setPlaceholderText(strWriteDesc);
ui->AlgArgUpdataFilePathlineEdit_2->setPlaceholderText(strWriteDesc);
ui->AlgArgUpdataFilePathlineEdit_3->setPlaceholderText(strWriteDesc);
ui->AlgArgUpdataFilePathlineEdit_4->setPlaceholderText(strWriteDesc);
ui->firmwareUpdataFilePathlineEdit->setPlaceholderText(strWriteDesc);
for(int i = 1; i <= 32; i++){
if(i <= 16){
ui->VolumeKeyStepComBox->addItem(QString::number(i));
}
ui->VolumeKeyStallNumComBox->addItem(QString::number(i));
}
QStringList comBoxList;
comBoxList <<"不使能循环" <<"使能循环";
ui->VolumeKeyCyCleComBox->addItems(comBoxList);
comBoxList.clear();
comBoxList <<"顺时针" <<"逆时针";
ui->VolumeKnobDirectionComBox->addItems(comBoxList);
comBoxList.clear();
for(int i = 0; i <= 255; i++){
ui-> VolumeKnobRangeComBox->addItem(QString::number(i));
}
QString str65535Desc = "请输入[0,65535]之间的数";
QString str255Desc = "请输入[0,255]之间的数";
ui->soundPresLE->setPlaceholderText("请输入[0,140]之间的数");
ui->soundFrequencyLE->setPlaceholderText("请输入[20,20000]之间的数");
ui->soundCycleLE->setPlaceholderText(str65535Desc);
ui->soundContinueLE->setPlaceholderText(str65535Desc);
ui->soundNumsLE->setPlaceholderText(str255Desc);
ALGMODELDTAT algDataStruct;
algDataStruct.pAlgGroupBox = ui->algGroupBox_1;
algDataStruct.pAlgFilePath = ui->AlgArgUpdataFilePathlineEdit_1;
m_AlgModelList.append(algDataStruct);
algDataStruct.pAlgGroupBox = ui->algGroupBox_2;
algDataStruct.pAlgFilePath = ui->AlgArgUpdataFilePathlineEdit_2;
m_AlgModelList.append(algDataStruct);
algDataStruct.pAlgGroupBox = ui->algGroupBox_3;
algDataStruct.pAlgFilePath = ui->AlgArgUpdataFilePathlineEdit_3;
m_AlgModelList.append(algDataStruct);
algDataStruct.pAlgGroupBox = ui->algGroupBox_4;
algDataStruct.pAlgFilePath = ui->AlgArgUpdataFilePathlineEdit_4;
m_AlgModelList.append(algDataStruct);
ui->exportArgCountBox->setCurrentText("3");
}
void CHearingAidvMainWindow::initWDRCUi(int nChannelCount)
{
m_wdrcCTStatus.resize(nChannelCount);
m_wdrcMPOStatus.resize(nChannelCount);
m_wdrcGainStatus.resize(nChannelCount);
m_spinboxStatus.resize(nChannelCount);
m_wdrcCTStatus.fill(0);
m_wdrcMPOStatus.fill(0);
m_wdrcGainStatus.fill(0);
m_spinboxStatus.fill(0);
ui->FrequencyBandCoBoxFirst->clear();
QString path = QCoreApplication::applicationDirPath();
QString ChannelRangeFilePath = path + QString("/JsonFile/ChannelRange_%1.json").arg(nChannelCount);
QFile file(ChannelRangeFilePath);
QString msg;
if(!file.exists()){
msg = "WDRC频段数据文件不存在";
slotShowMsgBox(msg);
return;
}
if(file.size() == 0){
msg = "WDRC频段数据文件为空";
slotShowMsgBox(msg);
return;
}
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
msg = "WDRC频段数据文件无法打开";
slotShowMsgBox(msg);
return;
}
QString str = file.readAll();
file.close();
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(str.toUtf8(), &parseJsonErr);
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
slotShowMsgBox("WDRC频段配置文件错误!");
return;
}
QJsonObject jsonObject = document.object();
if (jsonObject.contains(QStringLiteral("WDRC Channel Range"))) {
QJsonValue arrayValue = jsonObject.value(QStringLiteral("WDRC Channel Range"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
for (int i = 1; i < nChannelCount +1; i++) {
QString strChannel = QString("%1-%2").arg(array.at(i - 1).toString()).arg(array.at(i).toString());
ui->FrequencyBandCoBoxFirst->addItem(strChannel);
CWDRCItemWidget * pWidget = new CWDRCItemWidget(this);
pWidget->setObjName(i - 1);
pWidget->setObjectName("enableWidget");
connect(pWidget,&CWDRCItemWidget::signal_isSelectAllCheckBox,
this,&CHearingAidvMainWindow::slotIsSelectAllCheckBox);
connect(this,&CHearingAidvMainWindow::signalWDRCIsSelectAll,
pWidget,&CWDRCItemWidget::slotSetisSelectAllCheckBox);
connect(pWidget->getChannelSingleCheckBox(),&QCheckBox::clicked,
this,&CHearingAidvMainWindow::slotWDRCSigalClicked);
connect(ui->scrollArea,&RubberScrollArea::signalSelectAllcheckbox,
pWidget,&CWDRCItemWidget::slotSetisSelectAllCheckBox);
connect(pWidget->getWDRCData().pGainComBox, SIGNAL(activated(int)),
this, SLOT(slotSetWDRCComBoxIndexSynchronization(int)));
connect(pWidget->getWDRCData().pCTComBox, SIGNAL(activated(int)),
this, SLOT(slotSetWDRCComBoxIndexSynchronization(int)));
connect(pWidget->getWDRCData().pMPOCoBox, SIGNAL(activated(int)),
this, SLOT(slotSetWDRCComBoxIndexSynchronization(int)));
connect(pWidget->getWDRCData().pCRSpinBox, SIGNAL(valueChanged(double)),
this, SLOT(slotSetWDRCSpinBoxValueSynchronization(double)));
pWidget->setChecBoxLabelValue(strChannel);
if(i ==1){
pWidget->setHeadWidgetHide(true);
}
ui->verticalLayout_WDRC->addWidget(pWidget);
m_wdrcGainStatus[i - 1] = pWidget->getWDRCData().pGainComBox->currentIndex();
m_wdrcCTStatus[i - 1] = pWidget->getWDRCData().pCTComBox->currentIndex();
m_wdrcMPOStatus[i - 1] = pWidget->getWDRCData().pMPOCoBox->currentIndex();
m_spinboxStatus[i - 1] = pWidget->getWDRCData().pCRSpinBox->value();
}
}
}
on_WDRCChannelCounBox_currentTextChanged("4");
}
void CHearingAidvMainWindow::initProcessProgressBar()
{
ui->showProcessProgressBar->setMinimum(0);
ui->showProcessProgressBar->setValue(0);
double dProgress = (ui->showProcessProgressBar->value() - ui->showProcessProgressBar->minimum()) * 100.0
/ (ui->showProcessProgressBar->maximum() - ui->showProcessProgressBar->minimum());
ui->showProcessProgressBar->setFormat(QString("读/写进度为: %1%").arg(QString::number(dProgress, 'f', 2)));
}
void CHearingAidvMainWindow::initCharts()
{
QValueAxis* pAxisXFirst = new QValueAxis(this);
QValueAxis* pAxisYFirst = new QValueAxis(this);
m_pLineSeriesFirst = new QLineSeries(this);
QChart *pChartFirst = new QChart();
pChartFirst->addAxis(pAxisXFirst, Qt::AlignBottom);
pChartFirst->addAxis(pAxisYFirst, Qt::AlignLeft);
pChartFirst->addSeries(m_pLineSeriesFirst);
m_pLineSeriesFirst->attachAxis(pAxisXFirst);
m_pLineSeriesFirst->attachAxis(pAxisYFirst);
ui->graphicsViewFirst->setRenderHint(QPainter::Antialiasing);
ui->graphicsViewFirst->setChart(pChartFirst);
pChartFirst->layout()->setContentsMargins(0, 0,0, 0);
pChartFirst->setMargins(QMargins(5, 5, 5,5));
pAxisXFirst->setTitleText("In(dB spl)");
pAxisYFirst->setTitleText("Out(dB spl)");
pAxisXFirst->setMin(20);
pAxisYFirst->setMin(20);
pAxisXFirst->setMax(WDRC_AXISX_RANGE);
pAxisYFirst->setMax(WDRC_AXISY_RANGE);
pAxisXFirst->setTickCount(11);
pAxisYFirst->setTickCount(7);
pAxisXFirst->setLineVisible(true);
pAxisYFirst->setLineVisible(true);
pAxisYFirst->setLabelFormat("%d");
pAxisXFirst->setLabelFormat("%d");
m_pLineSeriesFirst->clear();
QLegend *legend = pChartFirst->legend();
if(legend){
legend->setVisible(false);
}
}
void CHearingAidvMainWindow::drawCurves(float threshold,float ratio,float gain,float mpo,int type)
{
float yy = WDRC_AXISY_RANGE <= mpo ? WDRC_AXISY_RANGE : mpo;
QPointF first, second, third, forth;
first.setX(20);
first.setY(20 + gain);
if (threshold > yy){
second.setX(mpo - gain);
second.setY(mpo);
third.setX(WDRC_AXISX_RANGE);
third.setY(mpo);
forth = third;
}else{
second.setX(threshold - gain);
second.setY(threshold);
third.setX(threshold - gain + (yy - threshold)*ratio);
third.setY(yy);
forth.setX(WDRC_AXISX_RANGE);
forth.setY(yy);
}
if(type == LineSeriesFirst){
m_pLineSeriesFirst->clear();
m_pLineSeriesFirst->append(first);
m_pLineSeriesFirst->append(second);
m_pLineSeriesFirst->append(third);
m_pLineSeriesFirst->append(forth);
}
return;
}
void CHearingAidvMainWindow::initNoiseUi()
{
ui->NoiseNumberShowLabel->setText(QString("%1").arg(ui->NoiseHorizontalSlider->value()));
}
void CHearingAidvMainWindow::applyLineEditFormat(QLineEdit *lineEdit,int rex) {
QRegExp rxNormal("[A-Fa-f\\d\\s]+");
QRegExp rxNumber("[0-9]+$");
if(rex == HEX_NORMAL){
lineEdit->setValidator(new QRegExpValidator(rxNormal, lineEdit));
}else{
lineEdit->setValidator(new QRegExpValidator(rxNumber, lineEdit));
}
connect(lineEdit, &QLineEdit::textEdited, [lineEdit](const QString &input) {
QString hexStr = input.simplified().remove(" ");
QString formattedStr;
for (int i = 0; i < hexStr.length(); i += 2) {
formattedStr += hexStr.mid(i, 2) + " ";
}
formattedStr = formattedStr.trimmed();
lineEdit->setText(formattedStr.toUpper());
});
}
QByteArray CHearingAidvMainWindow::intToArry(int nData)
{
int *p = &nData;
QByteArray Arry = QByteArray::fromRawData(reinterpret_cast<const char *>(p),4);
QByteArray RawDataArry;
RawDataArry.append(Arry);
return RawDataArry;
}
void CHearingAidvMainWindow::initOther()
{
m_pSerialThread = new QThread;
m_pSerialWork->moveToThread(m_pSerialThread);
connect(m_pSerialThread, &QThread::finished,m_pSerialWork, &SerialWork::deleteLater);
m_pSerialThread->start();
QString strPWDest = "请输入8位密码";
ui->permPasswdLE->setMaxLength(PASSWORD_LENTH);
ui->permPasswdLE->setPlaceholderText(strPWDest);
ui->changeOldpaswdLE->setMaxLength(PASSWORD_LENTH);
ui->changeOldpaswdLE->setPlaceholderText(strPWDest);
ui->changeNewpaswdLE->setMaxLength(PASSWORD_LENTH);
ui->changeNewpaswdLE->setPlaceholderText(strPWDest);
ui->changeConfirmPaswdLE->setMaxLength(PASSWORD_LENTH);
ui->changeConfirmPaswdLE->setPlaceholderText(strPWDest);
ui->changeConfirmPaswdLE->setMaxLength(PASSWORD_LENTH);
ui->changeConfirmPaswdLE->setPlaceholderText(strPWDest);
ui->clearPaswdLE->setMaxLength(PASSWORD_LENTH);
ui->clearPaswdLE->setPlaceholderText(strPWDest);
ui->InitPasswordEdit->setMaxLength(PASSWORD_LENTH);
ui->InitPasswordEdit->setPlaceholderText(strPWDest);
QRegExp rxNumber("[a-zA-Z0-9]+$");
ui->permPasswdLE->setValidator(new QRegExpValidator(rxNumber));
ui->changeOldpaswdLE->setValidator(new QRegExpValidator(rxNumber));
ui->changeNewpaswdLE->setValidator(new QRegExpValidator(rxNumber));
ui->changeConfirmPaswdLE->setValidator(new QRegExpValidator(rxNumber));
ui->clearPaswdLE->setValidator(new QRegExpValidator(rxNumber));
ui->InitPasswordEdit->setValidator(new QRegExpValidator(rxNumber));
applyLineEditFormat(ui->FlashCopyDestAddrLE,HEX_NORMAL);
applyLineEditFormat(ui->FLashCopySrcAddressLE,HEX_NORMAL);
applyLineEditFormat(ui->FlashEraseAddressLE,HEX_NORMAL);
applyLineEditFormat(ui->FlashReadAddressLE,HEX_NORMAL);
applyLineEditFormat(ui->FlashVerifyAddressLE,HEX_NORMAL);
applyLineEditFormat(ui->FlashFromAddressLE,HEX_NORMAL);
}
void CHearingAidvMainWindow::initSerialDialog()
{
ui->SerialNameBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
ui->SerialNameBox->setMinimumContentsLength(5);
slotSerialNameBoxRefresh();
connect(m_pSerialWork, &SerialWork::signaSerialportStateChanged, this, &CHearingAidvMainWindow::slotSerialPortStateChanged);
connect(this, &CHearingAidvMainWindow::signalSendAccept, m_pSerialWork, &SerialWork::slotInitSerial);
connect(this, &CHearingAidvMainWindow::signalSendClose, m_pSerialWork, &SerialWork::slotCloseSerial);
}
void CHearingAidvMainWindow::initUiReadJsonData()
{
QString strCfgFilePath;
strCfgFilePath = QCoreApplication::applicationDirPath() +"/JsonFile/cfgFile.json";
QFile cfgFile(strCfgFilePath);
if (cfgFile.open(QIODevice::ReadOnly)) {
QByteArray data = cfgFile.readAll();
QJsonDocument doc = QJsonDocument::fromJson(data);
QJsonObject jsonObj = doc.object();
QJsonObject FlashObj = jsonObj["FlashData"].toObject();
ui->FlashReadAddressLE->setText(FlashObj["ReadAdd"].toString());
ui->FlashReadLenthLE->setText(FlashObj["ReadLen"].toString());
ui->FlashFromAddressLE->setText(FlashObj["WriteAdd"].toString());
ui->FlashFromLenthLE->setText(FlashObj["WriteLen"].toString());
ui->FlashEraseAddressLE->setText(FlashObj["EraseAdd"].toString());
ui->FlashEraseCombox->setCurrentIndex(FlashObj["EraseType"].toInt());
ui->FlashVerifyAddressLE->setText(FlashObj["CheckAdd"].toString());
ui->FlashVerifyLenthLE->setText(FlashObj["CheckLen"].toString());
ui->FLashCopySrcAddressLE->setText(FlashObj["BackSrceAdd"].toString());
ui->FlashCopyDestAddrLE->setText(FlashObj["BackDesAdd"].toString());
ui->FlashCopyLenthLE->setText(FlashObj["BackLen"].toString());
QJsonObject PureToneObj = jsonObj["PureToneData"].toObject();
ui->soundPresLE->setText(PureToneObj["SPL"].toString());
ui->soundFrequencyLE->setText(PureToneObj["Frequency"].toString());
ui->soundCycleLE->setText(PureToneObj["Cycle"].toString());
ui->soundContinueLE->setText(PureToneObj["Sound"].toString());
ui->soundNumsLE->setText(PureToneObj["SoundNum"].toString());
QJsonObject PassWdObj = jsonObj["PassWordData"].toObject();
ui->InitPasswordLevelCombox->setCurrentIndex(PassWdObj["InitPerm"].toInt());
ui->getPermLevelCombox->setCurrentIndex(PassWdObj["InputPerm"].toInt());
ui->changePaswdLevelCombox->setCurrentIndex(PassWdObj["ModifyPerm"].toInt());
ui->clearPaswdLevelCombox->setCurrentIndex(PassWdObj["ClearPerm"].toInt());
QJsonObject WDRCObj = jsonObj["WDRCData"].toObject();
ui->WDRCATLineEdit->setText(WDRCObj["AT"].toString());
ui->WDRCRTLineEdit->setText(WDRCObj["RT"].toString());
ui->WDRCChannelCounBox->setCurrentText(WDRCObj["ChannelCount"].toString());
QString WdrcCount = WDRCObj["ChannelCount"].toString();
if(WdrcCount.isEmpty()){
WdrcCount = "4";
}
on_WDRCChannelCounBox_currentTextChanged(WdrcCount);
QJsonObject NRNLIObj = jsonObj["NRNLIData"].toObject();
ui->NRNLICalibrationLeftLineEdit->setText(NRNLIObj["LeftValue"].toString());
ui->NRNLICalibrationRightLineEdit->setText(NRNLIObj["RightValue"].toString());
QJsonObject DirObj = jsonObj["fileDialogDirData"].toObject();
QString strFlashRead = DirObj["FlashReadDir"].toString();
QString strFlashWrite = DirObj["FlashWriteDir"].toString();
QString strOTAModelPath = DirObj["OtaModelDir"].toString();
QJsonObject otaModelFilePathObj = jsonObj["otaModelFilePath"].toObject();
QString strFirmwareFilePath = otaModelFilePathObj["firmwareFilePath"].toString();
QString strCfgFilePath = otaModelFilePathObj["cfgFilePath"].toString();
QString strAlg1FilePath = otaModelFilePathObj["alg1FilePath"].toString();
QString strAlg2FilePath = otaModelFilePathObj["alg2FilePath"].toString();
QString strAlg3FilePath = otaModelFilePathObj["alg3FilePath"].toString();
QString strAlg4FilePath = otaModelFilePathObj["alg4FilePath"].toString();
ui->firmwareUpdataFilePathlineEdit->setText(strFirmwareFilePath);
ui->configFilePathEdit->setText(strCfgFilePath);
ui->AlgArgUpdataFilePathlineEdit_1->setText(strAlg1FilePath);
ui->AlgArgUpdataFilePathlineEdit_2->setText(strAlg2FilePath);
ui->AlgArgUpdataFilePathlineEdit_3->setText(strAlg3FilePath);
ui->AlgArgUpdataFilePathlineEdit_4->setText(strAlg4FilePath);
ui->exportArgCountBox->setCurrentIndex(otaModelFilePathObj["algFileCount"].toInt());
if(!strFlashRead.isEmpty()){
m_strFalshReadPath = strFlashRead;
}
if(!strFlashWrite.isEmpty()){
m_strFalshWritePath = strFlashWrite;
}
if(!strOTAModelPath.isEmpty()){
m_strOTAModelPath = strOTAModelPath;
}
QJsonObject SerialObj = jsonObj["serialPortData"].toObject();
ui->SerialNameBox->setCurrentText(SerialObj["SerialName"].toString());
ui->comboBoxFre->setCurrentText(SerialObj["SerialFre"].toString());
cfgFile.close();
}
}
void CHearingAidvMainWindow::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_F1) {
on_userGuiBtn_clicked();
}
QWidget::keyPressEvent(event);
}
void CHearingAidvMainWindow::showStatusBarlightBtn(QString msg, int ret)
{
if(ret == 0){
ui->isSuccessStatusShowWidget->setStyleSheet("border-radius:8px;background-color:green;");
ui->errorMsgShowLabel->setStyleSheet("color:green;");
}else if(ret == 99){
ui->isSuccessStatusShowWidget->setStyleSheet("border-radius:8px;background-color:gray;");
ui->errorMsgShowLabel->setStyleSheet("color:black;");
}else {
ui->isSuccessStatusShowWidget->setStyleSheet("border-radius:8px;background-color:red;");
ui->errorMsgShowLabel->setStyleSheet("color:red;");
}
ui->errorMsgShowLabel->setText(msg);
}
void CHearingAidvMainWindow::initCalibrationValue()
{
ui->DeviceModeNumLeftMicBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
ui->DeviceModeNumLeftMicBox->setMinimumContentsLength(5);
ui->DeviceModeNumRightMicBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
ui->DeviceModeNumRightMicBox->setMinimumContentsLength(5);
ui->DeviceModeNumLeftReceiverBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
ui->DeviceModeNumLeftReceiverBox->setMinimumContentsLength(5);
ui->DeviceModeNumRightReceiverBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
ui->DeviceModeNumRightReceiverBox->setMinimumContentsLength(5);
ui->cbCutLowFreq->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
ui->cbCutLowFreq->setMinimumContentsLength(5);
ui->cbCutLowFreq->clear();
ui->cbCutLowFreq->addItem("关");
ui->cbCutLowFreq->addItem("开");
ui->cbCutLowFreq->setCurrentIndex(0);
slotMicDeviceNumRefresh();
slotMicRightDeviceNumRefresh();
slotReceiverDeviceNumRefresh();
slotReceiverRightDeviceNumRefresh();
}
void CHearingAidvMainWindow::initBtnStatus()
{
ui->ArgNumWidget->hide();
ui->DeviceTypeWidget->hide();
ui->VloumeWidget->hide();
ui->BackUpWidget->hide();
ui->PickupArgWidget->hide();
}
void CHearingAidvMainWindow::initTabFocusOrder()
{
QWidget* arr[] = {ui->NoiseHorizontalSlider,ui->NRARGWriteBtn,
ui->NRNLICalibrationLeftLineEdit,ui->NRNLIDataWriteBtn,
ui->InitPasswordLevelCombox,ui->clearPasswdBt,
ui->soundPresLE,ui->voiceCtrlBt,
ui->firmwareUpdataFilePathlineEdit,ui->OTADataSplicingBtn,
ui->VolumeKeyModeRadioBtn,ui->CfgCmdWriteAllBtn
};
int len = sizeof(arr)/sizeof(QWidget*);
int count = len/2;
for (int i=0;i<count;i++){
arr[2*i+1]->installEventFilter(new ChangeTabOrder(arr[2*i]));
}
QList<QWidget*>arrWDRCList;
arrWDRCList.append(ui->FrequencyBandCoBoxFirst);
arrWDRCList.append(ui->WDRCChannelCounBox);
int nOffset = 2;
CWDRCItemWidget *pWidget = NULL;
QList<CWDRCItemWidget*>WdrcitemList = ui->scrollAreaWidgetContents->findChildren<CWDRCItemWidget*>();
int nCount = ui->WDRCChannelCounBox->currentText().toInt();
for (int k=0;k<nCount * 4;k++){
arrWDRCList.append(nullptr);
}
for(int i = 0; i < nCount;i++){
if(WdrcitemList.size() > 0){
pWidget = WdrcitemList.at(i);
}
if(pWidget){
arrWDRCList[nOffset + i] = pWidget->getWDRCData().pGainComBox;
arrWDRCList[nOffset + nCount + i] = pWidget->getWDRCData().pCTComBox;
arrWDRCList[nOffset + 2 * nCount + i] =pWidget->getWDRCData().pCRSpinBox;
arrWDRCList[nOffset + 3 * nCount + i] =pWidget->getWDRCData().pMPOCoBox;
}
}
arrWDRCList.append(ui->WDRCATLineEdit);
arrWDRCList.append(ui->WDRCRTLineEdit);
arrWDRCList.append(ui->WDRCReadArgTogether);
arrWDRCList.append(ui->WDRCwriteArgTogether);
int ctlCount = arrWDRCList.count();
for (int i=0;i<ctlCount;i++){
if (i == ctlCount - 1){
arrWDRCList[ctlCount - 1]->installEventFilter(new ChangeTabOrder(arrWDRCList[0]));
}else{
QWidget::setTabOrder(arrWDRCList[i],arrWDRCList[i+1]);
}
}
QList<QWidget*>arrEQList;
CEQItemWidget *pEQWidget = NULL;
QList<CEQItemWidget*>EqitemList = ui->EQScrollAreaWidgetContents->findChildren<CEQItemWidget*>();
for(int i =0; i < EqitemList.size(); i++){
pEQWidget = EqitemList.at(i);
if(pEQWidget){
arrEQList.append(pEQWidget->getSlider());
}
}
arrEQList.append(ui->EQArgRead64ChannelBtn);
arrEQList.append(ui->EQArgWrite64ChannelBtn);
int EQctlCount = arrEQList.count();
for (int i=0;i<EQctlCount;i++){
if (i == EQctlCount - 1){
arrEQList[EQctlCount - 1]->installEventFilter(new ChangeTabOrder(arrEQList[0]));
}else{
QWidget::setTabOrder(arrEQList[i],arrEQList[i+1]);
}
}
}
QString CHearingAidvMainWindow::parseTimeShowUi(QString time)
{
QDateTime dateTime;
QString formattedTime;
if(time.length() == 8){
dateTime = QDateTime::fromString(time, "yyyyMMdd");
formattedTime = dateTime.toString("yyyy/MM/dd");
}else{
dateTime = QDateTime::fromString(time, "yyyyMMddhhmmss");
formattedTime = dateTime.toString("yyyy/MM/dd\nhh:mm:ss");
}
return formattedTime;
}
void CHearingAidvMainWindow::getDirFileAll(QString pathDir, QFileInfoList &fileList)
{
QDir dir(pathDir);
if(!dir.exists()){
return;
}
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
dir.setNameFilters(QStringList() << "*.txt");
fileList = dir.entryInfoList();
}
void CHearingAidvMainWindow::getFileCalibrationData(int type,QString strFilePath, QByteArray &fileDataArry)
{
QString strTailFilePath;
if(type == DEVICE_MIC){
strTailFilePath = QCoreApplication::applicationDirPath() +
"/MicCalibrationValue/" +QString("%1.txt").arg(strFilePath);
}else if(type == DEVICE_RECEIVER){
strTailFilePath = QCoreApplication::applicationDirPath() +
"/ReceiverCalibrationValue/" +QString("%1.txt").arg(strFilePath);
}
QFile file(strTailFilePath);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
QStringList values = line.split(' ');
foreach (const QString &value, values) {
qint8 Calibration = static_cast<qint8>(value.toInt());
fileDataArry.append(Calibration);
}
}
file.close();
}
}
void CHearingAidvMainWindow::initConnects()
{
connect(m_pSerialWork, &SerialWork::signaleStartTimer,this, &CHearingAidvMainWindow::slotStartTimer);
connect(m_pSerialWork, &SerialWork::signaleStopTimer,this, &CHearingAidvMainWindow::slotStopTimer);
connect(m_pSerialWork, &SerialWork::signalShowChannelCountDefault,this, &CHearingAidvMainWindow::slotShowChannelCountDefault);
connect(m_pSerialWork, &SerialWork::signalInitUIData,this, &CHearingAidvMainWindow::slotInitUiData);
connect(this, &CHearingAidvMainWindow::signalFlashToUiOrFile,m_pSerialWork, &SerialWork::slotFlashReadToUiOrFile);
connect(m_pSerialWork, &SerialWork::signalFlashData,this, &CHearingAidvMainWindow::slotFlashDataUpdata);
connect(m_pSerialWork, &SerialWork::signalShowUpdateCmdReadData,this, &CHearingAidvMainWindow::slotShowUpdataCmdReadData);
connect(m_pSerialWork, &SerialWork::signaShowMesgbox,this, &CHearingAidvMainWindow::slotShowMsgBox);
connect(m_pSerialWork, &SerialWork::signaShowMesgboxDialog,this, &CHearingAidvMainWindow::slotShowMsgBoxdialog);
connect(m_pSerialWork, &SerialWork::signaShowMegDevStatus,this, &CHearingAidvMainWindow::slotShowMsgDevStatus);
connect(m_pSerialWork, &SerialWork::signalCMDWriteFinshed,this, &CHearingAidvMainWindow::slotCmdWriteFinshed);
connect(m_pSerialWork, &SerialWork::signalCMDAllFinshed,this, &CHearingAidvMainWindow::slotAllCmdFinshed);
connect(m_pSerialWork, &SerialWork::signalShowNoOper,this, &CHearingAidvMainWindow::slotStausBarNoOper);
connect(m_pSerialWork, &SerialWork::signalOperationResult,this, &CHearingAidvMainWindow::slotShowAnswerResult);
connect(m_pSerialWork, &SerialWork::signalShowVolumeCurrNum,this, &CHearingAidvMainWindow::slotShowReadCurrCtrlCMDNum);
connect(m_pSerialWork, &SerialWork::signalShowCfgCmdReadData,this, &CHearingAidvMainWindow::slotShowCfgCmdReadData);
connect(m_pSerialWork, &SerialWork::signalShowAlgCmdReadData,this, &CHearingAidvMainWindow::slotShowAlgeriaCmdReadData);
connect(ui->flashSwitchBtn, &SwitchButton::checkedChanged, this ,&CHearingAidvMainWindow::slotFlashSwitchBtnClicked);
connect(ui->changeNewpaswdLE,&LineEditPassword::textChanged,this,&CHearingAidvMainWindow::on_changeOldpaswdLE_textChanged);
connect(ui->VolumeMuteLeftSwithBtn, &SwitchButton::checkedChanged, this ,&CHearingAidvMainWindow::slotVolumeMuteSwithBtnClicked);
connect(ui->VolumeMuteRightSwithBtn, &SwitchButton::checkedChanged, this ,&CHearingAidvMainWindow::slotVolumeMuteSwithBtnClicked);
connect(ui->soundContinueLE,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_soundPresLE_textChanged);
connect(ui->soundCycleLE,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_soundPresLE_textChanged);
connect(ui->soundFrequencyLE,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_soundPresLE_textChanged);
connect(ui->soundNumsLE,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_soundPresLE_textChanged);
connect(ui->soundPresLE,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_soundPresLE_textChanged);
connect(ui->AlgARGBtn_1,&QPushButton::clicked,this,&CHearingAidvMainWindow::slotChangeAlgArgBtnClick);
connect(ui->AlgARGBtn_2,&QPushButton::clicked,this,&CHearingAidvMainWindow::slotChangeAlgArgBtnClick);
connect(ui->AlgARGBtn_3,&QPushButton::clicked,this,&CHearingAidvMainWindow::slotChangeAlgArgBtnClick);
connect(ui->AlgARGBtn_4,&QPushButton::clicked,this,&CHearingAidvMainWindow::slotChangeAlgArgBtnClick);
connect(ui->modeTypeBtn_0,&QRadioButton::clicked,this,&CHearingAidvMainWindow::slotChangeModeTypeBtnClick);
connect(ui->modeTypeBtn_1,&QRadioButton::clicked,this,&CHearingAidvMainWindow::slotChangeModeTypeBtnClick);
connect(ui->modeTypeBtn_2,&QRadioButton::clicked,this,&CHearingAidvMainWindow::slotChangeModeTypeBtnClick);
connect(ui->modeTypeBtn_3,&QRadioButton::clicked,this,&CHearingAidvMainWindow::slotChangeModeTypeBtnClick);
connect(ui->algBypassSwitch,&SwitchButton::checkedChanged,this,&CHearingAidvMainWindow::slotAlgSwitchBtnClicked);
connect(ui->algNLISwitchBtn,&SwitchButton::checkedChanged,this,&CHearingAidvMainWindow::slotAlgSwitchBtnClicked);
connect(ui->algNRSwitchBtn,&SwitchButton::checkedChanged,this,&CHearingAidvMainWindow::slotAlgSwitchBtnClicked);
connect(ui->algWDRCSwitchBtn,&SwitchButton::checkedChanged,this,&CHearingAidvMainWindow::slotAlgSwitchBtnClicked);
connect(ui->algEQSwitchBtn,&SwitchButton::checkedChanged,this,&CHearingAidvMainWindow::slotAlgSwitchBtnClicked);
connect(ui->algHSSwitchBtn,&SwitchButton::checkedChanged,this,&CHearingAidvMainWindow::slotAlgSwitchBtnClicked);
connect(ui->algFFTSwitchBtn,&SwitchButton::checkedChanged,this,&CHearingAidvMainWindow::slotAlgSwitchBtnClicked);
connect(ui->pickupLeftChannelPGAEdit,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_pickupLeftChannelDGAEdit_textChanged);
connect(ui->pickupRightChannelDGAEdit,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_pickupLeftChannelDGAEdit_textChanged);
connect(ui->pickupRightChannelPGAEdit,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_pickupLeftChannelDGAEdit_textChanged);
connect(ui->playbackArgRightChannelDGAEdilt,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_playbackArgLeftChannelDGAEdilt_textChanged);
connect(ui->NRNLICalibrationRightLineEdit,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_NRNLICalibrationLeftLineEdit_textChanged);
connect(ui->WDRCRTLineEdit,&QLineEdit::textChanged,this,&CHearingAidvMainWindow::on_WDRCATLineEdit_textChanged);
connect(ui->SerialNameBox,&ComboBoxCustom::signalComboBoxClicked,this,&CHearingAidvMainWindow::slotSerialNameBoxRefresh);
connect(ui->DeviceModeNumLeftMicBox,&ComboBoxCustom::signalComboBoxClicked,this,&CHearingAidvMainWindow::slotMicDeviceNumRefresh);
connect(ui->DeviceModeNumRightMicBox,&ComboBoxCustom::signalComboBoxClicked,this,&CHearingAidvMainWindow::slotMicRightDeviceNumRefresh);
connect(ui->DeviceModeNumLeftReceiverBox,&ComboBoxCustom::signalComboBoxClicked,this,&CHearingAidvMainWindow::slotReceiverDeviceNumRefresh);
connect(ui->DeviceModeNumRightReceiverBox,&ComboBoxCustom::signalComboBoxClicked,this,&CHearingAidvMainWindow::slotReceiverRightDeviceNumRefresh);
connect(ui->channelLeftCtrlBtn,&QCheckBox::clicked,this,&CHearingAidvMainWindow::slotVolumeChannelSelectClicked);
connect(ui->channelRightCtrlBtn,&QCheckBox::clicked,this,&CHearingAidvMainWindow::slotVolumeChannelSelectClicked);
}
void CHearingAidvMainWindow::slotIsSelectAllCheckBox(bool isChecked)
{
for(auto checkBox: ui->scrollArea->m_checkList){
checkBox->setChecked(isChecked);
}
}
void CHearingAidvMainWindow::slotEQArgIsSelectAllCheckBox(bool isChecked)
{
for(auto checkBox: ui->EQArgscrollArea->m_checkList){
checkBox->setChecked(isChecked);
}
}
void CHearingAidvMainWindow::initEQUi()
{
m_eq_status.resize(64);
m_eq_status.fill(0);
QString path = QCoreApplication::applicationDirPath();
QFile file(path + "/JsonFile/EQChannelRange.json");
QString msg;
if(!file.exists()){
msg = "EQ频点数据文件不存在";
slotShowMsgBox(msg);
return;
}
if(file.size() == 0){
msg = "EQ频点数据文件为空";
slotShowMsgBox(msg);
return;
}
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
msg = "EQ频点数据文件无法打开";
slotShowMsgBox(msg);
return;
}
QString str = file.readAll();
file.close();
QJsonParseError parseJsonErr;
QJsonDocument document = QJsonDocument::fromJson(str.toUtf8(), &parseJsonErr);
if (!(parseJsonErr.error == QJsonParseError::NoError)) {
slotShowMsgBox("EQ频点数据文件错误");
return;
}
QJsonObject jsonObject = document.object();
if (jsonObject.contains(QStringLiteral("EQ Channel Range"))) {
QJsonValue arrayValue = jsonObject.value(QStringLiteral("EQ Channel Range"));
if (arrayValue.isArray()) {
QJsonArray array = arrayValue.toArray();
int size = 0;
size = array.size();
for(int i = 0; i < size ; i++){
QString strChannel = QString("%1").arg(array.at(i).toString());
CEQItemWidget * pWidget = new CEQItemWidget(this);
pWidget->setChecBoxLabelString(strChannel);
pWidget->setSliderObjName(i);
connect(pWidget,&CEQItemWidget::signalIsSelectAllCheckBox,
this,&CHearingAidvMainWindow::slotEQArgIsSelectAllCheckBox);
connect(pWidget->getSlider(),&QSlider::valueChanged,
this,&CHearingAidvMainWindow::slotSetEqSliderPosSynchronization);
connect(this,&CHearingAidvMainWindow::signalEQIsSelectAll,
pWidget,&CEQItemWidget::slotSetEQIsSelectAllCheckBox);
connect(pWidget->getSignalCheckBox(),&QCheckBox::clicked,
this,&CHearingAidvMainWindow::slotEqSigalClicked);
connect(ui->EQArgscrollArea,&RubberScrollArea::signalSelectAllcheckbox,
pWidget,&CEQItemWidget::slotSetEQIsSelectAllCheckBox);
if(i < size / 4){
ui->HLEQ_1->addWidget(pWidget);
}else if(i < size / 2){
ui->HLEQ_2->addWidget(pWidget);
}else if(i < size / 4 *3){
ui->HLEQ_3->addWidget(pWidget);
}else if(i < size){
ui->HLEQ_4->addWidget(pWidget);
}
if(i == (size / 4 *1) -1 || i == (size /4 *2) -1 ||
i == (size / 4 *3) -1 || i == size -1){
pWidget->setHeadWidgetHide(true);
}
if(i == 0){
pWidget->setHeadCheckBoxHide(true);
}
m_eq_status[i]= pWidget->getSlider()->sliderPosition();
}
}
}
ui->EQArgscrollArea->m_checkList= this->findChildren<QCheckBox*>("EQChannelCheckBox");
}
QByteArray CHearingAidvMainWindow::getPaswd(QLineEdit *le)
{
QByteArray array;
array = le->text().trimmed().toUtf8();
return array;
}
void CHearingAidvMainWindow::on_getPermissionBt_clicked()
{
if(ui->permPasswdLE->text().length() != PASSWORD_LENTH){
slotShowMsgBox("获取密码不得少于8位");
return;
}
QByteArray array = getPaswd(ui->permPasswdLE);
uchar level = ui->getPermLevelCombox->currentText().toInt();
array.append(level);
int ret = m_pSerialWork->processData(CMD_UPDATE_0x03, INST_CMD_0x00, array);
if(ret != 0)
return;
}
void CHearingAidvMainWindow::on_changePasswdBt_clicked()
{
if(ui->changeOldpaswdLE->text().length() != PASSWORD_LENTH ||
ui->changeNewpaswdLE->text().length() != PASSWORD_LENTH ||
ui->changeConfirmPaswdLE->text().length() != PASSWORD_LENTH){
slotShowMsgBox("更改密码不得少于8位");
return;
}
QByteArray array = getPaswd(ui->changeOldpaswdLE);
if(!(ui->changeNewpaswdLE->text() == ui->changeConfirmPaswdLE->text())){
slotShowMsgBox("新密码和确认密码不一致");
return;
}
array.append(getPaswd(ui->changeNewpaswdLE));
uchar level = ui->changePaswdLevelCombox->currentText().toInt();
array.append(level);
int ret = m_pSerialWork->processData(CMD_UPDATE_0x03, INST_CMD_0x01, array);
if(ret != 0)
return;
}
void CHearingAidvMainWindow::on_clearPasswdBt_clicked()
{
if(ui->clearPaswdLE->text().length() != PASSWORD_LENTH){
slotShowMsgBox("清除密码不得少于8位");
return;
}
QByteArray array = getPaswd(ui->clearPaswdLE);
uchar level = ui->clearPaswdLevelCombox->currentText().toInt();
array.append(level);
int ret = m_pSerialWork->processData(CMD_UPDATE_0x03, INST_CMD_0x02, array);
if(ret != 0)
return;
}
QByteArray CHearingAidvMainWindow::getHexAddr(QLineEdit *le)
{
bool ok;
QString strResAddress = le->text().trimmed().replace(" ","");
int dec = strResAddress.toInt(&ok,16);
QByteArray array = intToArry(dec);
return array;
}
void CHearingAidvMainWindow::on_FlashReadToUiBt_clicked()
{
m_nReadFileDataTailSize = 0;
ui->FlashReadTE->clear();
if(ui->FlashReadLenthLE->text().isEmpty()){
slotShowMsgBox("请先输入Flash读取的长度");
return;
}
emit signalFlashToUiOrFile(CODE_FLAG_1);
m_nReadFileDataTailSize = ui->FlashReadLenthLE->text().toInt();
initProcessProgressBar();
uartReadBytes512();
}
void CHearingAidvMainWindow::on_FlashFileReadBtn_clicked()
{
QString filePath = QFileDialog::getSaveFileName(this, tr("读取到文件"), QDir::currentPath(), tr("Bin Files (*.bin);;Text Files (*.txt)"));
if (!filePath.isEmpty()) {
m_flashReadFile.setFile(filePath);
}
}
int CHearingAidvMainWindow::uartWriteFileBytes(int transmissionsCount,QByteArray fileDataArray)
{
FileDealManger *m_pFileOperation = nullptr;
m_pFileOperation = new FileDealManger();
m_pFileOperation->setDataSourceUi(reinterpret_cast<unsigned char*>(fileDataArray.data()));
m_nWriteFullSize = 0;
QByteArray sendData;
sendData.clear();
bool ok;
QString strResAddress = ui->FlashFromAddressLE->text().trimmed().replace(" ","");
int dec = strResAddress.toInt(&ok,16);
int address =dec + transmissionsCount*WRITE_DATA_SIZE;
QByteArray startAddress = m_pFileOperation->intToArry32(address);
m_pFileOperation->getFilePiecewiseArry(m_nLastPackDataSize, transmissionsCount,m_nSendCount,&m_pArrySectionalData256,m_nWriteFullSize);
QByteArray sendFileSizeArry = m_pFileOperation->intToArry32(m_nWriteFullSize);
QByteArray fileDataArry = QByteArray::fromRawData(reinterpret_cast<const char *>(m_pArrySectionalData256), m_nWriteFullSize);
sendData.append(startAddress);
sendData.append(sendFileSizeArry);
sendData.append(fileDataArry);
int ret = m_pSerialWork->processData(CMD_UPDATE_0x03, INST_CMD_0x21,sendData);
if(ret != 0)
return ret;
return 0;
}