Gesture output demo + arcs with mouse + free com port on release
authorMjolnir <thomas.pietrzak@inria.fr>
Fri, 4 Sep 2015 11:37:01 +0000 (13:37 +0200)
committerMjolnir <thomas.pietrzak@inria.fr>
Fri, 4 Sep 2015 11:37:01 +0000 (13:37 +0200)
12 files changed:
Library/LivingDevice.cpp
Library/LivingDevice.h
Library/XYPlotter.cpp
Library/XYPlotter.h
LivingDemos/Force.h
LivingDemos/GestureOutput.cpp
LivingDemos/GestureOutput.h
LivingDemos/LivingDemos.pro
LivingDemos/MenuPrincipal.cpp
LivingDemos/MenuPrincipal.h
LivingDemos/gestureoutput.ui
LivingDemos/menuprincipal.ui

index 5bccf371cfd7eef3ba41a06ce2b1e1b5d3cd57d1..d1c4739d45b32f02263ace05ec3dcc3b738274b5 100644 (file)
@@ -11,7 +11,7 @@ char const *LivingDevice::serialports[] = {"/dev/ttyUSB0", "/dev/ttyUSB1", "/dev
 bool LivingDevice::usedports[] = {false, false, false, false, false};
 
 LivingDevice::LivingDevice(QString name, int timeout)
-: serialPort(NULL)
+: serialPort(NULL), portnum(-1)
 {
     discover(name, timeout);
 }
@@ -51,7 +51,8 @@ void LivingDevice::discover(QString name, int timeout)
                 if (answer == name)
                 {
                     qDebug() << "Found " << name << " on port" << serialports[i];
-                    usedports[i] = true;
+                    portnum = i;
+                    usedports[portnum] = true;
                 }
                 else
                 {
@@ -77,7 +78,10 @@ void LivingDevice::discover(QString name, int timeout)
 void LivingDevice::closeSerialPort()
 {
     if (serialPort)
+    {
         delete serialPort;
+        usedports[portnum] = false;
+    }
     serialPort = NULL;
 }
 
index a820cfebfb2d5a879f1de4a7d48605f8665be774..137bcca340768a6064645402cd598fa969535032 100644 (file)
@@ -17,6 +17,7 @@ class LIVINGDESKTOPLIBRARYSHARED_EXPORT LivingDevice
 
     protected:
         Serial *serialPort;
+        int portnum;
 
         static char const *serialports[];
         static bool usedports[];
index 74a7759e15842a35856d64c72aa2b37318e11b32..77af07095277f8720682c7d28bc5a05ffbe6c857 100644 (file)
@@ -1,6 +1,7 @@
 #include "XYPlotter.h"
 
 #include <QDebug>
+#include <QtMath>
 
 const int XYPlotter::toolDistance = 70;
 
@@ -18,6 +19,33 @@ void XYPlotter::moveTo(int x, int y, bool toolup)
     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()
index b178f8cb73fdee7bc75949144077b309e56805e1..83491cd4f59b832935ca57c5e68fd8d34f3158b7 100644 (file)
@@ -10,6 +10,7 @@ class LIVINGDESKTOPLIBRARYSHARED_EXPORT XYPlotter : public LivingDevice
         ~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; }
index 7102a628216301526b769c6b6f80f2be6d62b401..bf78cd60da1443df52498daaf0408fca8ed38f9b 100644 (file)
@@ -19,7 +19,7 @@ class Force : public QMainWindow
         explicit Force(QWidget *parent = 0);
         ~Force();
 
-    public slots:
+    private slots:
         void moveMouse();
 
     private:
index 59d33fd75c9a252eaa5a91edc1b56cc82800886b..18de6fc1b251eb25c7e105e2362546799139e6b3 100644 (file)
 #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);
+    }
+}
index ce6f181c85d83edfed64cf206b32fce07fce9c43..e97e7a4f9bcb732ab341423046bedf94206ae0ac 100644 (file)
@@ -15,6 +15,13 @@ class GestureOutput : public QDialog
         explicit GestureOutput(QWidget *parent = 0);
         ~GestureOutput();
 
+    private slots:
+        void gestureL();
+        void gestureM();
+        void gestureN();
+        void gestureU();
+        void move();
+
     private:
         Ui::GestureOutput *ui;
 };
index 05b108487a48b70e21302b9474584d254cb4e16f..73d9e2f99528133177960779d07aca6a1c373dc2 100644 (file)
@@ -26,13 +26,16 @@ SOURCES += main.cpp\
         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
index f7d78b6df24d81f858e1fa4d6de68abaeba636c6..a2edcd3e3594f7ace7c1e237df84b81e815ccaef 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <Tidy.h>
 #include <Force.h>
+#include <GestureOutput.h>
 
 MenuPrincipal::MenuPrincipal(QWidget *parent) :
     QMainWindow(parent),
@@ -21,6 +22,7 @@ MenuPrincipal::MenuPrincipal(QWidget *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();
@@ -171,3 +173,9 @@ void MenuPrincipal::openForce()
     Force *f = new Force(this);
     f->show();
 }
+
+void MenuPrincipal::openGestureOutput()
+{
+    GestureOutput * g= new GestureOutput(this);
+    g->show();
+}
index b7a6e43ce485d12123375b67d07595091e8241e7..ba2bbcab1a26b1285cff285a59fee28f8a8a029e 100644 (file)
@@ -48,6 +48,7 @@ class MenuPrincipal : public QMainWindow
         //run demos
         void openTidy();
         void openForce();
+        void openGestureOutput();
 
     private:
         Ui::MenuPrincipal *ui;
index 575b262009636eef4fc803c721b77ff069133c95..b7e9b3acb626e189172ac1f37088c6b18e7b2251 100644 (file)
+<?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>
index 9cfa8b0fc17ee41b5bce2f1c10b2075887fe0d8e..ca9aaa0bc0b65aa5347d94fcb74c731f2da8296b 100644 (file)
@@ -52,7 +52,7 @@
     <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>
@@ -65,7 +65,7 @@
          </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>