Control over rotation
authorMjolnir <thomas.pietrzak@inria.fr>
Fri, 11 Sep 2015 14:43:55 +0000 (16:43 +0200)
committerMjolnir <thomas.pietrzak@inria.fr>
Fri, 11 Sep 2015 14:43:55 +0000 (16:43 +0200)
16 files changed:
Library/LivingDevice.cpp
LivingDemos/Force.cpp
LivingDemos/Force.h
LivingDemos/GestureOutput.cpp
LivingDemos/LivingDemos.pro
LivingDemos/MenuPrincipal.cpp
LivingDemos/Peephole.cpp
LivingDemos/Peephole.h
LivingDemos/ScreenRotate.cpp
LivingDemos/ScreenRotate.h
LivingDemos/ScreenRotationControl.cpp [new file with mode: 0644]
LivingDemos/ScreenRotationControl.h [new file with mode: 0644]
LivingDemos/screenrotationcontrol.ui [new file with mode: 0644]
images/calendarapp.png
images/emailapp.png
images/presentationapp.png

index 513a2d43e9659ef5a03e20bba0fede78dbf95297..5f023dcb1a3041846e541b2f4413f514a9a306b3 100644 (file)
@@ -7,7 +7,7 @@
 
 //#define QIODEVICE_DEBUG
 
-char const *LivingDevice::serialports[] = {"/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyUSB4"};
+char const *LivingDevice::serialports[] = {"/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyUSB4", "/dev/ttyUSB5"};
 bool LivingDevice::usedports[] = {false, false, false, false, false};
 
 LivingDevice::LivingDevice(QString name, int timeout)
@@ -24,7 +24,7 @@ LivingDevice::~LivingDevice()
 void LivingDevice::discover(QString name, int timeout)
 {
     qDebug() << "Discovering" << name;
-    for (int i = 0 ; i < 5 && !serialPort ; i++)
+    for (int i = 0 ; i < 6 && !serialPort ; i++)
     {
         if (usedports[i])
             continue;
@@ -56,7 +56,7 @@ void LivingDevice::discover(QString name, int timeout)
                 }
                 else
                 {
-                    qDebug() << "Not" << name;
+                    qDebug() << "Found " << answer << ", not" << name;
                     closeSerialPort();
                 }
             }
index 905cec1772d3572a53c0b9050de21ed25da3fc0c..c15f723784566f40c071973c994b57b13e35e9db 100644 (file)
@@ -5,7 +5,8 @@
 
 Force::Force(QWidget *parent) :
     QMainWindow(parent),
-    ui(new Ui::Fullscreen)
+    ui(new Ui::Fullscreen),
+    _origin(false)
 {
     ui->setupUi(this);
     setWindowState(Qt::WindowMaximized);
@@ -22,7 +23,7 @@ Force::Force(QWidget *parent) :
     if (!menu->getMouse())
         qDebug() << "Warning: mouse not connected";
     else
-        menu->getMouse()->moveTo(500, 500);
+        menu->getMouse()->moveTo(1500, 700);
 }
 
 Force::~Force()
@@ -34,5 +35,12 @@ void Force::moveMouse()
 {
     MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
     if (menu->getMouse())
-        menu->getMouse()->moveTo(0, 0);
+    {
+        if (_origin)
+            menu->getMouse()->moveTo(1500, 700);
+        else
+            menu->getMouse()->moveTo(0, 0);
+
+        _origin = !_origin;
+    }
 }
index bf78cd60da1443df52498daaf0408fca8ed38f9b..8c6941781af349505aef50297293be4b9ecdb289 100644 (file)
@@ -25,6 +25,7 @@ class Force : public QMainWindow
     private:
         Ui::Fullscreen *ui;
         QGraphicsScene _background;
+        bool _origin;
 };
 
 #endif // FORCE_H
index 18de6fc1b251eb25c7e105e2362546799139e6b3..8a005bf4cb16a33db96212b723fd66653e3b6d33 100644 (file)
@@ -43,8 +43,8 @@ void GestureOutput::gestureL()
     {
         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);
+        menu->getMouse()->moveTo(x, y - 200);
+        menu->getMouse()->moveTo(x + 100, y - 200);
     }
 }
 
