Skip to content

Commit

Permalink
-no-log added
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Viola <[email protected]>
  • Loading branch information
cagnulein authored and Roberto Viola committed Oct 12, 2020
1 parent c21e337 commit cd1c10a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/domyostreadmill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ bool restart = false;
bool initDone = false;
bool initRequest = false;

QFile* debugCommsLog;
QFile* debugCommsLog = 0;

domyostreadmill::domyostreadmill()
domyostreadmill::domyostreadmill(bool logs)
{
QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
refresh = new QTimer(this);
debugCommsLog = new QFile("debug-" + QDateTime::currentDateTime().toString() + ".log");
debugCommsLog->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
if(logs)
{
debugCommsLog = new QFile("debug-" + QDateTime::currentDateTime().toString() + ".log");
debugCommsLog->open(QIODevice::WriteOnly | QIODevice::Unbuffered);
}

initDone = false;

Expand All @@ -94,8 +97,11 @@ domyostreadmill::domyostreadmill()
void domyostreadmill::debug(QString text)
{
QString debug = QDateTime::currentDateTime().toString() + text + '\n';
debugCommsLog->write(debug.toLocal8Bit());
qDebug() << debug;
if(debugCommsLog)
{
debugCommsLog->write(debug.toLocal8Bit());
qDebug() << debug;
}
}

void domyostreadmill::writeCharacteristic(uint8_t* data, uint8_t data_len, QString info, bool disable_log)
Expand Down
2 changes: 1 addition & 1 deletion src/domyostreadmill.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class domyostreadmill : public treadmill
{
Q_OBJECT
public:
domyostreadmill();
domyostreadmill(bool logs = true);
virtualtreadmill* virtualTreadMill = 0;
bool connected();

Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
#include "domyostreadmill.h"
#include "mainwindow.h"

bool nologs = false;

QCoreApplication* createApplication(int &argc, char *argv[])
{
bool nogui = false;

for (int i = 1; i < argc; ++i) {
if (!qstrcmp(argv[i], "-no-gui"))
nogui = true;
if (!qstrcmp(argv[i], "-no-log"))
nologs = true;
}

if(nogui)
Expand All @@ -22,7 +27,7 @@ int main(int argc, char *argv[])
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));

//virtualtreadmill* V = new virtualtreadmill();
domyostreadmill* D = new domyostreadmill();
domyostreadmill* D = new domyostreadmill(!nologs);

if (qobject_cast<QApplication *>(app.data())) {
// start GUI version...
Expand Down

0 comments on commit cd1c10a

Please sign in to comment.