bool LivingDevice::usedports[] = {false, false, false, false, false};
LivingDevice::LivingDevice(QString name, int timeout)
-: serialPort(NULL)
+: serialPort(NULL), portnum(-1)
{
discover(name, timeout);
}
if (answer == name)
{
qDebug() << "Found " << name << " on port" << serialports[i];
- usedports[i] = true;
+ portnum = i;
+ usedports[portnum] = true;
}
else
{
void LivingDevice::closeSerialPort()
{
if (serialPort)
+ {
delete serialPort;
+ usedports[portnum] = false;
+ }
serialPort = NULL;
}
protected:
Serial *serialPort;
+ int portnum;
static char const *serialports[];
static bool usedports[];
#include "XYPlotter.h"
#include <QDebug>
+#include <QtMath>
const int XYPlotter::toolDistance = 70;
char commands[] = {'G', 'X', 'Y', 'Z'};
int values[] = {0, x, y, toolup * toolDistance};
sendCommand(commands, values, 4);
+ posX = x;
+ posY = y;
+}
+
+void XYPlotter::movearc(int centerx, int centery, int angle, bool toolup)
+{
+
+ int g;
+ if (angle > 0)
+ g = 2;
+ else
+ g = 3;
+
+ qreal a = angle * M_PI / 180.;
+ qreal deltax = int(posX) - centerx;
+ qreal deltay = int(posY) - centery;
+ qreal currentangle = qAtan2(deltay, deltax);
+ qreal radius = qSqrt(qPow(deltax, 2.0) + qPow(deltay, 2.0));
+ int destx = centerx + radius * cos(currentangle + a);
+ int desty = centery + radius * sin(currentangle + a);
+
+ char commands[] = {'G', 'X', 'Y', 'Z', 'I', 'J'};
+ int values[] = {g, destx, desty, toolup * toolDistance, -deltax, -deltay};
+ sendCommand(commands, values, 6);
+
+ posX = destx;
+ posY = desty;
}
void XYPlotter::calibrate()
~XYPlotter();
void moveTo(int x, int y, bool toolup=true);
+ void movearc(int centerx, int centery, int angle, bool toolup=true);
unsigned int getX() { return posX; }
unsigned int getY() { return posY; }
explicit Force(QWidget *parent = 0);
~Force();
- public slots:
+ private slots:
void moveMouse();
private:
#include "GestureOutput.h"
#include "ui_gestureoutput.h"
+#include <QDebug>
+#include <MenuPrincipal.h>
+
GestureOutput::GestureOutput(QWidget *parent) :
QDialog(parent),
ui(new Ui::GestureOutput)
{
ui->setupUi(this);
+ setAttribute(Qt::WA_DeleteOnClose);
+
+ connect(ui->gestureL, SIGNAL(clicked()), this, SLOT(gestureL()));
+ connect(ui->gestureM, SIGNAL(clicked()), this, SLOT(gestureM()));
+ connect(ui->gestureN, SIGNAL(clicked()), this, SLOT(gestureN()));
+ connect(ui->gestureU, SIGNAL(clicked()), this, SLOT(gestureU()));
+ connect(ui->move, SIGNAL(clicked()), this, SLOT(move()));
+
+ MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(parent);
+ if (!menu->getMouse())
+ qDebug() << "Warning: mouse not connected";
+ else
+ {
+ menu->getMouse()->moveTo(500, 500);
+ ui->gestureL->setEnabled(true);
+ ui->gestureM->setEnabled(true);
+ ui->gestureN->setEnabled(true);
+ ui->gestureU->setEnabled(true);
+ ui->move->setEnabled(true);
+ }
}
GestureOutput::~GestureOutput()
{
delete ui;
}
+
+void GestureOutput::gestureL()
+{
+ MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
+ if (menu->getMouse())
+ {
+ unsigned int x = menu->getMouse()->getX();
+ unsigned int y = menu->getMouse()->getY();
+ menu->getMouse()->moveTo(x, y - 100);
+ menu->getMouse()->moveTo(x + 50, y - 100);
+ }
+}
+
+void GestureOutput::gestureM()
+{
+ MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
+ if (menu->getMouse())
+ {
+ unsigned int x = menu->getMouse()->getX();
+ unsigned int y = menu->getMouse()->getY();
+ menu->getMouse()->moveTo(x, y + 100);
+ menu->getMouse()->moveTo(x + 50, y + 50);
+ menu->getMouse()->moveTo(x + 100, y + 100);
+ menu->getMouse()->moveTo(x + 100, y);
+ }
+}
+
+void GestureOutput::gestureN()
+{
+ MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
+ if (menu->getMouse())
+ {
+ unsigned int x = menu->getMouse()->getX();
+ unsigned int y = menu->getMouse()->getY();
+ menu->getMouse()->moveTo(x, y + 100);
+ menu->getMouse()->moveTo(x + 50, y);
+ menu->getMouse()->moveTo(x + 50, y + 100);
+ }
+}
+
+void GestureOutput::gestureU()
+{
+ MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
+ if (menu->getMouse())
+ {
+ unsigned int x = menu->getMouse()->getX();
+ unsigned int y = menu->getMouse()->getY();
+ menu->getMouse()->moveTo(x, y - 100);
+ menu->getMouse()->movearc(x + 50, y - 100, -180);
+ menu->getMouse()->moveTo(x + 100, y);
+ }
+}
+
+void GestureOutput::move()
+{
+ MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
+ if (menu->getMouse())
+ {
+ unsigned int x = ui->xvalue->value();
+ unsigned int y = ui->yvalue->value();
+ menu->getMouse()->moveTo(x, y);
+ }
+}
explicit GestureOutput(QWidget *parent = 0);
~GestureOutput();
+ private slots:
+ void gestureL();
+ void gestureM();
+ void gestureN();
+ void gestureU();
+ void move();
+
private:
Ui::GestureOutput *ui;
};
MenuPrincipal.cpp \
Options.cpp \
Tidy.cpp \
- Force.cpp
+ Force.cpp \
+ GestureOutput.cpp
HEADERS += MenuPrincipal.h \
Options.h \
Tidy.h \
- Force.h
+ Force.h \
+ GestureOutput.h
FORMS += menuprincipal.ui \
options.ui \
- fullscreen.ui
+ fullscreen.ui \
+ gestureoutput.ui
#include <Tidy.h>
#include <Force.h>
+#include <GestureOutput.h>
MenuPrincipal::MenuPrincipal(QWidget *parent) :
QMainWindow(parent),
//demos
connect(ui->tidy, SIGNAL(clicked()), this, SLOT(openTidy()));
connect(ui->force, SIGNAL(clicked()), this, SLOT(openForce()));
+ connect(ui->gestureoutput, SIGNAL(clicked()), this, SLOT(openGestureOutput()));
connectKeyboard();
connectScreen();
Force *f = new Force(this);
f->show();
}
+
+void MenuPrincipal::openGestureOutput()
+{
+ GestureOutput * g= new GestureOutput(this);
+ g->show();
+}
//run demos
void openTidy();
void openForce();
+ void openGestureOutput();
private:
Ui::MenuPrincipal *ui;
+<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <author/>
- <comment/>
- <exportmacro/>
<class>GestureOutput</class>
<widget class="QDialog" name="GestureOutput">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>400</width>
- <height>300</height>
+ <width>505</width>
+ <height>459</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="geometry">
- <rect>
- <x>30</x>
- <y>240</y>
- <width>341</width>
- <height>32</height>
- </rect>
- </property>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
- </property>
- </widget>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QPushButton" name="gestureM">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>30</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>M</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QPushButton" name="gestureN">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>30</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>N</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="gestureL">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>30</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>L</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QPushButton" name="gestureU">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>30</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>U</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Maximum</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinAndMaxSize</enum>
+ </property>
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="xLabel">
+ <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="1" column="0">
+ <widget class="QLabel" name="yLabel">
+ <property name="text">
+ <string>Y</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>
+ </layout>
+ </item>
+ <item>
+ <widget class="QPushButton" name="move">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Move</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Close</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
</widget>
- <pixmapfunction/>
+ <tabstops>
+ <tabstop>gestureM</tabstop>
+ <tabstop>gestureL</tabstop>
+ <tabstop>gestureN</tabstop>
+ <tabstop>gestureU</tabstop>
+ </tabstops>
<resources/>
<connections>
<connection>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
- <widget class="QPushButton" name="pushButton_2">
+ <widget class="QPushButton" name="gestureoutput">
<property name="minimumSize">
<size>
<width>0</width>
</font>
</property>
<property name="text">
- <string>Demo 3</string>
+ <string>Gesture Output</string>
</property>
</widget>
</item>
<tabstops>
<tabstop>tidy</tabstop>
<tabstop>force</tabstop>
- <tabstop>pushButton_2</tabstop>
+ <tabstop>gestureoutput</tabstop>
<tabstop>pushButton_4</tabstop>
<tabstop>options</tabstop>
</tabstops>