Skip to content

Commit 64b2e08

Browse files
committed
Fix issue with disconnect button
1 parent 8294636 commit 64b2e08

3 files changed

Lines changed: 30 additions & 26 deletions

File tree

assets/qml/main.qml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,16 @@ ApplicationWindow {
239239
Connections {
240240
target: Cpp_JSON_Generator
241241
enabled: !app.firstValidPacket
242-
function onJsonChanged() {
243-
app.firstValidPacket = true
244-
uiConfigTimer.start()
245-
}
246-
} Timer {
247-
id: uiConfigTimer
248-
interval: 250
249-
onTriggered: {
250-
setup.hide()
251-
toolbar.dataClicked()
242+
function onFrameChanged() {
243+
if (Cpp_IO_Manager.connected || Cpp_CSV_Player.isOpen) {
244+
app.firstValidPacket = true
245+
setup.hide()
246+
toolbar.dataClicked()
247+
} else {
248+
toolbar.consoleClicked()
249+
setup.show()
250+
app.firstValidPacket = false
251+
}
252252
}
253253
}
254254

src/JSON/Generator.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ static const QRegExp UNMATCHED_VALUES_REGEX("(%\b([0-9]|[1-9][0-9])\b)");
4848
* Initializes the JSON Parser class and connects appropiate SIGNALS/SLOTS
4949
*/
5050
Generator::Generator()
51-
: m_jsonChanged(false)
52-
, m_dataFormatErrors(0)
53-
, m_opMode(kAutomatic)
51+
: m_opMode(kAutomatic)
5452
{
5553
auto io = IO::Manager::getInstance();
54+
auto cp = CSV::Player::getInstance();
55+
connect(cp, SIGNAL(openChanged()), this, SLOT(reset()));
5656
connect(io, SIGNAL(deviceChanged()), this, SLOT(reset()));
5757
connect(io, SIGNAL(frameReceived(QByteArray)), this, SLOT(readData(QByteArray)));
5858
m_workerThread.start();
@@ -264,13 +264,20 @@ void Generator::setJsonDocument(const QJsonDocument &document, const QDateTime &
264264
if (document.object().isEmpty())
265265
return;
266266

267-
m_jsonChanged = true;
268-
m_document = document;
267+
bool csvOpen = CSV::Player::getInstance()->isOpen();
268+
bool devOpen = IO::Manager::getInstance()->connected();
269269

270-
if (m_frame.read(m_document.object()))
271-
emit frameChanged();
270+
if (csvOpen || devOpen)
271+
{
272+
m_document = document;
273+
if (m_frame.read(m_document.object()))
274+
emit frameChanged();
275+
276+
emit jsonChanged(document, time);
277+
}
272278

273-
emit jsonChanged(document, time);
279+
else
280+
reset();
274281
}
275282

276283
/**
@@ -279,8 +286,11 @@ void Generator::setJsonDocument(const QJsonDocument &document, const QDateTime &
279286
*/
280287
void Generator::reset()
281288
{
282-
m_dataFormatErrors = 0;
283-
setJsonDocument(QJsonDocument::fromJson(QByteArray("{}")));
289+
m_frame.clear();
290+
m_document = QJsonDocument::fromJson(QByteArray("{}"));
291+
292+
emit frameChanged();
293+
emit jsonChanged(document(), QDateTime::currentDateTime());
284294
}
285295

286296
/**

src/JSON/Generator.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ class Generator : public QObject
100100
QString jsonMapFilepath() const;
101101
OperationMode operationMode() const;
102102

103-
QJSEngine *javaScriptEngine() { return &m_engine; }
104-
105103
public slots:
106104
void loadJsonMap();
107105
void setOperationMode(const OperationMode mode);
@@ -123,17 +121,13 @@ private slots:
123121
private:
124122
Frame m_frame;
125123
QFile m_jsonMap;
126-
bool m_jsonChanged;
127124
QSettings m_settings;
128125
QString m_jsonMapData;
129-
int m_dataFormatErrors;
130126
OperationMode m_opMode;
131127
QJsonDocument m_document;
132128

133129
QThread m_workerThread;
134130
JSONWorker *m_jsonWorker;
135-
136-
QJSEngine m_engine;
137131
};
138132
}
139133

0 commit comments

Comments
 (0)