@@ -55,10 +55,10 @@ void GestureOutput::gestureM()
     {
         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, y + 200);
         menu->getMouse()->moveTo(x + 100, y + 100);
-        menu->getMouse()->moveTo(x + 100, y);
+        menu->getMouse()->moveTo(x + 200, y + 200);
+        menu->getMouse()->moveTo(x + 200, y);
     }
 }
 
@@ -69,9 +69,9 @@ void GestureOutput::gestureN()
     {
         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);
+        menu->getMouse()->moveTo(x, y + 200);
+        menu->getMouse()->moveTo(x + 100, y);
+        menu->getMouse()->moveTo(x + 100, y + 200);
     }
 }
 
@@ -82,9 +82,9 @@ void GestureOutput::gestureU()
     {
         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);
+        menu->getMouse()->moveTo(x, y - 200);
+        menu->getMouse()->movearc(x + 100, y - 200, -180);
+        menu->getMouse()->moveTo(x + 200, y);
     }
 }
 
index fa8765d60e8ad90916c833347dcbb92f35267268..c46a2567e8a38952c14e92ffee07a80945d440bb 100644 (file)
@@ -30,7 +30,8 @@ SOURCES += main.cpp\
     GestureOutput.cpp \
     Peephole.cpp \
     LargeView.cpp \
-    ScreenRotate.cpp
+    ScreenRotate.cpp \
+    ScreenRotationControl.cpp
 
 HEADERS  += MenuPrincipal.h \
     Options.h \
@@ -39,9 +40,11 @@ HEADERS  += MenuPrincipal.h \
     GestureOutput.h \
     Peephole.h \
     LargeView.h \
-    ScreenRotate.h
+    ScreenRotate.h \
+    ScreenRotationControl.h
 
 FORMS    += menuprincipal.ui \
     options.ui \
     fullscreen.ui \
-    gestureoutput.ui
+    gestureoutput.ui \
+    screenrotationcontrol.ui
index 98cd6dc9e658db40f872045a143ce2be9bbb1cea..a09a2e6bd0d53b72a7c5b0776284543d93904bcc 100644 (file)
@@ -190,11 +190,12 @@ void MenuPrincipal::openPeephole()
 {
     Peephole *p= new Peephole(this);
     p->show();
-    QTimer::singleShot(Peephole::updatedelay, p, SLOT(updatescreenpos()));
+    QTimer::singleShot(Peephole::_updatedelay, p, SLOT(updatescreenpos()));
 }
 
 void MenuPrincipal::openScreenRotate()
 {
     ScreenRotate *s = new ScreenRotate(this);
     s->show();
+    QTimer::singleShot(ScreenRotate::_updatedelay, s, SLOT(updatescreenangle()));
 }
index 9295c38132a494dde5f4757a7289be76005bff64..a9e01e3d82c26b244c92f34515fcff5965ef22fd 100644 (file)
@@ -6,13 +6,13 @@
 #include <QThread>
 #include <QTimer>
 
-const int Peephole::updatedelay = 100;
+const int Peephole::_updatedelay = 100;
 
 Peephole::Peephole(QWidget *parent) :
     QMainWindow(parent),
-    screenpos(330),
-    previousscreenpos(330),
-    viewpos(0),
+    _screenpos(330),
+    _previousscreenpos(330),
+    _viewpos(0),
     ui(new Ui::Fullscreen)
 {
     ui->setupUi(this);
@@ -22,7 +22,7 @@ Peephole::Peephole(QWidget *parent) :
     ui->image->setScene(&_background);
     QPixmap back("../../images/panorama.jpg");
     _background.addPixmap(back);
-    bgwidth = back.width();
+    _bgwidth = back.width();
     ui->image->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     ui->image->setDragMode(QGraphicsView::ScrollHandDrag);
     ui->image->setResizeAnchor(QGraphicsView::AnchorViewCenter);
@@ -37,7 +37,7 @@ Peephole::Peephole(QWidget *parent) :
     if (!menu->getScreen())
         qDebug() << "Warning: screen not connected";
     else
-        rackwidth = menu->getScreen()->getWidth();
+        _rackwidth = menu->getScreen()->getWidth();
 }
 
 Peephole::~Peephole()
