Skip to content

Commit 40d755b

Browse files
authored
Merge pull request #497 from deXol/develop
Make sure init messages are called first with a TimerJob
2 parents b25dc0f + 613e4e1 commit 40d755b

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/MPDevice.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,34 +140,31 @@ void MPDevice::setupMessageProtocol()
140140

141141
void MPDevice::sendInitMessages()
142142
{
143-
statusTimer->start(500);
144-
QTimer::singleShot(100, [this]() {
145-
if (isBLE())
143+
statusTimer->start(STATUS_STARTING_DELAY);
144+
addTimerJob(INIT_STARTING_DELAY);
145+
if (isBLE())
146+
{
147+
/**
148+
* Reset Flip Bit is written directly to device
149+
* so TimerJob has no effect, hence sending
150+
* it with a lower timeout.
151+
*/
152+
QTimer::singleShot(INIT_STARTING_DELAY/2, [this]()
146153
{
147154
if (AppDaemon::isDebugDev())
148155
qDebug() << "Resetting flip bit for BLE";
149-
150156
bleImpl->sendResetFlipBit();
151-
if (bleImpl->isAfterAuxFlash())
152-
{
153-
qDebug() << "Fixing communication with device after Aux Flash";
154-
writeCancelRequest();
155-
}
156-
bleImpl->getPlatInfo();
157-
}
157+
});
158158

159-
exitMemMgmtMode(false);
160-
//TODO Remove when GET_MOOLTIPASS_PARM implemented for BLE
161-
/**
162-
* Temporary solution until GET_MOOLTIPASS_PARM
163-
* is not implemented for the ble device we do not
164-
* get if BLE is detected.
165-
*/
166-
if (isBLE())
159+
if (bleImpl->isAfterAuxFlash())
167160
{
168-
flashMbSizeChanged(0);
161+
qDebug() << "Fixing communication with device after Aux Flash";
162+
writeCancelRequest();
169163
}
170-
});
164+
bleImpl->getPlatInfo();
165+
}
166+
167+
exitMemMgmtMode(false);
171168
}
172169

173170
void MPDevice::sendData(MPCmd::Command c, const QByteArray &data, quint32 timeout, MPCommandCb cb, bool checkReturn)
@@ -500,6 +497,14 @@ void MPDevice::runAndDequeueJobs()
500497
currentJobs->start();
501498
}
502499

500+
void MPDevice::addTimerJob(int msec)
501+
{
502+
auto *waitingJob = new AsyncJobs(QString("Waiting job"), this);
503+
waitingJob->append(new TimerJob{msec});
504+
jobsQueue.enqueue(waitingJob);
505+
runAndDequeueJobs();
506+
}
507+
503508
void MPDevice::updateFilesCache()
504509
{
505510
getStoredFiles([this](bool success, QList<QVariantMap> files)

src/MPDevice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ private slots:
232232
/* Platform function for writing data, should be implemented in platform class */
233233
virtual void platformWrite(const QByteArray &data) { Q_UNUSED(data); }
234234

235+
void addTimerJob(int msec);
235236
void loadLoginNode(AsyncJobs *jobs, const QByteArray &address,
236237
const MPDeviceProgressCb &cbProgress);
237238
void loadLoginChildNode(AsyncJobs *jobs, MPNode *parent, MPNode *parentClone, const QByteArray &address);
@@ -433,6 +434,8 @@ private slots:
433434
EXPORT_IS_BLE_INDEX = 14,
434435
EXPORT_BLE_USER_CATEGORIES_INDEX = 15
435436
};
437+
static constexpr int STATUS_STARTING_DELAY = 500;
438+
static constexpr int INIT_STARTING_DELAY = 300;
436439
};
437440

438441
#endif // MPDEVICE_H

0 commit comments

Comments
 (0)