AtCore  1.0.70
AtCore is a API to manage the serial connection between the computer and 3D Printers.
atcore.h
Go to the documentation of this file.
1 /* AtCore
2  Copyright (C) <2016 - 2019>
3 
4  Authors:
5  Tomaz Canabrava <tcanabrava@kde.org>
6  Chris Rizzitello <rizzitello@kde.org>
7  Patrick José Pereira <patrickjp@kde.org>
8  Lays Rodrigues <lays.rodrigues@kde.org>
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) version 3, or any
14  later version accepted by the membership of KDE e.V. (or its
15  successor approved by the membership of KDE e.V.), which shall
16  act as a proxy defined in Section 6 of version 3 of the license.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library. If not, see <http://www.gnu.org/licenses/>.
25 */
26 #pragma once
27 #include <QObject>
28 #include <QSerialPort>
29 #include <QSerialPortInfo>
30 #include <memory>
31 
32 #include "atcore_export.h"
33 #include "beddeform.h"
34 #include "ifirmware.h"
35 #include "temperature.h"
36 
37 class SerialLayer;
38 class IFirmware;
39 class QTime;
40 
60 class ATCORE_EXPORT AtCore : public QObject
61 {
62  Q_OBJECT
63  Q_PROPERTY(QString version READ version CONSTANT)
64  Q_PROPERTY(QStringList availableFirmwarePlugins READ availableFirmwarePlugins NOTIFY availableFirmwarePluginsChanged)
65  Q_PROPERTY(int extruderCount READ extruderCount WRITE setExtruderCount NOTIFY extruderCountChanged)
66  Q_PROPERTY(int temperatureTimerInterval READ temperatureTimerInterval WRITE setTemperatureTimerInterval NOTIFY temperatureTimerIntervalChanged);
67  Q_PROPERTY(int serialTimerInterval READ serialTimerInterval WRITE setSerialTimerInterval NOTIFY serialTimerIntervalChanged)
68  Q_PROPERTY(QStringList serialPorts READ serialPorts NOTIFY portsChanged)
69  Q_PROPERTY(float percentagePrinted READ percentagePrinted NOTIFY printProgressChanged)
70  Q_PROPERTY(QStringList portSpeeds READ portSpeeds CONSTANT)
71  Q_PROPERTY(QString connectedPort READ connectedPort CONSTANT)
72  Q_PROPERTY(AtCore::STATES state READ state WRITE setState NOTIFY stateChanged)
73  Q_PROPERTY(bool sdMount READ isSdMounted WRITE setSdMounted NOTIFY sdMountChanged)
74  Q_PROPERTY(QStringList sdFileList READ sdFileList NOTIFY sdCardFileListChanged)
75  Q_PROPERTY(bool autoTemperatureReport READ autoTemperatureReport WRITE setAutoTemperatureReport NOTIFY autoTemperatureReportChanged)
76  Q_PROPERTY(Temperature *temperature READ temperature CONSTANT)
77 
78  friend class AtCoreTests;
79  // Add friends as Sd Card support is extended to more plugins.
80  friend class RepetierPlugin;
81  friend class MarlinPlugin;
82  // friend class SmoothiePlugin;
83  // friend class TeacupPlugin;
84  // friend class AprinterPlugin;
85  // friend class SprinterPlugin;
86 
87 public:
91  enum STATES {
94  IDLE,
95  BUSY,
98  STOP,
101  };
102  Q_ENUM(STATES)
106  enum AXES {
107  X = 1 << 0,
108  Y = 1 << 1,
109  Z = 1 << 2,
110  E = 1 << 3,
111  };
112  Q_ENUM(AXES)
116  enum UNITS {
118  IMPERIAL
119  };
120  Q_ENUM(UNITS)
125  explicit AtCore(QObject *parent = nullptr);
126  ~AtCore() = default;
127 
132  QString version() const;
133 
139  QStringList serialPorts() const;
140 
145  QString connectedPort() const;
146 
156  Q_INVOKABLE bool newConnection(const QString &port, int baud, const QString &fwName, bool disableROC = false);
157 
161  QStringList portSpeeds() const;
162 
167  Q_INVOKABLE void closeConnection();
168 
174  Q_INVOKABLE IFirmware *firmwarePlugin() const;
175 
180  QStringList availableFirmwarePlugins() const;
181 
187  AtCore::STATES state();
188 
194  int extruderCount() const;
195 
200  float percentagePrinted() const;
201 
205  std::shared_ptr<BedDeform> bedDeform();
206 
210  Temperature *temperature();
211 
215  int serialTimerInterval() const;
216 
220  int temperatureTimerInterval() const;
221 
226  Q_INVOKABLE void mountSd(uint slot = 0);
227 
232  Q_INVOKABLE void umountSd(uint slot = 0);
233 
238  QStringList sdFileList();
239 
244  bool isSdMounted() const;
245 
250  bool autoTemperatureReport() const;
251 
252 signals:
253 
264  void atcoreMessage(const QString &msg);
265 
270  void extruderCountChanged(const int newCount);
271 
277  void printProgressChanged(const float newProgress);
278 
283  void receivedMessage(const QByteArray &message);
284 
289  void serialTimerIntervalChanged(const int newTime);
290 
295  void temperatureTimerIntervalChanged(const int newTime);
296 
301  void autoTemperatureReportChanged(bool autoReport);
302 
307  void autoCheckTemperatureIntervalChanged(const int newTime);
308 
314  void stateChanged(AtCore::STATES newState);
315 
319  void portsChanged(const QStringList &portList);
320 
324  void sdMountChanged(bool newState);
325 
329  void sdCardFileListChanged(const QStringList &fileList);
330 
335  void pushedCommand(const QByteArray &comm);
336 
340  void availableFirmwarePluginsChanged();
341 
342 public slots:
343 
349  void setState(AtCore::STATES state);
350 
356  Q_INVOKABLE void pushCommand(const QString &comm);
357 
363  Q_INVOKABLE void print(const QString &fileName, bool sdPrint = false);
364 
369  Q_INVOKABLE void stop();
370 
375  Q_INVOKABLE void emergencyStop();
376 
385  void pause(const QString &pauseActions);
386 
392  Q_INVOKABLE void resume();
393 
399  Q_INVOKABLE void home(uchar axis);
400 
405  Q_INVOKABLE void home();
406 
413  Q_INVOKABLE void setExtruderTemp(uint temp = 0, uint extruder = 0, bool andWait = false);
414 
421  Q_INVOKABLE void move(AtCore::AXES axis, double arg);
422 
429  Q_INVOKABLE void move(QLatin1Char axis, double arg);
430 
437  Q_INVOKABLE void setBedTemp(uint temp = 0, bool andWait = false);
438 
444  Q_INVOKABLE void setFanSpeed(uint speed = 0, uint fanNumber = 0);
445 
450  Q_INVOKABLE void setAbsolutePosition();
451 
456  Q_INVOKABLE void setRelativePosition();
457 
462  Q_INVOKABLE void disableMotors(uint delay = 0);
463 
468  Q_INVOKABLE void setPrinterSpeed(uint speed = 100);
469 
474  Q_INVOKABLE void setFlowRate(uint rate = 100);
475 
481  Q_INVOKABLE void close();
482 
487  Q_INVOKABLE void showMessage(const QString &message);
488 
494  Q_INVOKABLE void setUnits(AtCore::UNITS units);
495 
500  void setSerialTimerInterval(int newTime);
501 
506  void setTemperatureTimerInterval(int newTime);
507 
512  void setAutoTemperatureReport(bool autoReport);
513 
518  Q_INVOKABLE void setAutoCheckTemperatureInterval(int newTime);
519 
523  Q_INVOKABLE void sdDelete(const QString &fileName);
524 
528  void sdCardPrintStatus();
529 
530 private slots:
534  void processQueue();
535 
539  void checkTemperature();
540 
545  void newMessage(const QByteArray &message);
546 
551  void newCommand(const QByteArray &command);
552 
558  void findFirmware(const QByteArray &message);
559 
563  void locateSerialPort();
564 
569  void disableResetOnConnect(const QString &port);
570 
574  void getSDFileList();
575 
579  void handleSerialError(QSerialPort::SerialPortError error);
580 
581 private:
587  Q_INVOKABLE void loadFirmwarePlugin(const QString &fwName);
588 
592  bool firmwarePluginLoaded() const;
593 
597  bool serialInitialized() const;
598 
602  void requestFirmware();
603 
609  QMap<QString, QString> findFirmwarePlugins(const QString &path);
610 
615  bool isReadingSdCardList() const;
616 
621  void stopSdPrint();
622 
628  void waitForPrinterReboot(const QByteArray &message, const QString &fwName);
629 
634  AtCorePrivate *d;
635 
636 protected:
642  void setExtruderCount(int newCount);
647  void appendSdCardFileList(const QString &fileName);
648 
652  void clearSdCardFileList();
653 
658  void setSdMounted(const bool mounted);
659 
664  void setReadingSdCardList(bool readingList);
665 };
The Temperature class.
Definition: temperature.h:35
Just Finished print job.
Definition: atcore.h:100
The IFirmware class Base Class for Firmware Plugins.
Definition: ifirmware.h:39
The AtCore class aims to provides a high level interface for serial based gcode devices ...
Definition: atcore.h:60
Printer Returned Error.
Definition: atcore.h:97
Connected to printer and ready for commands.
Definition: atcore.h:94
The RepetierPlugin class Plugin for Repetier.
Definition: repetierplugin.h:34
Printer is paused.
Definition: atcore.h:96
The AtCorePrivate struct Provides a private data set for atcore.
Definition: atcore.cpp:50
The MarlinPlugin class Plugin for Marlin.
Definition: marlinplugin.h:34
AtCorePrivate * d
Definition: atcore.h:633
UNITS
The UNITS enum - Possible Mesurment Units.
Definition: atcore.h:116
AXES
The AXES enum - Printer Axes.
Definition: atcore.h:106
Stop Printing and Clean Queue.
Definition: atcore.h:98
Just Starting a print job.
Definition: atcore.h:99
The SerialLayer class. Provide the low level serial operations.
Definition: seriallayer.h:35
Not Connected to a printer, initial state.
Definition: atcore.h:92
Attempting to connect, Fw not probed.
Definition: atcore.h:93
Printer is Printing or working.
Definition: atcore.h:95
STATES
STATES enum Possible states the printer can be in.
Definition: atcore.h:91
Metric Units (Meters)
Definition: atcore.h:117