@@ -49,16 +49,16 @@ Peephole::~Peephole()
 // prevents flooding the device
 void Peephole::updatescreenpos()
 {
-    if (screenpos != previousscreenpos)
+    if (_screenpos != _previousscreenpos)
     {
         MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
         if (menu->getScreen())
         {
-            menu->getScreen()->moveto(screenpos);
-            previousscreenpos = screenpos;
+            menu->getScreen()->moveto(_screenpos);
+            _previousscreenpos = _screenpos;
         }
     }
-    QTimer::singleShot(updatedelay, this, SLOT(updatescreenpos()));
+    QTimer::singleShot(_updatedelay, this, SLOT(updatescreenpos()));
 }
 
 void Peephole::scroll(int pos)
@@ -67,6 +67,6 @@ void Peephole::scroll(int pos)
     unsigned int range = ui->image->horizontalScrollBar()->maximum() - min;
     if (range == 0)
         return;
-    unsigned int dest = rackwidth * pos / range - min;
-    screenpos = dest;
+    unsigned int dest = _rackwidth * pos / range - min;
+    _screenpos = dest;
 }
index b0acc856c476a28df2bf6327a9a1b1b408afccb6..797b7161589410008d35d67546e2163b5d112b84 100644 (file)
@@ -17,15 +17,15 @@ class Peephole : public QMainWindow
     public:
         explicit Peephole(QWidget *parent = 0);
         ~Peephole();
-        static const int updatedelay;
+        static const int _updatedelay;
 
     public slots:
         void updatescreenpos();
         void scroll(int pos);
 
     private:
-        int screenpos, previousscreenpos, viewpos;
-        unsigned int rackwidth, bgwidth;
+        int _screenpos, _previousscreenpos, _viewpos;
+        unsigned int _rackwidth, _bgwidth;
         Ui::Fullscreen *ui;
         QGraphicsScene _background;
 };
index e8f9f5106c7b23cc75a3fbd4b6638b15b9376213..a09c3baf858e0be365b4a8b7093a438444720a9d 100644 (file)
@@ -1,13 +1,19 @@
 #include "ScreenRotate.h"
 
 #include <QDebug>
-#include <MenuPrincipal.h>
 #include <QGraphicsPixmapItem>
+#include <QTimer>
+
+#include <MenuPrincipal.h>
+
+const int ScreenRotate::_updatedelay = 500;
 
 ScreenRotate::ScreenRotate(QWidget *parent) :
     QMainWindow(parent),
     ui(new Ui::Fullscreen),
-    _window(NULL)
+    _window(NULL),
+    _screenangle(0),
+    _previousscreenangle(0)
 {
     ui->setupUi(this);
     setWindowState(Qt::WindowMaximized);
@@ -25,6 +31,11 @@ ScreenRotate::ScreenRotate(QWidget *parent) :
     connect(ui->appbutton2, SIGNAL(clicked()), this, SLOT(setupCalendar()));
     connect(ui->appbutton3, SIGNAL(clicked()), this, SLOT(setupEmails()));
 
+    _rotationcontrol = new ScreenRotationControl(this->centralWidget());
+    connect(_rotationcontrol, SIGNAL(update(int)), this, SLOT(rotateScreen(int)));
+    _rotationcontrol->show();
+    //_rotationcontrol->raise();
+
     MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(parent);
     if (!menu->getScreen())
         qDebug() << "Warning: screen not connected";
@@ -34,9 +45,26 @@ ScreenRotate::ScreenRotate(QWidget *parent) :
 
 ScreenRotate::~ScreenRotate()
 {
+    delete _rotationcontrol;
     delete ui;
 }
 
+// allows asynchronous udate
+// prevents flooding the device
+void ScreenRotate::updatescreenangle()
+{
+    if (_screenangle != _previousscreenangle)
+    {
+        MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
+        if (menu->getScreen())
+        {
+            menu->getScreen()->rotation(_screenangle);
+            _previousscreenangle = _screenangle;
+        }
+    }
+    QTimer::singleShot(_updatedelay, this, SLOT(updatescreenangle()));
+}
+
 void ScreenRotate::rotateScreen()
 {
     MenuPrincipal * menu = dynamic_cast<MenuPrincipal *>(this->parent());
@@ -55,6 +83,11 @@ void ScreenRotate::rotateScreen()
     }
 }
 
