Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. diff --git a/src/atcore.cpp b/src/atcore.cpp
  2. index 3d47405..712de87 100644
  3. --- a/src/atcore.cpp
  4. +++ b/src/atcore.cpp
  5. @@ -53,6 +53,7 @@ AtCore::AtCore(QObject *parent) :
  6. QObject(parent),
  7. d(new AtCorePrivate)
  8. {
  9. + qRegisterMetaType<PrinterState>("PrinterState");
  10. setState(DISCONNECTED);
  11.  
  12. for (const auto &path : AtCoreDirectories::pluginDir) {
  13. @@ -254,14 +255,17 @@ void AtCore::print(const QString &fileName)
  14. connect(printThread, &PrintThread::finished, thread, &QThread::quit);
  15. connect(printThread, &PrintThread::finished, printThread, &PrintThread::deleteLater);
  16. connect(thread, &QThread::finished, printThread, &PrintThread::deleteLater);
  17. - thread->start();
  18. + if(!thread->isRunning())
  19. + thread->start();
  20. }
  21.  
  22. void AtCore::pushCommand(const QString &comm)
  23. {
  24. if (!pluginLoaded()) {
  25. + qDebug() << "Plugin not Loaded !";
  26. serial()->pushCommand(comm.toLocal8Bit());
  27. } else {
  28. + qDebug() << "Plugin Loaded !";
  29. serial()->pushCommand(plugin()->translate(comm));
  30. }
  31. }
  32. diff --git a/src/plugins/repetierplugin.cpp b/src/plugins/repetierplugin.cpp
  33. index b67ae97..3e93c82 100644
  34. --- a/src/plugins/repetierplugin.cpp
  35. +++ b/src/plugins/repetierplugin.cpp
  36. @@ -60,9 +60,8 @@ void RepetierPlugin::validateCommand(const QString &lastMessage)
  37. {
  38. if (lastMessage.contains(_extruderTemp) || lastMessage.contains(_bedTemp)) {
  39. extractTemp(lastMessage);
  40. - } else if (lastMessage.contains(_ok) || lastMessage.contains(_wait)) {
  41. - emit readyForCommand();
  42. }
  43. + emit readyForCommand();
  44. }
  45.  
  46. QByteArray RepetierPlugin::translate(const QString &command)
  47. diff --git a/src/printThread.cpp b/src/printThread.cpp
  48. index 324d724..f1736ed 100644
  49. --- a/src/printThread.cpp
  50. +++ b/src/printThread.cpp
  51. @@ -3,6 +3,7 @@
  52. #include "gcodecommands.h"
  53.  
  54. #include <QDebug>
  55. +#include <QMutexLocker>
  56.  
  57. class PrintThreadPrivate
  58. {
  59. @@ -17,6 +18,7 @@ public:
  60.  
  61. PrintThread::PrintThread(AtCore *parent, QString fileName) : d(new PrintThreadPrivate)
  62. {
  63. + QMutexLocker locker(&mutex1);
  64. d->core = parent;
  65. //QString cline;
  66. QFile file(fileName);
  67. @@ -24,6 +26,7 @@ PrintThread::PrintThread(AtCore *parent, QString fileName) : d(new PrintThreadPr
  68. d->totalSize = file.bytesAvailable();
  69. d->stillSize = d->totalSize;
  70. d->gcodestream = new QTextStream(&file);
  71. + qDebug() << d->gcodestream->readLine();
  72. }
  73.  
  74. void PrintThread::start()
  75. @@ -38,6 +41,7 @@ void PrintThread::start()
  76.  
  77. void PrintThread::commandReady()
  78. {
  79. + QMutexLocker locker(&mutex1);
  80. qDebug() << "Command Ready!";
  81. switch (d->core->state()) {
  82. case STARTPRINT:
  83. @@ -45,9 +49,14 @@ void PrintThread::commandReady()
  84. case BUSY:
  85. d->core->setState(BUSY);
  86. nextLine();
  87. + while(d->cline.isEmpty())
  88. + nextLine();
  89. + qDebug() << "after nextline";
  90. if (!d->cline.isEmpty()) {
  91. + qDebug() << "cline not empty";
  92. d->core->pushCommand(d->cline);
  93. }
  94. + qDebug() << "busy break";
  95. break;
  96.  
  97. case ERROR:
  98. @@ -68,22 +77,36 @@ void PrintThread::commandReady()
  99. qDebug() << tr("Unknown State");
  100. break;
  101. }
  102. +
  103. if (d->gcodestream->atEnd()) {
  104. + qDebug() << "atEnd";
  105. disconnect(d->core->plugin(), &IFirmware::readyForCommand, this, &PrintThread::commandReady);
  106. d->core->setState(FINISHEDPRINT);
  107. d->core->setState(IDLE);
  108. emit finished();
  109. }
  110. + else
  111. + {
  112. + qDebug() << "run it again";
  113. + commandReady();
  114. + }
  115. }
  116.  
  117. void PrintThread::nextLine()
  118. {
  119. - d->cline = d->gcodestream->readLine();
  120. + qDebug() << "nextline";
  121. + QMutexLocker locker(&mutex2);
  122. + qDebug() << d->gcodestream;
  123. + QTextStream *gcodestream = d->gcodestream;
  124. + d->cline = gcodestream->readLine();
  125. + qDebug() << d->cline;
  126. d->stillSize -= d->cline.size() + 1; //remove read chars
  127. + qDebug() << d->stillSize;
  128. d->printProgress = float(d->totalSize - d->stillSize) * 100.0 / float(d->totalSize);
  129. emit(printProgressChanged(d->printProgress));
  130. d->cline = d->cline.simplified();
  131. if (d->cline.contains(QChar::fromLatin1(';'))) {
  132. d->cline.resize(d->cline.indexOf(QChar::fromLatin1(';')));
  133. }
  134. + qDebug() << "end nextline";
  135. }
  136. diff --git a/src/printThread.h b/src/printThread.h
  137. index 328122f..555e39e 100644
  138. --- a/src/printThread.h
  139. +++ b/src/printThread.h
  140. @@ -20,6 +20,7 @@
  141.  
  142. #include <QTextStream>
  143. #include <QFile>
  144. +#include <QMutex>
  145. #include "atcore.h"
  146.  
  147. class PrintThreadPrivate;
  148. @@ -41,5 +42,7 @@ private slots:
  149. void commandReady();
  150.  
  151. private:
  152. + mutable QMutex mutex1;
  153. + mutable QMutex mutex2;
  154. PrintThreadPrivate *d;
  155. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement