forked from lmdpua/A2168_Laptop_Battery_Flasher_on_CP2112
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
146 lines (116 loc) · 7.16 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "types.h"
#include "Library\Windows\SLABCP2112.h"
#include <QLabel>
#include <QMessageBox>
#include <QModelIndex>
#include <QAbstractItemView>
#include "A2168_interface.h"
#include <QFile>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
flashData = new QByteArray;//выделим память для массива из кучи
flashArrayIsFull = false;
timerStatusBar = new QTimer();
connect(timerStatusBar, SIGNAL(timeout()), this, SLOT(slotTimerStatusBarAlarm()));
timerStatusBar->start(2000); // Запустим таймер на 2 секунды
timerStandartSBSReading = new QTimer();
connect(timerStandartSBSReading, SIGNAL(timeout()), this, SLOT(on_button_StandartSBS_ReadOnce_clicked()));
//Таймер запускается в другом месте, по кнопке
statusbarTable = new QTableWidget;
setTableStatusbar(statusbarTable);
connect(&device, &CP2112::connected_Changed, [=](){statusbarTable->item(0,0)->setText(device.getConnected()) ; });
connect(&device, &CP2112::serial_Changed, [=](){statusbarTable->item(1,0)->setText(device.getSerial()) ; });
connect(&device, &CP2112::manufacturer_Changed, [=](){statusbarTable->item(0,1)->setText(device.getManufacturer()) ; });
connect(&device, &CP2112::product_Changed, [=](){statusbarTable->item(1,1)->setText(device.getProduct()) ; });
connect(&device, &CP2112::status_Changed, [=](){statusbarTable->item(0,2)->setText(device.getStatus()) ; });
connect(&device, &CP2112::status_0_Changed, [=](){statusbarTable->item(1,2)->setText(device.getStatus_0()) ; });
connect(&device, &CP2112::status_1_Changed, [=](){statusbarTable->item(1,3)->setText(device.getStatus_1()) ; });
device.readINI();
slotTimerStatusBarAlarm();
// device.init();
// ui->lineEdit_8->setText(QString ("%1").arg(device.getConfig(Bitrate).toInt()));
// ui->lineEdit_9->setText(QString ("0x%1").arg(device.getConfig(ACK_Address).toInt(),2,16,QLatin1Char('0')));
// ui->lineEdit_10->setText(QString ("%1").arg(device.getConfig(Auto_Respond).toBool()));
// ui->lineEdit_11->setText(QString ("%1").arg(device.getConfig(Write_Timeout).toInt()));
// ui->lineEdit_12->setText(QString ("%1").arg(device.getConfig(Read_Timeout).toInt()));
// ui->lineEdit_13->setText(QString ("%1").arg(device.getConfig(Transfer_Retries).toInt()));
// ui->lineEdit_14->setText(QString ("%1").arg(device.getConfig(SCL_Low_Timeout).toBool()));
// ui->lineEdit_15->setText(QString ("%1").arg(device.getConfig(Response_Timeout).toInt()));
// ui->lineEdit_16->setText(QString ("%1").arg(device.getConfig(RX_TX_Leds_On).toBool()));
setTableStandardSBS (ui->tableViewStandartSBSLeft, tableStandartSBS_Left, 0, 21);
setTableStandardSBS (ui->tableViewStandartSBSRight, tableStandartSBS_Right, 21, 38);
setTableExtendedUnseal (ui->tableViewExtendedUnsealLeft, tableExtendedUnseal_Left, 0,19);
setTableExtendedUnseal (ui->tableViewExtendedUnsealRight, tableExtendedUnseal_Right, 19,31);
setTableFlashMemory(ui->tableViewFlashMemory, tableFlashMemory);
//Реакция на клик по таблице Flash Memory
connect(ui->tableViewFlashMemory->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)), this,
SLOT(onTableFlashMemoryCellClicked(QModelIndex, QModelIndex)));
setTableBitFlags(ui->tableViewFETControl, tableFETControl, FETControl);
setTableBitFlags(ui->tableViewStateOfHealth, tableStateOfHealth, StateOfHealth);
setTableBitFlags(ui->tableViewSafetyAlarm1, tableSafetyAlarm1, SafetyAlarm1);
setTableBitFlags(ui->tableViewPFAlarm1, tablePFAlarm1, PFAlarm1);
setTableBitFlags(ui->tableViewOperationStatus, tableOperationStatus, OperationStatus);
setTableBitFlags(ui->tableViewChargingStatus, tableChargingStatus, ChargingStatus);
setTableBitFlags(ui->tableViewSafetyAlarm2, tableSafetyAlarm2, SafetyAlarm2);
setTableBitFlags(ui->tableViewPFAlarm2, tablePFAlarm2, PFAlarm2);
setTableBitFlags(ui->tableViewTempRange, tableTempRange, TempRange);
quint8 row=0;
row = sizeof(list_First_Level_Protection)/sizeof(list_First_Level_Protection[0]);
setTableFlashDetailed(ui->tableView1stLevelProtection, table1stLevelProtection, list_First_Level_Protection, row);
row = sizeof(list_Second_Level_Protection)/sizeof(list_Second_Level_Protection[0]);
setTableFlashDetailed(ui->tableView2ndLevelProtection, table2ndLevelProtection, list_Second_Level_Protection, row);
row = sizeof(list_Charge_Control)/sizeof(list_Charge_Control[0]);
setTableFlashDetailed(ui->tableViewChargeControl, tableChargeControl, list_Charge_Control, row);
row = sizeof(list_System_Setting)/sizeof(list_System_Setting[0]);
setTableFlashDetailed(ui->tableViewSystemSetting, tableSystemSetting, list_System_Setting, row);
row = sizeof(list_SBS_Setting)/sizeof(list_SBS_Setting[0]);
setTableFlashDetailed(ui->tableViewSBS_Setting, tableSBS_Setting, list_SBS_Setting, row);
row = sizeof(list_System_Data)/sizeof(list_System_Data[0]);
setTableFlashDetailed(ui->tableViewSystemData, tableSystemData, list_System_Data, row);
row = sizeof(list_Gas_Gauge)/sizeof(list_Gas_Gauge[0]);
setTableFlashDetailed(ui->tableViewGasGauge, tableGasGauge, list_Gas_Gauge, row);
row = sizeof(list_Calibration)/sizeof(list_Calibration[0]);
setTableFlashDetailed(ui->tableViewCalibration, tableCalibration, list_Calibration, row);
row = sizeof(list_LED_Support)/sizeof(list_LED_Support[0]);
setTableFlashDetailed(ui->tableViewLEDSupport, tableLEDSupport, list_LED_Support, row);
on_button_SBS_clicked();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slotTimerStatusBarAlarm()
{
if(device.isInTransferMode())return;//Если устройство в режиме передачи, выходим
device.setTransfer(true);//Ставим влаг, что устройство в режиме передачи
if(!device.init()){
device.setTransfer(false); //Снимаем флаг, что устройство в режиме передачи
return;
}
QString str = "Speed: " + QString::number(device.getSpeed()) + "Hz";
statusbarTable->item(1,4)->setText(str);
if(battery.isConnected(&device)){
statusbarTable->item(0,3)->setText("Battery Connected");
quint16 data;
battery.readWord(&device,0x0d,&data);
batteryLevel->setValue(data);
// QByteArray array;
// quint8 len=0;
// battery.readBlock(&device,0x22,&array,&len);
// QString str;
// str.append(array);
// statusbarTable->item(1,4)->setText(str);
}else{
statusbarTable->item(0,3)->setText("Battery Not Connected");
batteryLevel->setValue(0);
}
// device.disconnect(); //Отключим все стигналы
device.close();
device.setTransfer(false); //Снимаем флаг, что устройство в режиме передачи
}