+void ScreenRotate::rotateScreen(int v)
+{
+    _screenangle = v;
+}
+
 void ScreenRotate::setupEmails()
 {
     if (_window)
index abd88c5ff20fd879eee06aec481c0e33a098c868..dfd5ad949ff9a31f4cc2a2975ed0ea0eb839a6b8 100644 (file)
@@ -5,9 +5,11 @@
 #include <QGraphicsScene>
 
 #include <ui_fullscreen.h>
+#include <ScreenRotationControl.h>
 
 namespace Ui {
     class Fullscreen;
+    class ScreenRotationControl;
 }
 
 class ScreenRotate : public QMainWindow
@@ -18,16 +20,22 @@ class ScreenRotate : public QMainWindow
         explicit ScreenRotate(QWidget *parent = 0);
         ~ScreenRotate();
 
+        static const int _updatedelay;
+
     public slots:
         void rotateScreen();
+        void rotateScreen(int v);
         void setupEmails();
         void setupPresentation();
         void setupCalendar();
+        void updatescreenangle();
 
     private:
         Ui::Fullscreen *ui;
+        ScreenRotationControl *_rotationcontrol;
         QGraphicsScene _background;
         QGraphicsPixmapItem *_window;
+        int _screenangle, _previousscreenangle;
         bool _straight;
 };
 
diff --git a/LivingDemos/ScreenRotationControl.cpp b/LivingDemos/ScreenRotationControl.cpp
new file mode 100644 (file)
index 0000000..260fd85
--- /dev/null
@@ -0,0 +1,24 @@
+#include "ScreenRotationControl.h"
+#include "ui_screenrotationcontrol.h"
+
+#include <QDebug>
+
+ScreenRotationControl::ScreenRotationControl(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::ScreenRotationControl)
+{
+    ui->setupUi(this);
+
+    connect(ui->screenangle, SIGNAL(valueChanged(int)), this, SLOT(transmitvalue(int)));
+    connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close()));
+}
+
+ScreenRotationControl::~ScreenRotationControl()
+{
+    delete ui;
+}
+
+void ScreenRotationControl::transmitvalue(int v)
+{
+    emit update(v);
+}
diff --git a/LivingDemos/ScreenRotationControl.h b/LivingDemos/ScreenRotationControl.h
new file mode 100644 (file)
index 0000000..628b756
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef SCREENROTATIONCONTROL_H
+#define SCREENROTATIONCONTROL_H
+
+#include <QDialog>
+
+namespace Ui {
+    class ScreenRotationControl;
+}
+
+class ScreenRotationControl : public QDialog
+{
+        Q_OBJECT
+
+    public:
+        explicit ScreenRotationControl(QWidget *parent = 0);
+        ~ScreenRotationControl();
+
+    signals:
+        void update(int);
+
+    private slots:
+        void transmitvalue(int);
+
+    private:
+        Ui::ScreenRotationControl *ui;
+};
+
+#endif // SCREENROTATIONCONTROL_H
diff --git a/LivingDemos/screenrotationcontrol.ui b/LivingDemos/screenrotationcontrol.ui
new file mode 100644 (file)
index 0000000..3cba9a1
--- /dev/null
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ScreenRotationControl</class>
+ <widget class="QDialog" name="ScreenRotationControl">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>240</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="label">
+     <property name="font">
+      <font>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Screen angular position</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QSlider" name="screenangle">
+     <property name="maximum">
+      <number>180</number>
+     </property>
+     <property name="singleStep">
+      <number>10</number>
+     </property>
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="tickPosition">
+      <enum>QSlider::TicksBothSides</enum>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Close</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
index 11b9a8cebf9fb3175e2f15cc07f69f3a6b91cbe3..40f55290f41ad2082fc779e3c5182647c6c543c9 100644 (file)
Binary files a/images/calendarapp.png and b/images/calendarapp.png differ
index fe109a1470a167fe61e694bbb13575358e563876..28541752340574ffe6617421cb6c7467ea877b09 100644 (file)
Binary files a/images/emailapp.png and b/images/emailapp.png differ
index a1eb176b880e76cc8f3e67abd363b30a30f6a0c4..3856fe3ecf265f0a2307f090837c923eebc8833c 100644 (file)
Binary files a/images/presentationapp.png and b/images/presentationapp.png differ