-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
166 lines (135 loc) · 4.49 KB
/
Copy pathmainwindow.cpp
File metadata and controls
166 lines (135 loc) · 4.49 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
/*
Copyright 2013 Mike Bergmann, Bones AG
This file is part of BSMDemo.
BSMDemo 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 2 of the License, or
(at your option) any later version.
BSMDemo 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 BSMDemo. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "PortListener.h"
#include "qextserialport.h"
#include <QDebug>
#include <QFileDialog>
#include <QSplitter>
#include <QThread>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_ports()
, m_listener(NULL)
{
ui->setupUi(this);
ui->groupBox->setEnabled(false);
ui->pbConnect->setText(tr("&Connect"));
ui->pbRefresh->setText(tr("&Refresh"));
ui->pbSpeak->setText(tr("&Speak"));
checkPorts();
QSplitter *splitter = new QSplitter(this);
splitter->setOrientation(Qt::Vertical);
ui->verticalLayout_2->addWidget(splitter);
ui->teInfo->setParent(splitter);
ui->tePlainText->setParent(splitter);
statusBar()->showMessage(QString("Version ")+qApp->applicationVersion());
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch(e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_pbConnect_clicked()
{
if(ui->cbSerial->count() <= 0)
return;
if(!m_listener) {
m_listener = new PortListener(m_ports.at(ui->cbSerial->currentIndex()).portName, ui->teInfo, ui->tePlainText); // signals get hooked up internally
connect(m_listener,SIGNAL(volumeChanged(int)),ui->sbVolume,SLOT(setValue(int)));
connect(ui->sbVolume,SIGNAL(valueChanged(int)),m_listener,SLOT(setVolume(int)));
m_listener->getVolume();
ui->cbVoice->insertItems(0,m_listener->languages.values());
connect(m_listener,SIGNAL(languageChanged(int)),ui->cbVoice,SLOT(setCurrentIndex(int)));
connect(ui->cbVoice,SIGNAL(currentIndexChanged(int)),m_listener,SLOT(setLanguage(int)));
m_listener->getLanguage();
connect(m_listener, SIGNAL(waitOnIndication(bool)),ui->groupBox,SLOT(setDisabled(bool)));
m_listener->sendHexMessage("7e0103002c7e"); // Get Software Version
ui->groupBox->setEnabled(true);
} else {
ui->groupBox->setEnabled(false);
ui->pbConnect->setText(tr("&Connect"));
delete m_listener;
m_listener = NULL;
}
if(m_listener) {
if(m_listener->isOpen() && m_listener->getLastError() == E_NO_ERROR) {
ui->pbConnect->setText(tr("&Disconnect"));
} else {
ui->groupBox->setEnabled(false);
ui->pbConnect->setText(tr("&Connect"));
delete m_listener;
}
}
}
void MainWindow::checkPorts()
{
m_ports.clear();
ui->cbSerial->clear();
m_ports = QextSerialEnumerator::getPorts();
qDebug() << "List of ports:";
for(int i = 0; i < m_ports.size(); i++) {
#ifdef FTDI_ONLY
if(m_ports.at(i).vendorID == 0x403 && m_ports.at(i).productID == 0x6001) {
qDebug() << "Found FTDI:" << m_ports.at(i).portName;
ui->cbSerial->addItem(m_ports.at(i).friendName);
}
#else
qDebug() << "Found:" << m_ports.at(i).portName;
ui->cbSerial->addItem(m_ports.at(i).friendName);
#endif
qDebug() << "port name:" << m_ports.at(i).portName;
qDebug() << "friendly name:" << m_ports.at(i).friendName;
qDebug() << "physical name:" << m_ports.at(i).physName;
qDebug() << "enumerator name:" << m_ports.at(i).enumName;
qDebug() << "vendor ID:" << QString::number(m_ports.at(i).vendorID, 16);
qDebug() << "product ID:" << QString::number(m_ports.at(i).productID, 16);
qDebug() << "===================================";
}
}
void MainWindow::on_pbRefresh_clicked()
{
checkPorts();
}
void MainWindow::on_pbSpeak_clicked()
{
m_listener->speakText(ui->leSpeak->text());
}
void MainWindow::on_tbPlay_clicked()
{
m_listener->playAndPause();
}
void MainWindow::on_tbUp_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Upload WAV File"), QString(), "*.WAV");
if(!fileName.isEmpty())
m_listener->sendFile(fileName);
}
void MainWindow::on_pbSOS_clicked()
{
m_listener->SOS(ui->leSOS->text());
}