.DS_Store
*.pdf
*.exe
-build-*
+build*
-#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();
+}
#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
#
#-------------------------------------------------
-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
-#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;
+ }
}
#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
#include "livingdesktoplibrary.h"
-
LivingDesktopLibrary::LivingDesktopLibrary()
{
}
#define LIVINGDESKTOPLIBRARY_GLOBAL_H
#include <QtCore/qglobal.h>
+#include <QString>
#if defined(LIVINGDESKTOPLIBRARY_LIBRARY)
# define LIVINGDESKTOPLIBRARYSHARED_EXPORT Q_DECL_EXPORT
# 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
#
#-------------------------------------------------
-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\
#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);
+}
#include <QMainWindow>
+#include <XYPlotter.h>
+#include <QDebug>
+
namespace Ui {
class MainWindow;
}
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
+ public slots:
+ void moveMouse();
+
private:
Ui::MainWindow *ui;
+ XYPlotter *mouse;
};
#endif // MAINWINDOW_H
+<?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>