AtCore  1.0.72
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 KDE Libary for 3D Printers
2  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
3  SPDX-FileCopyrightText: 2016, 2018 Tomaz Canabrava <tcanabrava@kde.org>
4  SPDX-FileCopyrightText: 2016-2019 Chris Rizzitello <rizzitello@kde.org>
5  SPDX-FileCopyrightText: 2016-2019 Patrick José Pereira <patrickjp@kde.org>
6  SPDX-FileCopyrightText: 2016, 2019 Lays Rodrigues <lays.rodrigues@kde.org>
7  SPDX-FileCopyrightText: 2018 Leandro Santiago <leandrosansilva@gmail.com>
8 */
9 
10 #pragma once
11 #include <QObject>
12 #include <QSerialPort>
13 #include <QSerialPortInfo>
14 #include <memory>
15 
16 #include "atcore_export.h"
17 #include "beddeform.h"
18 #include "ifirmware.h"
19 #include "temperature.h"
20 
21 class SerialLayer;
22 class IFirmware;
23 class QTime;
24 
44 class ATCORE_EXPORT AtCore : public QObject
45 {
46  Q_OBJECT
47  Q_PROPERTY(QString version READ version CONSTANT)
48  Q_PROPERTY(QStringList availableFirmwarePlugins READ availableFirmwarePlugins NOTIFY availableFirmwarePluginsChanged)
49  Q_PROPERTY(int extruderCount READ extruderCount WRITE setExtruderCount NOTIFY extruderCountChanged)
50  Q_PROPERTY(int temperatureTimerInterval READ temperatureTimerInterval WRITE setTemperatureTimerInterval NOTIFY temperatureTimerIntervalChanged);
51  Q_PROPERTY(int serialTimerInterval READ serialTimerInterval WRITE setSerialTimerInterval NOTIFY serialTimerIntervalChanged)
52  Q_PROPERTY(QStringList serialPorts READ serialPorts NOTIFY portsChanged)
53  Q_PROPERTY(float percentagePrinted READ percentagePrinted NOTIFY printProgressChanged)
54  Q_PROPERTY(QStringList portSpeeds READ portSpeeds CONSTANT)
55  Q_PROPERTY(QString connectedPort READ connectedPort CONSTANT)
56  Q_PROPERTY(AtCore::STATES state READ state WRITE setState NOTIFY stateChanged)
57  Q_PROPERTY(bool sdMount READ isSdMounted WRITE setSdMounted NOTIFY sdMountChanged)
58  Q_PROPERTY(QStringList sdFileList READ sdFileList NOTIFY sdCardFileListChanged)
59  Q_PROPERTY(bool autoTemperatureReport READ autoTemperatureReport WRITE setAutoTemperatureReport NOTIFY autoTemperatureReportChanged)
60  Q_PROPERTY(Temperature *temperature READ temperature CONSTANT)
61 
62  friend class AtCoreTests;
63  // Add friends as Sd Card support is extended to more plugins.
64  friend class RepetierPlugin;
65  friend class MarlinPlugin;
66  // friend class SmoothiePlugin;
67  // friend class TeacupPlugin;
68  // friend class AprinterPlugin;
69  // friend class SprinterPlugin;
70 
71 public:
75  enum STATES {
78  IDLE,
79  BUSY,
82  STOP,
85  };
86  Q_ENUM(STATES)
90  enum AXES {
91  X = 1 << 0,
92  Y = 1 << 1,
93  Z = 1 << 2,
94  E = 1 << 3,
95  };
96  Q_ENUM(AXES)
100  enum UNITS {
102  IMPERIAL
103  };
104  Q_ENUM(UNITS)
109  explicit AtCore(QObject *parent = nullptr);
110  ~AtCore();
111 
116  QString version() const;
117 
123  QStringList serialPorts() const;
124 
129  QString connectedPort() const;
130 
140  Q_INVOKABLE bool newConnection(const QString &port, int baud, const QString &fwName, bool disableROC = false);
141 
145  QStringList portSpeeds() const;
146 
151  Q_INVOKABLE void closeConnection();
152 
158  Q_INVOKABLE IFirmware *firmwarePlugin() const;
159 
164  QStringList availableFirmwarePlugins() const;
165 
171  AtCore::STATES state();
172 
178  int extruderCount() const;
179 
184  float percentagePrinted() const;
185 
189  std::shared_ptr<BedDeform> bedDeform();
190 
194  Temperature *temperature();
195 
199  int serialTimerInterval() const;
200 
204  int temperatureTimerInterval() const;
205 
210  Q_INVOKABLE void mountSd(uint slot = 0);
211 
216  Q_INVOKABLE void umountSd(uint slot = 0);
217 
222  QStringList sdFileList();
223 
228  bool isSdMounted() const;
229 
234  bool autoTemperatureReport() const;
235 
236 signals:
237 
248  void atcoreMessage(const QString &msg);
249 
254  void extruderCountChanged(const int newCount);
255 
261  void printProgressChanged(const float newProgress);
262 
267  void receivedMessage(const QByteArray &message);
268 
273  void serialTimerIntervalChanged(const int newTime);
274 
279  void temperatureTimerIntervalChanged(const int newTime);
280 
285  void autoTemperatureReportChanged(bool autoReport);
286 
291  void autoCheckTemperatureIntervalChanged(const int newTime);
292 
298  void stateChanged(AtCore::STATES newState);
299 
303  void portsChanged(const QStringList &portList);
304 
308  void sdMountChanged(bool newState);
309 
313  void sdCardFileListChanged(const QStringList &fileList);
314 
319  void pushedCommand(const QByteArray &comm);
320 
324  void availableFirmwarePluginsChanged();
325 
326 public slots:
327 
333  void setState(AtCore::STATES state);
334 
338  Q_INVOKABLE void updateFWPlugins();
339 
345  Q_INVOKABLE void pushCommand(const QString &comm);
346 
352  Q_INVOKABLE void print(const QString &fileName, bool sdPrint = false);
353 
358  Q_INVOKABLE void stop();
359 
364  Q_INVOKABLE void emergencyStop();
365 
374  void pause(const QString &pauseActions);
375 
381  Q_INVOKABLE void resume();
382 
388  Q_INVOKABLE void home(uchar axis);
389 
394  Q_INVOKABLE void home();
395 
402  Q_INVOKABLE void setExtruderTemp(uint temp = 0, uint extruder = 0, bool andWait = false);
403 
410  Q_INVOKABLE void move(AtCore::AXES axis, double arg);
411 
418  Q_INVOKABLE void move(QLatin1Char axis, double arg);
419 
426  Q_INVOKABLE void setBedTemp(uint temp = 0, bool andWait = false);
427 
433  Q_INVOKABLE void setFanSpeed(uint speed = 0, uint fanNumber = 0);
434 
439  Q_INVOKABLE void setAbsolutePosition();
440 
445  Q_INVOKABLE void setRelativePosition();
446 
451  Q_INVOKABLE void disableMotors(uint delay = 0);
452 
457  Q_INVOKABLE void setPrinterSpeed(uint speed = 100);
458 
463  Q_INVOKABLE void setFlowRate(uint rate = 100);
464 
470  Q_INVOKABLE void close();
471 
476  Q_INVOKABLE void showMessage(const QString &message);
477 
483  Q_INVOKABLE void setUnits(AtCore::UNITS units);
484 
489  void setSerialTimerInterval(int newTime);
490 
495  void setTemperatureTimerInterval(int newTime);
496 
501  void setAutoTemperatureReport(bool autoReport);
502 
507  Q_INVOKABLE void setAutoCheckTemperatureInterval(int newTime);
508 
512  Q_INVOKABLE void sdDelete(const QString &fileName);
513 
517  void sdCardPrintStatus();
518 
519 private slots:
523  void processQueue();
524 
528  void checkTemperature();
529 
534  void newMessage(const QByteArray &message);
535 
540  void newCommand(const QByteArray &command);
541 
547  void findFirmware(const QByteArray &message);
548 
552  void locateSerialPort();
553 
558  void disableResetOnConnect(const QString &port);
559 
563  void getSDFileList();
564 
568  void handleSerialError(QSerialPort::SerialPortError error);
569 
570 private:
576  Q_INVOKABLE void loadFirmwarePlugin(const QString &fwName);
577 
581  bool firmwarePluginLoaded() const;
582 
586  bool serialInitialized() const;
587 
591  void requestFirmware();
592 
597  bool isReadingSdCardList() const;
598 
603  void stopSdPrint();
604 
610  void waitForPrinterReboot(const QByteArray &message, const QString &fwName);
611 
616  std::unique_ptr<AtCorePrivate> d;
617 
618 protected:
624  void setExtruderCount(int newCount);
629  void appendSdCardFileList(const QString &fileName);
630 
634  void clearSdCardFileList();
635 
640  void setSdMounted(const bool mounted);
641 
646  void setReadingSdCardList(bool readingList);
647 };
AtCore::BUSY
@ BUSY
Printer is Printing or working.
Definition: atcore.h:79
temperature.h
ifirmware.h
AtCore::FINISHEDPRINT
@ FINISHEDPRINT
Just Finished print job.
Definition: atcore.h:84
AtCore::ERRORSTATE
@ ERRORSTATE
Printer Returned Error.
Definition: atcore.h:81
AtCore::d
std::unique_ptr< AtCorePrivate > d
Definition: atcore.h:615
MarlinPlugin
The MarlinPlugin class Plugin for Marlin.
Definition: marlinplugin.h:17
AtCore::IDLE
@ IDLE
Connected to printer and ready for commands.
Definition: atcore.h:78
AtCore::UNITS
UNITS
The UNITS enum - Possible Mesurment Units.
Definition: atcore.h:100
AtCore::PAUSE
@ PAUSE
Printer is paused.
Definition: atcore.h:80
SerialLayer
The SerialLayer class. Provide the low level serial operations.
Definition: seriallayer.h:19
AtCore::STATES
STATES
STATES enum Possible states the printer can be in.
Definition: atcore.h:75
AtCore
The AtCore class aims to provides a high level interface for serial based gcode devices
Definition: atcore.h:44
AtCore::DISCONNECTED
@ DISCONNECTED
Not Connected to a printer, initial state.
Definition: atcore.h:76
AtCore::CONNECTING
@ CONNECTING
Attempting to connect, Fw not probed.
Definition: atcore.h:77
AtCore::STOP
@ STOP
Stop Printing and Clean Queue.
Definition: atcore.h:82
AtCore::AXES
AXES
The AXES enum - Printer Axes.
Definition: atcore.h:90
AtCore::STARTPRINT
@ STARTPRINT
Just Starting a print job.
Definition: atcore.h:83
Temperature
The Temperature class.
Definition: temperature.h:20
IFirmware
The IFirmware class Base Class for Firmware Plugins.
Definition: ifirmware.h:24
beddeform.h
AtCore::AtCorePrivate
The AtCorePrivate struct Provides a private data set for atcore.
Definition: atcore.cpp:35
AtCore::METRIC
@ METRIC
Metric Units (Meters)
Definition: atcore.h:101
RepetierPlugin
The RepetierPlugin class Plugin for Repetier.
Definition: repetierplugin.h:17