From: Mjolnir Date: Fri, 11 Sep 2015 14:43:55 +0000 (+0200) Subject: Control over rotation X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=6556149135363532f4abe622be0c78b24eb60aa6;p=livingdesktop.git Control over rotation --- diff --git a/Library/LivingDevice.cpp b/Library/LivingDevice.cpp index 513a2d4..5f023dc 100644 --- a/Library/LivingDevice.cpp +++ b/Library/LivingDevice.cpp @@ -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(); } } diff --git a/LivingDemos/Force.cpp b/LivingDemos/Force.cpp index 905cec1..c15f723 100644 --- a/LivingDemos/Force.cpp +++ b/LivingDemos/Force.cpp @@ -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(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; + } } diff --git a/LivingDemos/Force.h b/LivingDemos/Force.h index bf78cd6..8c69417 100644 --- a/LivingDemos/Force.h +++ b/LivingDemos/Force.h @@ -25,6 +25,7 @@ class Force : public QMainWindow private: Ui::Fullscreen *ui; QGraphicsScene _background; + bool _origin; }; #endif // FORCE_H diff --git a/LivingDemos/GestureOutput.cpp b/LivingDemos/GestureOutput.cpp index 18de6fc..8a005bf 100644 --- a/LivingDemos/GestureOutput.cpp +++ b/LivingDemos/GestureOutput.cpp @@ -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); } } diff --git a/LivingDemos/LivingDemos.pro b/LivingDemos/LivingDemos.pro index fa8765d..c46a256 100644 --- a/LivingDemos/LivingDemos.pro +++ b/LivingDemos/LivingDemos.pro @@ -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 diff --git a/LivingDemos/MenuPrincipal.cpp b/LivingDemos/MenuPrincipal.cpp index 98cd6dc..a09a2e6 100644 --- a/LivingDemos/MenuPrincipal.cpp +++ b/LivingDemos/MenuPrincipal.cpp @@ -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())); } diff --git a/LivingDemos/Peephole.cpp b/LivingDemos/Peephole.cpp index 9295c38..a9e01e3 100644 --- a/LivingDemos/Peephole.cpp +++ b/LivingDemos/Peephole.cpp @@ -6,13 +6,13 @@ #include #include -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(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; } diff --git a/LivingDemos/Peephole.h b/LivingDemos/Peephole.h index b0acc85..797b716 100644 --- a/LivingDemos/Peephole.h +++ b/LivingDemos/Peephole.h @@ -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; }; diff --git a/LivingDemos/ScreenRotate.cpp b/LivingDemos/ScreenRotate.cpp index e8f9f51..a09c3ba 100644 --- a/LivingDemos/ScreenRotate.cpp +++ b/LivingDemos/ScreenRotate.cpp @@ -1,13 +1,19 @@ #include "ScreenRotate.h" #include -#include #include +#include + +#include + +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(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(this->parent()); + if (menu->getScreen()) + { + menu->getScreen()->rotation(_screenangle); + _previousscreenangle = _screenangle; + } + } + QTimer::singleShot(_updatedelay, this, SLOT(updatescreenangle())); +} + void ScreenRotate::rotateScreen() { MenuPrincipal * menu = dynamic_cast(this->parent()); @@ -55,6 +83,11 @@ void ScreenRotate::rotateScreen() } } +void ScreenRotate::rotateScreen(int v) +{ + _screenangle = v; +} + void ScreenRotate::setupEmails() { if (_window) diff --git a/LivingDemos/ScreenRotate.h b/LivingDemos/ScreenRotate.h index abd88c5..dfd5ad9 100644 --- a/LivingDemos/ScreenRotate.h +++ b/LivingDemos/ScreenRotate.h @@ -5,9 +5,11 @@ #include #include +#include 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 index 0000000..260fd85 --- /dev/null +++ b/LivingDemos/ScreenRotationControl.cpp @@ -0,0 +1,24 @@ +#include "ScreenRotationControl.h" +#include "ui_screenrotationcontrol.h" + +#include + +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 index 0000000..628b756 --- /dev/null +++ b/LivingDemos/ScreenRotationControl.h @@ -0,0 +1,28 @@ +#ifndef SCREENROTATIONCONTROL_H +#define SCREENROTATIONCONTROL_H + +#include + +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 index 0000000..3cba9a1 --- /dev/null +++ b/LivingDemos/screenrotationcontrol.ui @@ -0,0 +1,73 @@ + + + ScreenRotationControl + + + + 0 + 0 + 400 + 240 + + + + Dialog + + + + + + + 75 + true + + + + Screen angular position + + + Qt::AlignCenter + + + + + + + 180 + + + 10 + + + Qt::Horizontal + + + QSlider::TicksBothSides + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QDialogButtonBox::Close + + + + + + + + diff --git a/images/calendarapp.png b/images/calendarapp.png index 11b9a8c..40f5529 100644 Binary files a/images/calendarapp.png and b/images/calendarapp.png differ diff --git a/images/emailapp.png b/images/emailapp.png index fe109a1..2854175 100644 Binary files a/images/emailapp.png and b/images/emailapp.png differ diff --git a/images/presentationapp.png b/images/presentationapp.png index a1eb176..3856fe3 100644 Binary files a/images/presentationapp.png and b/images/presentationapp.png differ