test working with plotter
authorMjolnir <thomas.pietrzak@inria.fr>
Tue, 18 Aug 2015 12:22:45 +0000 (14:22 +0200)
committerMjolnir <thomas.pietrzak@inria.fr>
Tue, 18 Aug 2015 12:22:45 +0000 (14:22 +0200)
12 files changed:
.gitignore
Library/ErrorMessage.cpp
Library/ErrorMessage.h
Library/LivingDesktopLibrary.pro
Library/XYPlotter.cpp
Library/XYPlotter.h
Library/livingdesktoplibrary.cpp
Library/livingdesktoplibrary_global.h
Test/Test.pro
Test/mainwindow.cpp
Test/mainwindow.h
Test/mainwindow.ui

index a1f03306a044cd54afeea572617aafbb1d312679..ef25ad75ca06854945bf66f943639b8e629de4a3 100644 (file)
@@ -3,4 +3,4 @@
 .DS_Store
 *.pdf
 *.exe
-build-*
+build*
index 0d3cc4d90f535666d48a0d95a9905849d8a97447..59ca7710bc88da77f597b96b4932a72a15a19f46 100644 (file)
@@ -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();
+}
index da7bff52d668841c2d73c9c6b50ab3dea01d53bf..8a8f70402d728d6aab83926768620e763736bee1 100644 (file)
@@ -1,10 +1,23 @@
 #ifndef ERROR_H
 #define ERROR_H
 
-class Error
+#include "livingdesktoplibrary_global.h"
+
+#include <exception>
+using namespace std;
+
+#include <QString>
+
+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
index 8b421c97a1532698430bd90f6dc8da826c3f3df6..ee75eb3f65f768dd053c4d4d70a91acbdf48954e 100644 (file)
@@ -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
index 40b59a64be4a3b8357d5f4fb485f9ec7aff1460f..b8bcc75b4f1f9b0178bf3e8529b65078e9eb26b0 100644 (file)
@@ -1,5 +1,37 @@
-#include "xyplotter.h"
+#include "XYPlotter.h"
 
-XYPlotter::XYPlotter()
+#include <QString>
+
+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;
+    }
 }
index d552ab0c4e56c59048c26e9fbf17f93e161a4d67..521928a9ff23a8151b5f33e1a5fdc1ebb64a3f77 100644 (file)
@@ -1,10 +1,25 @@
 #ifndef XYPLOTTER_H
 #define XYPLOTTER_H
 
-class XYPlotter
+#include "livingdesktoplibrary_global.h"
+#include <QSerialPort>
+#include <ErrorMessage.h>
+
+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
index ceadd29b5b2a96b87ba020e95d414005f3b3ec1d..ee03a320da58ec65ff72d9ba32037a947de219e6 100644 (file)
@@ -1,6 +1,5 @@
 #include "livingdesktoplibrary.h"
 
-
 LivingDesktopLibrary::LivingDesktopLibrary()
 {
 }
index 5f1dff7224729eefa2859c50c42afa870577faf5..7feb7d8f1fcc57ad8a680c77eb699f5f6736599a 100644 (file)
@@ -2,6 +2,7 @@
 #define LIVINGDESKTOPLIBRARY_GLOBAL_H
 
 #include <QtCore/qglobal.h>
+#include <QString>
 
 #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
index 3d7da79ed86375486c12239bde2c36a0a0f673fc..4435f9c0b39503dc74c42a3914982b2358db757b 100644 (file)
@@ -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\
index 49d64fce7cedf4ed8c5e0124cfe43e90c23c6ab6..a46af7e299aa0bfb4887b2c7710e5db37f44388f 100644 (file)
@@ -1,14 +1,41 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
-MainWindow::MainWindow(QWidget *parent) :
-    QMainWindow(parent),
-    ui(new Ui::MainWindow)
+#include <ErrorMessage.h>
+
+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);
+}
index fdfc88406831e930c1ca4db76f992ac032a84f18..a180b49934d9f24cdf81aaa7bf67f1ddf04097b1 100644 (file)
@@ -3,6 +3,9 @@
 
 #include <QMainWindow>
 
+#include <XYPlotter.h>
+#include <QDebug>
+
 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
index 6050363fa71ed2da04105077f9fef06150d05ee2..61aa35ef63878e6e38b9f601fd9fd121cc130e7c 100644 (file)
@@ -1,7 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
  <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow" >
-  <property name="geometry" >
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <height>300</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>MainWindow</string>
   </property>
-  <widget class="QMenuBar" name="menuBar" />
-  <widget class="QToolBar" name="mainToolBar" />
-  <widget class="QWidget" name="centralWidget" />
-  <widget class="QStatusBar" name="statusBar" />
+  <widget class="QWidget" name="centralWidget">
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
+     <widget class="QLabel" name="label">
+      <property name="text">
+       <string>X</string>
+      </property>
+     </widget>
+    </item>
+    <item row="0" column="1">
+     <widget class="QSpinBox" name="xvalue">
+      <property name="maximum">
+       <number>2000</number>
+      </property>
+      <property name="singleStep">
+       <number>100</number>
+      </property>
+     </widget>
+    </item>
+    <item row="3" column="0" colspan="2">
+     <widget class="QPushButton" name="movebutton">
+      <property name="enabled">
+       <bool>false</bool>
+      </property>
+      <property name="text">
+       <string>Move</string>
+      </property>
+     </widget>
+    </item>
+    <item row="1" column="1">
+     <widget class="QSpinBox" name="yvalue">
+      <property name="maximum">
+       <number>2000</number>
+      </property>
+      <property name="singleStep">
+       <number>100</number>
+      </property>
+     </widget>
+    </item>
+    <item row="1" column="0">
+     <widget class="QLabel" name="label_2">
+      <property name="text">
+       <string>Y</string>
+      </property>
+     </widget>
+    </item>
+    <item row="2" column="0">
+     <widget class="QLabel" name="label_3">
+      <property name="text">
+       <string>Z</string>
+      </property>
+     </widget>
+    </item>
+    <item row="2" column="1">
+     <widget class="QCheckBox" name="toolupvalue">
+      <property name="text">
+       <string>Tool Up</string>
+      </property>
+     </widget>
+    </item>
+   </layout>
+  </widget>
  </widget>
- <layoutDefault spacing="6" margin="11" />
- <pixmapfunction></pixmapfunction>
+ <layoutdefault spacing="6" margin="11"/>
  <resources/>
  <connections/>
 </ui>