From: Mjolnir Date: Tue, 18 Aug 2015 12:22:45 +0000 (+0200) Subject: test working with plotter X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=697c699963f5f3cc9e9550b2088b6b8f86d21db4;p=livingdesktop.git test working with plotter --- diff --git a/.gitignore b/.gitignore index a1f0330..ef25ad7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ .DS_Store *.pdf *.exe -build-* +build* diff --git a/Library/ErrorMessage.cpp b/Library/ErrorMessage.cpp index 0d3cc4d..59ca771 100644 --- a/Library/ErrorMessage.cpp +++ b/Library/ErrorMessage.cpp @@ -1,5 +1,15 @@ -#include "error.h" +#include "ErrorMessage.h" -Error::Error() +ErrorMessage::ErrorMessage(QString m) throw() +:_message(m) { } + +ErrorMessage::~ErrorMessage() throw() +{ +} + +const char* ErrorMessage::what() const throw() +{ + return _message.toStdString().data(); +} diff --git a/Library/ErrorMessage.h b/Library/ErrorMessage.h index da7bff5..8a8f704 100644 --- a/Library/ErrorMessage.h +++ b/Library/ErrorMessage.h @@ -1,10 +1,23 @@ #ifndef ERROR_H #define ERROR_H -class Error +#include "livingdesktoplibrary_global.h" + +#include +using namespace std; + +#include + +class LIVINGDESKTOPLIBRARYSHARED_EXPORT ErrorMessage: public exception { public: - Error(); + ErrorMessage(QString m) throw(); + ~ErrorMessage() throw(); + + virtual const char* what() const throw(); + + private: + QString _message; }; #endif // ERROR_H diff --git a/Library/LivingDesktopLibrary.pro b/Library/LivingDesktopLibrary.pro index 8b421c9..ee75eb3 100644 --- a/Library/LivingDesktopLibrary.pro +++ b/Library/LivingDesktopLibrary.pro @@ -4,17 +4,21 @@ # #------------------------------------------------- -QT -= core gui +QT += core gui serialport -TARGET = LivingDesktopLibrary +TARGET = LivingDesktop TEMPLATE = lib DEFINES += LIVINGDESKTOPLIBRARY_LIBRARY -SOURCES += livingdesktoplibrary.cpp +SOURCES += livingdesktoplibrary.cpp\ + ErrorMessage.cpp \ + XYPlotter.cpp HEADERS += livingdesktoplibrary.h\ - livingdesktoplibrary_global.h + livingdesktoplibrary_global.h\ + ErrorMessage.h \ + XYPlotter.h unix { target.path = /usr/lib diff --git a/Library/XYPlotter.cpp b/Library/XYPlotter.cpp index 40b59a6..b8bcc75 100644 --- a/Library/XYPlotter.cpp +++ b/Library/XYPlotter.cpp @@ -1,5 +1,37 @@ -#include "xyplotter.h" +#include "XYPlotter.h" -XYPlotter::XYPlotter() +#include + +XYPlotter::XYPlotter(QString port) +: serialPort(new QSerialPort(port)), connected(false), posX(0), posY(0), toolUp(false) +{ + if(serialPort->open(QIODevice::ReadWrite)) + { + serialPort->setBaudRate(QSerialPort::Baud115200,QSerialPort::AllDirections); + serialPort->setDataBits(QSerialPort::Data8); + serialPort->setParity(QSerialPort::NoParity); + serialPort->setStopBits(QSerialPort::TwoStop); + serialPort->setFlowControl(QSerialPort::NoFlowControl); + connected = true; + } + else + { + serialPort->close(); + throw(ErrorMessage("XYPlotter: serial port error " + QString::number(serialPort->error()))); + } +} + +void XYPlotter::moveTo(unsigned int x, unsigned int y, bool toolup=true) { + if (connected) + { + QString buffer = "G01X" + QString::number(x) + + "Y" + QString::number(y) + + "Z" + QString::number(toolup) + + "F50000\n"; + serialPort->write(buffer.toStdString().data(), strlen(buffer.toStdString().data())); + posX = x; + posY = y; + toolUp = toolup; + } } diff --git a/Library/XYPlotter.h b/Library/XYPlotter.h index d552ab0..521928a 100644 --- a/Library/XYPlotter.h +++ b/Library/XYPlotter.h @@ -1,10 +1,25 @@ #ifndef XYPLOTTER_H #define XYPLOTTER_H -class XYPlotter +#include "livingdesktoplibrary_global.h" +#include +#include + +class LIVINGDESKTOPLIBRARYSHARED_EXPORT XYPlotter { public: - XYPlotter(); + XYPlotter(QString port); + + void moveTo(unsigned int x, unsigned int y, bool toolup); + + private: + XYPlotter(){} + + QSerialPort* serialPort; + bool connected; + + unsigned int posX, posY; + bool toolUp; }; #endif // XYPLOTTER_H diff --git a/Library/livingdesktoplibrary.cpp b/Library/livingdesktoplibrary.cpp index ceadd29..ee03a32 100644 --- a/Library/livingdesktoplibrary.cpp +++ b/Library/livingdesktoplibrary.cpp @@ -1,6 +1,5 @@ #include "livingdesktoplibrary.h" - LivingDesktopLibrary::LivingDesktopLibrary() { } diff --git a/Library/livingdesktoplibrary_global.h b/Library/livingdesktoplibrary_global.h index 5f1dff7..7feb7d8 100644 --- a/Library/livingdesktoplibrary_global.h +++ b/Library/livingdesktoplibrary_global.h @@ -2,6 +2,7 @@ #define LIVINGDESKTOPLIBRARY_GLOBAL_H #include +#include #if defined(LIVINGDESKTOPLIBRARY_LIBRARY) # define LIVINGDESKTOPLIBRARYSHARED_EXPORT Q_DECL_EXPORT @@ -9,4 +10,11 @@ # define LIVINGDESKTOPLIBRARYSHARED_EXPORT Q_DECL_IMPORT #endif +namespace LivingDesktop +{ + const QString MOUSE_PORT = "ttyUSB1"; + const QString KEYBOARD_PORT = "ttyUSB1"; + const QString SCREEN_PORT = "ttyUSB2"; +} + #endif // LIVINGDESKTOPLIBRARY_GLOBAL_H diff --git a/Test/Test.pro b/Test/Test.pro index 3d7da79..4435f9c 100644 --- a/Test/Test.pro +++ b/Test/Test.pro @@ -4,12 +4,22 @@ # #------------------------------------------------- -QT += core gui +QT += core gui serialport greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Test TEMPLATE = app +DEPENDPATH += $$PWD/../Library +INCLUDEPATH += $$PWD/../Library + +CONFIG(debug, debug|release) { +LIBS += -L$$PWD/../builds/livingdesktop-Debug -lLivingDesktop +} + +CONFIG(release, debug|release) { +LIBS += -L$$PWD/../builds/livingdesktop-Release -lLivingDesktop +} SOURCES += main.cpp\ diff --git a/Test/mainwindow.cpp b/Test/mainwindow.cpp index 49d64fc..a46af7e 100644 --- a/Test/mainwindow.cpp +++ b/Test/mainwindow.cpp @@ -1,14 +1,41 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) +#include + +MainWindow::MainWindow(QWidget *parent) +: QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + qDebug("Start test"); + try + { + mouse = new XYPlotter("ttyUSB1"); + connect(ui->movebutton, SIGNAL(clicked()), this, SLOT(moveMouse())); + ui->movebutton->setEnabled(true); + } + catch (ErrorMessage e) + { + mouse = NULL; + qDebug(e.what()); + } } MainWindow::~MainWindow() { + if (mouse) + { + mouse->moveTo(0, 0, false); + delete mouse; + } delete ui; } + +void MainWindow::moveMouse() +{ + unsigned int x = ui->xvalue->value(); + unsigned int y = ui->xvalue->value(); + bool toolup = ui->toolupvalue->checkState() == Qt::Checked; + if (mouse) + mouse->moveTo(x, y, toolup); +} diff --git a/Test/mainwindow.h b/Test/mainwindow.h index fdfc884..a180b49 100644 --- a/Test/mainwindow.h +++ b/Test/mainwindow.h @@ -3,6 +3,9 @@ #include +#include +#include + namespace Ui { class MainWindow; } @@ -15,8 +18,12 @@ class MainWindow : public QMainWindow explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + public slots: + void moveMouse(); + private: Ui::MainWindow *ui; + XYPlotter *mouse; }; #endif // MAINWINDOW_H diff --git a/Test/mainwindow.ui b/Test/mainwindow.ui index 6050363..61aa35e 100644 --- a/Test/mainwindow.ui +++ b/Test/mainwindow.ui @@ -1,7 +1,8 @@ + MainWindow - - + + 0 0 @@ -9,16 +10,73 @@ 300 - + MainWindow - - - - + + + + + + X + + + + + + + 2000 + + + 100 + + + + + + + false + + + Move + + + + + + + 2000 + + + 100 + + + + + + + Y + + + + + + + Z + + + + + + + Tool Up + + + + + - - +