diff --git a/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp b/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp index 4d452c312..51f204ecd 100644 --- a/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp +++ b/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp @@ -559,7 +559,12 @@ void OpenTxSimulator::getTrims(Trims & trims) void OpenTxSimulator::wheelEvent(int steps) { -#if defined(REV9E) +#if defined(PCBHORUS) || defined(PCBFLAMENCO) + if (steps > 0) + rotencValue -= 2; + else + rotencValue += 2; +#elif defined(REV9E) if (steps == 255) rotencValue -= 2; else diff --git a/companion/src/simulation/CMakeLists.txt b/companion/src/simulation/CMakeLists.txt index c5173c094..8a6249219 100644 --- a/companion/src/simulation/CMakeLists.txt +++ b/companion/src/simulation/CMakeLists.txt @@ -18,11 +18,9 @@ set(simulation_UIS set(simulation_HDRS simulatordialog.h - cursorwidget.h - menuwidget.h - xcursorwidget.h - xmenuwidget.h - myslider.h + # lcdwidget.h + buttonswidget.h + sliderwidget.h telemetrysimu.h trainersimu.h debugoutput.h diff --git a/companion/src/simulation/buttonswidget.h b/companion/src/simulation/buttonswidget.h new file mode 100644 index 000000000..80d09ee06 --- /dev/null +++ b/companion/src/simulation/buttonswidget.h @@ -0,0 +1,120 @@ +/* + * Author - Bertrand Songis + * + * Based on th9x -> http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef _BUTTONSWIDGET_H_ +#define _BUTTONSWIDGET_H_ + +#include +#include + +class ButtonsWidget : public QWidget +{ + + Q_OBJECT + + public: + + explicit ButtonsWidget(QWidget * parent): + QWidget(parent) + { + } + + + virtual void setStyleSheet(const QString & sheet) + { + defaultStyleSheet = sheet; + QWidget::setStyleSheet(sheet); + } + + void addArea(int x1, int y1, int x2, int y2, int key, const char * bitmap) + { + QPolygon polygon; + polygon.setPoints(4, x1, y1, x1, y2, x2, y2, x2, y1); + addArea(polygon, key, bitmap); + } + + void addArea(const QPolygon & polygon, int key, const char * bitmap) + { + areas.push_back(Area(polygon, key, bitmap)); + } + + protected: + + class Area { + public: + Area(const QPolygon & polygon, int key, const char * bitmap): + polygon(polygon), + key(key), + bitmap(bitmap) + { + } + bool contains(int x, int y) + { + return polygon.containsPoint(QPoint(x, y), Qt::OddEvenFill); + } + public: + QPolygon polygon; + int key; + const char * bitmap; + }; + + void setBitmap(const char * bitmap) + { + QWidget::setStyleSheet(QString("background:url(:/images/%1);").arg(bitmap)); + } + + virtual void mousePressEvent(QMouseEvent * event) + { + int x = event->x(); + int y = event->y(); + setFocus(); + if (event->button() == Qt::LeftButton) { + foreach(Area area, areas) { + if (area.contains(x, y)) { + setBitmap(area.bitmap); + emit buttonPressed(area.key); + break; + } + } + } + } + + virtual void mouseReleaseEvent(QMouseEvent * event) + { + QWidget::setStyleSheet(defaultStyleSheet); + setFocus(); + emit buttonPressed(0); + } + + void paintEvent(QPaintEvent *) + { + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); + } + + signals: + + void buttonPressed(int button); + + protected: + + QList areas; + QString defaultStyleSheet; +}; + +#endif /* _BUTTONSWIDGET_H_ */ diff --git a/companion/src/simulation/cursorwidget.h b/companion/src/simulation/cursorwidget.h deleted file mode 100644 index 7d35b343e..000000000 --- a/companion/src/simulation/cursorwidget.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -#ifndef CURSORWIDGET_H -#define CURSORWIDGET_H - -#include -#include - -class cursorWidget : public QWidget { - - Q_OBJECT - - public: - - explicit cursorWidget(QWidget * parent = 0): - QWidget(parent) - { - } - - protected: - - virtual void mousePressEvent(QMouseEvent * event) - { - float upx[] = {68,28,51,83,105,68}; - float upy[] = {83,45,32,32,45,83}; - float minx[] = {74,114,127,127,114,74}; - float miny[] = {90,51,80,106,130,90}; - float dox[] = {68,28,51,83,105,68}; - float doy[] = {98,137,151,151,137,98}; - float plusx[] = { 80,20,7,7,20,80}; - float plusy[] = {90,51,80,106,130,90}; - - int x=event->x(); - int y=event->y(); - setFocus(); - if (event->button()==Qt::LeftButton) { - if (pnpoly(6,upx,upy,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/9xcursup.png);"); - emit buttonPressed(Qt::Key_Up); - } - else if (pnpoly(6,minx,miny,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/9xcursmin.png);"); - emit buttonPressed(Qt::Key_Right); - } - else if (pnpoly(6,dox,doy,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/9xcursdown.png);"); - emit buttonPressed(Qt::Key_Down); - } - else if (pnpoly(6,plusx,plusy,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/9xcursplus.png);"); - emit buttonPressed(Qt::Key_Left); - } else if (sqrt(((float)x-22)*((float)x-22)+((float)y-165)*((float)y-165))<17) { - setStyleSheet("background:url(:/images/9xcursphoto.png);"); - emit buttonPressed(Qt::Key_Print); - } - } - // QWidget::mousePressEvent(event); - } - - virtual void mouseReleaseEvent(QMouseEvent * event) - { - setStyleSheet("background:url(:/images/9xcurs.png);"); - emit buttonPressed(0); - setFocus(); - //QWidget::mouseReleaseEvent(event); - } - - void paintEvent(QPaintEvent *) - { - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); - } - - inline int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) - { - int i, j, c = 0; - for (i = 0, j = nvert-1; i < nvert; j = i++) { - if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) - c = !c; - } - return c; - } - - signals: - void buttonPressed(int button); - -}; - - -#endif /* CURSORWIDGET_H */ - diff --git a/companion/src/simulation/dialwidget.h b/companion/src/simulation/dialwidget.h new file mode 100644 index 000000000..d84099a61 --- /dev/null +++ b/companion/src/simulation/dialwidget.h @@ -0,0 +1,25 @@ +#ifndef _DIALWIDGET_H_ +#define _DIALWIDGET_H_ + +class DialWidget : public QDial +{ + public: + + explicit DialWidget(QWidget * parent = 0): + QDial(parent) + { + } + + protected: + + void mousePressEvent(QMouseEvent * event) + { + if (event->button() == Qt::RightButton && event->type() == QEvent::MouseButtonDblClick) { + setValue(0); + event->accept(); + } + QDial::mousePressEvent(event); + } +}; + +#endif // _DIALWIDGET_H_ diff --git a/companion/src/simulation/lcdwidget.h b/companion/src/simulation/lcdwidget.h index 035c8ce8b..12dbbc8bb 100644 --- a/companion/src/simulation/lcdwidget.h +++ b/companion/src/simulation/lcdwidget.h @@ -14,14 +14,16 @@ * */ -#ifndef _LCD_WIDGET_H_ -#define _LCD_WIDGET_H_ +#ifndef _LCDWIDGET_H_ +#define _LCDWIDGET_H_ #include #include "appdata.h" -class LcdWidget : public QWidget { +class LcdWidget : public QWidget +{ public: + LcdWidget(QWidget * parent = 0): QWidget(parent), lcdBuf(NULL), @@ -186,4 +188,4 @@ class LcdWidget : public QWidget { }; -#endif // _LCD_WIDGET_H_ +#endif // _LCDWIDGET_H_ diff --git a/companion/src/simulation/menuwidget.h b/companion/src/simulation/menuwidget.h deleted file mode 100644 index 9974286eb..000000000 --- a/companion/src/simulation/menuwidget.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -#ifndef MENUWIDGET_H -#define MENUWIDGET_H - -#include -#include - -class menuWidget : public QWidget { - - Q_OBJECT - - public: - - explicit menuWidget(QWidget * parent = 0): - QWidget(parent) - { - } - - protected: - - virtual void mousePressEvent(QMouseEvent * event) - { - int x=event->x(); - int y=event->y(); - setFocus(); - if (event->button()==Qt::LeftButton) { - if (x>25 && x<71 && y>60 && y<81) { - setStyleSheet("background:url(:/images/9xmenumenu.png);"); - emit buttonPressed(Qt::Key_Enter); - } else if (x>25 && x<71 && y>117 && y<139) { - setStyleSheet("background:url(:/images/9xmenuexit.png);"); - emit buttonPressed(Qt::Key_Escape); - } - } - // QWidget::mousePressEvent(event); - } - - virtual void mouseReleaseEvent(QMouseEvent * event) - { - setStyleSheet("background:url(:/images/9xmenu.png);"); - setFocus(); - emit buttonPressed(0); - // QWidget::mouseReleaseEvent(event); - } - - void paintEvent(QPaintEvent *) - { - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); - } - - signals: - void buttonPressed(int button); - -}; -#endif /* MENUWIDGET_H */ - diff --git a/companion/src/simulation/myqdial.h b/companion/src/simulation/myqdial.h deleted file mode 100644 index 54f76473e..000000000 --- a/companion/src/simulation/myqdial.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MYQDIAL_H -#define MYQDIAL_H - - -class myQDial : public QDial -{ -public: - explicit myQDial(QWidget *parent = 0) : QDial(parent) {} - -protected: - void mousePressEvent(QMouseEvent *event) - { - if (event->button() == Qt::RightButton && event->type() == QEvent::MouseButtonDblClick) { - setValue(0); - event->accept(); - } - QDial::mousePressEvent(event); - } -}; - -#endif diff --git a/companion/src/simulation/myslider.h b/companion/src/simulation/myslider.h deleted file mode 100644 index d2c6801a5..000000000 --- a/companion/src/simulation/myslider.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef MYSLIDER_H -#define MYSLIDER_H - -#include -#include - -class mySlider : public QSlider -{ - Q_OBJECT - - public: - - explicit mySlider(QFrame * parent = 0): - QSlider(parent) - { - } - - -protected: - - void mousePressEvent(QMouseEvent * event) - { - if (event->button() == Qt::RightButton && event->type() == QEvent::MouseButtonDblClick) { - setValue(0); - event->accept(); - } - QSlider::mousePressEvent(event); - } -}; - -#endif diff --git a/companion/src/simulation/simulatordialog-9x.ui b/companion/src/simulation/simulatordialog-9x.ui index a4bd8be46..085eb56b3 100644 --- a/companion/src/simulation/simulatordialog-9x.ui +++ b/companion/src/simulation/simulatordialog-9x.ui @@ -30,7 +30,16 @@ :/icon.png:/icon.png - + + 5 + + + 5 + + + 5 + + 5 @@ -66,7 +75,16 @@ 2 - + + 5 + + + 5 + + + 5 + + 5 @@ -399,7 +417,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -463,7 +481,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -868,7 +886,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -932,7 +950,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -990,7 +1008,16 @@ QPushButton:checked { 2 - + + 2 + + + 2 + + + 2 + + 2 @@ -1020,7 +1047,7 @@ QPushButton:checked { - + 0 @@ -1077,7 +1104,7 @@ QPushButton:checked { - + 0 @@ -1137,7 +1164,7 @@ QPushButton:checked { - + 0 @@ -1286,7 +1313,7 @@ QPushButton:checked { - + 0 @@ -1339,8 +1366,27 @@ QPushButton:checked { + + + + + 0 + 0 + + + + + 55 + 186 + + + + background:url(:/images/9xdr.png) + + + - + 0 @@ -1361,25 +1407,6 @@ QPushButton:checked { - - - - - 0 - 0 - - - - - 55 - 186 - - - - background:url(:/images/9xdr.png) - - - @@ -1475,26 +1502,20 @@ QPushButton:checked { 1 - mySlider + SliderWidget QSlider -
myslider.h
+
sliderwidget.h
- cursorWidget - QWidget -
cursorwidget.h
- 1 -
- - menuWidget - QWidget -
menuwidget.h
- 1 -
- - myQDial + DialWidget QDial -
myqdial.h
+
dialwidget.h
+
+ + ButtonsWidget + QWidget +
buttonswidget.h
+ 1
diff --git a/companion/src/simulation/simulatordialog-flamenco.ui b/companion/src/simulation/simulatordialog-flamenco.ui index 09d45e6cc..74beb1638 100644 --- a/companion/src/simulation/simulatordialog-flamenco.ui +++ b/companion/src/simulation/simulatordialog-flamenco.ui @@ -7,7 +7,7 @@ 0 0 726 - 688 + 708
@@ -30,7 +30,16 @@ :/icon.png:/icon.png - + + 5 + + + 5 + + + 5 + + 5 @@ -86,7 +95,7 @@ 0 - + 0 @@ -108,7 +117,7 @@ - + 0 @@ -263,7 +272,16 @@ 2 - + + 5 + + + 5 + + + 5 + + 5 @@ -298,7 +316,7 @@ - + 0 @@ -902,7 +920,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -991,7 +1009,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -1579,7 +1597,7 @@ QPushButton:checked { - + 0 @@ -1639,21 +1657,15 @@ QPushButton:checked { 1 - mySlider + ButtonsWidget + QWidget +
buttonswidget.h
+ 1 +
+ + SliderWidget QSlider -
myslider.h
-
- - xcursorWidget - QWidget -
xcursorwidget.h
- 1 -
- - xmenuWidget - QWidget -
xmenuwidget.h
- 1 +
sliderwidget.h
diff --git a/companion/src/simulation/simulatordialog-horus.ui b/companion/src/simulation/simulatordialog-horus.ui index fbeb54962..c51e173f9 100644 --- a/companion/src/simulation/simulatordialog-horus.ui +++ b/companion/src/simulation/simulatordialog-horus.ui @@ -6,8 +6,8 @@ 0 0 - 726 - 688 + 739 + 740
@@ -30,7 +30,16 @@ :/icon.png:/icon.png - + + 5 + + + 5 + + + 5 + + 5 @@ -78,54 +87,13 @@ - + QLayout::SetMinimumSize 0 - - - - - 0 - 0 - - - - - 120 - 208 - - - - true - - - background:url(:/images/x9l0.png); - - - - - - - - 0 - 0 - - - - - 120 - 208 - - - - background:url(:/images/x9r0.png) - - - @@ -142,6 +110,47 @@ + + + + + 0 + 0 + + + + + 89 + 186 + + + + true + + + background:url(:/images/9xmenu.png); + + + + + + + + 0 + 0 + + + + + 128 + 186 + + + + background:url(:/images/9xcurs.png) + + + @@ -263,7 +272,16 @@ 2 - + + 5 + + + 5 + + + 5 + + 5 @@ -298,7 +316,7 @@
- + 0 @@ -902,7 +920,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -991,7 +1009,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -1579,7 +1597,7 @@ QPushButton:checked { - + 0 @@ -1639,21 +1657,15 @@ QPushButton:checked { 1 - mySlider + ButtonsWidget + QWidget +
buttonswidget.h
+ 1 +
+ + SliderWidget QSlider -
myslider.h
-
- - xcursorWidget - QWidget -
xcursorwidget.h
- 1 -
- - xmenuWidget - QWidget -
xmenuwidget.h
- 1 +
sliderwidget.h
diff --git a/companion/src/simulation/simulatordialog-taranis.ui b/companion/src/simulation/simulatordialog-taranis.ui index 422cc5195..65c040d92 100644 --- a/companion/src/simulation/simulatordialog-taranis.ui +++ b/companion/src/simulation/simulatordialog-taranis.ui @@ -7,7 +7,7 @@ 0 0 739 - 658 + 695
@@ -30,7 +30,16 @@ :/icon.png:/icon.png - + + 5 + + + 5 + + + 5 + + 5 @@ -86,7 +95,7 @@ 0 - + 0 @@ -127,7 +136,7 @@ - + 0 @@ -864,7 +873,7 @@ - + 0 @@ -904,7 +913,7 @@ - + 0 @@ -935,7 +944,7 @@ - + 0 @@ -966,7 +975,7 @@ - + 0 @@ -1248,7 +1257,7 @@ QPushButton:checked { - + 0 @@ -1320,7 +1329,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -1420,7 +1429,7 @@ QPushButton:checked { - + Right Double Click to Reset @@ -1638,7 +1647,7 @@ QPushButton:checked { - + 0 @@ -1741,26 +1750,20 @@ QPushButton:checked { 1 - mySlider + ButtonsWidget + QWidget +
buttonswidget.h
+ 1 +
+ + SliderWidget QSlider -
myslider.h
+
sliderwidget.h
- xcursorWidget - QWidget -
xcursorwidget.h
- 1 -
- - xmenuWidget - QWidget -
xmenuwidget.h
- 1 -
- - myQDial + DialWidget QDial -
myqdial.h
+
dialwidget.h
diff --git a/companion/src/simulation/simulatordialog.cpp b/companion/src/simulation/simulatordialog.cpp index 24d6bba2b..fbf96467f 100644 --- a/companion/src/simulation/simulatordialog.cpp +++ b/companion/src/simulation/simulatordialog.cpp @@ -1,9 +1,10 @@ #include "simulatordialog.h" -#include "ui_simulatordialog-9x.h" -#include "ui_simulatordialog-taranis.h" +#include "appdata.h" +#include "lcdwidget.h" #include #include "helpers.h" #include "simulatorinterface.h" +#include "sliderwidget.h" #define GBALL_SIZE 20 #define RESX 1024 @@ -47,6 +48,11 @@ void SimulatorDialog::updateDebugOutput() traceMutex.unlock(); } +void SimulatorDialog::wheelEvent (QWheelEvent *event) +{ + simulator->wheelEvent(event->delta() > 0 ? 1 : -1); +} + SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator, unsigned int flags): QDialog(parent), flags(flags), @@ -70,154 +76,6 @@ SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator traceCallbackInstance = this; } -uint32_t SimulatorDialog9X::switchstatus = 0; - -SimulatorDialog9X::SimulatorDialog9X(QWidget * parent, SimulatorInterface *simulator, unsigned int flags): - SimulatorDialog(parent, simulator, flags), - ui(new Ui::SimulatorDialog9X), - beepShow(0) -{ - lcdWidth = 128; - lcdHeight = 64; - lcdDepth = 1; - - initUi(ui); - - // install simulator TRACE hook - simulator->installTraceHook(traceCb); - - backLight = g.backLight(); - if (backLight > 4) backLight = 0; - switch (backLight) { - case 1: - ui->lcd->setBackgroundColor(166,247,159); - break; - case 2: - ui->lcd->setBackgroundColor(247,159,166); - break; - case 3: - ui->lcd->setBackgroundColor(255,195,151); - break; - case 4: - ui->lcd->setBackgroundColor(247,242,159); - break; - default: - ui->lcd->setBackgroundColor(159,165,247); - break; - } - - //restore switches - if (g.simuSW()) - restoreSwitches(); - - ui->trimHR_L->setText(QString::fromUtf8(leftArrow)); - ui->trimHR_R->setText(QString::fromUtf8(rightArrow)); - ui->trimVR_U->setText(QString::fromUtf8(upArrow)); - ui->trimVR_D->setText(QString::fromUtf8(downArrow)); - ui->trimHL_L->setText(QString::fromUtf8(leftArrow)); - ui->trimHL_R->setText(QString::fromUtf8(rightArrow)); - ui->trimVL_U->setText(QString::fromUtf8(upArrow)); - ui->trimVL_D->setText(QString::fromUtf8(downArrow)); - for (int i=0; isetProperty("index", i); - connect(pots[i], SIGNAL(valueChanged(int)), this, SLOT(dialChanged(int))); - } - connect(ui->cursor, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); - connect(ui->menu, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); - connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimHR_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimVR_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimVR_D, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimHL_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimHL_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimVL_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimVL_D, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimHR_L, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimHR_R, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimVR_U, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimVR_D, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimHL_R, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimHL_L, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimVL_U, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimVL_D, SIGNAL(released()), this, SLOT(onTrimReleased())); -} - -SimulatorDialog9X::~SimulatorDialog9X() -{ - saveSwitches(); - delete ui; -} - -uint32_t SimulatorDialogTaranis::switchstatus = 0; - -SimulatorDialogTaranis::SimulatorDialogTaranis(QWidget * parent, SimulatorInterface *simulator, unsigned int flags): - SimulatorDialog(parent, simulator, flags), - ui(new Ui::SimulatorDialogTaranis) -{ - lcdWidth = 212; - lcdHeight = 64; - lcdDepth = 4; - - initUi(ui); - - // install simulator TRACE hook - simulator->installTraceHook(traceCb); - - ui->lcd->setBackgroundColor(47, 123, 227); - - // restore switches - if (g.simuSW()) { - restoreSwitches(); - } - - for (int i=0; isetValue(-1024); - pots[i]->setSingleStep(2048/5); - pots[i]->setPageStep(2048/5); - } - else if (!(flags & (SIMULATOR_FLAGS_S1 << i))) { - pots[i]->hide(); - potLabels[i]->hide(); - } - } - - ui->trimHR_L->setText(QString::fromUtf8(leftArrow)); - ui->trimHR_R->setText(QString::fromUtf8(rightArrow)); - ui->trimVR_U->setText(QString::fromUtf8(upArrow)); - ui->trimVR_D->setText(QString::fromUtf8(downArrow)); - ui->trimHL_L->setText(QString::fromUtf8(leftArrow)); - ui->trimHL_R->setText(QString::fromUtf8(rightArrow)); - ui->trimVL_U->setText(QString::fromUtf8(upArrow)); - ui->trimVL_D->setText(QString::fromUtf8(downArrow)); - - connect(ui->cursor, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); - connect(ui->menu, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); - connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimHR_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimVR_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimVR_D, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimHL_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimHL_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimVL_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimVL_D, SIGNAL(pressed()), this, SLOT(onTrimPressed())); - connect(ui->trimHR_L, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimHR_R, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimVR_U, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimVR_D, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimHL_R, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimHL_L, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimVL_U, SIGNAL(released()), this, SLOT(onTrimReleased())); - connect(ui->trimVL_D, SIGNAL(released()), this, SLOT(onTrimReleased())); -} - -SimulatorDialogTaranis::~SimulatorDialogTaranis() -{ - saveSwitches(); - delete ui; -} - - SimulatorDialog::~SimulatorDialog() { traceCallbackInstance = 0; @@ -245,17 +103,6 @@ void SimulatorDialog::mouseReleaseEvent(QMouseEvent *event) } } -void SimulatorDialog9X::dialChanged(int value) -{ - int index = sender()->property("index").toInt(); - potValues[index]->setText(QString("%1 %").arg((value*100)/1024)); -} - -void SimulatorDialog::wheelEvent (QWheelEvent *event) -{ - simulator->wheelEvent(event->delta() > 0 ? 1 : -1); -} - void SimulatorDialog::onTrimPressed() { if (sender()->objectName() == QString("trimHL_L")) @@ -600,36 +447,6 @@ void SimulatorDialog::onButtonPressed(int value) } } -void SimulatorDialog9X::setLightOn(bool enable) -{ - QString bg = ""; - if (enable) { - QStringList list; - list << "bl" << "gr" << "rd" << "or" << "yl"; - bg = QString("-") + list[backLight]; - } - ui->top->setStyleSheet(QString("background:url(:/images/9xdt%1.png);").arg(bg)); - ui->bottom->setStyleSheet(QString("background:url(:/images/9xdb%1.png);").arg(bg)); - ui->left->setStyleSheet(QString("background:url(:/images/9xdl%1.png);").arg(bg)); - ui->right->setStyleSheet(QString("background:url(:/images/9xdr%1.png);").arg(bg)); -} - -void SimulatorDialog9X::updateBeepButton() -{ - #define CBEEP_ON "QLabel { background-color: #FF364E }" - #define CBEEP_OFF "QLabel { }" - - if (beepVal) { - beepShow = 20; - } - - ui->label_beep->setStyleSheet(beepShow ? CBEEP_ON : CBEEP_OFF); - - if (beepShow) { - beepShow--; - } -} - void SimulatorDialog::onTimerEvent() { static unsigned int lcd_counter = 0; @@ -729,211 +546,6 @@ void SimulatorDialog::setTrims() trimHRight->setRange(trimMin, trimMax); trimHRight->setValue(trims.values[3]); } -void SimulatorDialog9X::getValues() -{ - TxInputs inputs = { - { - int(1024*nodeLeft->getX()), // LEFT HORZ - int(-1024*nodeLeft->getY()), // LEFT VERT - int(-1024*nodeRight->getY()), // RGHT VERT - int(1024*nodeRight->getX()) // RGHT HORZ - }, - - { - pots[0]->value(), - pots[1]->value(), - pots[2]->value() - }, - - { - ui->switchTHR->isChecked(), - ui->switchRUD->isChecked(), - ui->switchELE->isChecked(), - ui->switchID2->isChecked() ? 1 : (ui->switchID1->isChecked() ? 0 : -1), - ui->switchAIL->isChecked(), - ui->switchGEA->isChecked(), - ui->switchTRN->isDown(), - 0, 0, 0 - }, - - { - buttonPressed == Qt::Key_Enter, - buttonPressed == Qt::Key_Escape, - buttonPressed == Qt::Key_Down, - buttonPressed == Qt::Key_Up, - buttonPressed == Qt::Key_Right, - buttonPressed == Qt::Key_Left, - }, - - middleButtonPressed, - - { - trimPressed == TRIM_LH_L, - trimPressed == TRIM_LH_R, - trimPressed == TRIM_LV_DN, - trimPressed == TRIM_LV_UP, - trimPressed == TRIM_RV_DN, - trimPressed == TRIM_RV_UP, - trimPressed == TRIM_RH_L, - trimPressed == TRIM_RH_R - } - }; - - simulator->setValues(inputs); -} - -void SimulatorDialog9X::saveSwitches(void) -{ - // qDebug() << "SimulatorDialog9X::saveSwitches()"; - switchstatus=ui->switchTHR->isChecked(); - switchstatus<<=1; - switchstatus+=(ui->switchRUD->isChecked()&0x1); - switchstatus<<=1; - switchstatus+=(ui->switchID2->isChecked()&0x1); - switchstatus<<=1; - switchstatus+=(ui->switchID1->isChecked()&0x1); - switchstatus<<=1; - switchstatus+=(ui->switchID0->isChecked()&0x1); - switchstatus<<=1; - switchstatus+=(ui->switchGEA->isChecked()&0x1); - switchstatus<<=1; - switchstatus+=(ui->switchELE->isChecked()&0x1); - switchstatus<<=1; - switchstatus+=(ui->switchAIL->isChecked()&0x1); -} - -void SimulatorDialog9X::restoreSwitches(void) -{ - // qDebug() << "SimulatorDialog9X::restoreSwitches()"; - ui->switchAIL->setChecked(switchstatus & 0x1); - switchstatus >>=1; - ui->switchELE->setChecked(switchstatus & 0x1); - switchstatus >>=1; - ui->switchGEA->setChecked(switchstatus & 0x1); - switchstatus >>=1; - ui->switchID0->setChecked(switchstatus & 0x1); - switchstatus >>=1; - ui->switchID1->setChecked(switchstatus & 0x1); - switchstatus >>=1; - ui->switchID2->setChecked(switchstatus & 0x1); - switchstatus >>=1; - ui->switchRUD->setChecked(switchstatus & 0x1); - switchstatus >>=1; - ui->switchTHR->setChecked(switchstatus & 0x1); -} - -void SimulatorDialogTaranis::resetSH() -{ - ui->switchH->setValue(0); -} - -void SimulatorDialogTaranis::on_switchH_sliderReleased() -{ - QTimer::singleShot(400, this, SLOT(resetSH())); -} - -void SimulatorDialogTaranis::getValues() -{ - for (int i=0; ivalue()+1024)/(2048.0/5))*(2048.0/5)-1024; - pots[i]->setValue(s1); - } - } - - TxInputs inputs = { - { - int(1024*nodeLeft->getX()), // LEFT HORZ - int(-1024*nodeLeft->getY()), // LEFT VERT - int(-1024*nodeRight->getY()), // RGHT VERT - int(1024*nodeRight->getX()) // RGHT HORZ - }, - - { - -pots[0]->value(), - pots[1]->value(), - ((flags && SIMULATOR_FLAGS_S3) ? pots[2]->value() : 0), - -sliders[0]->value(), - sliders[1]->value() - }, - - { - ui->switchA->value() - 1, - ui->switchB->value() - 1, - ui->switchC->value() - 1, - ui->switchD->value() - 1, - ui->switchE->value() - 1, - ui->switchF->value(), - ui->switchG->value() - 1, - ui->switchH->value(), 0, 0 - }, - - { - buttonPressed == Qt::Key_PageUp, - buttonPressed == Qt::Key_Escape, - buttonPressed == Qt::Key_Enter, - buttonPressed == Qt::Key_PageDown, - buttonPressed == Qt::Key_Plus, - buttonPressed == Qt::Key_Minus - }, - - middleButtonPressed, - - { - trimPressed == TRIM_LH_L, - trimPressed == TRIM_LH_R, - trimPressed == TRIM_LV_DN, - trimPressed == TRIM_LV_UP, - trimPressed == TRIM_RV_DN, - trimPressed == TRIM_RV_UP, - trimPressed == TRIM_RH_L, - trimPressed == TRIM_RH_R - } - }; - - simulator->setValues(inputs); -} - -void SimulatorDialogTaranis::saveSwitches(void) -{ - // qDebug() << "SimulatorDialogTaranis::saveSwitches()"; - switchstatus=ui->switchA->value(); - switchstatus<<=2; - switchstatus+=ui->switchB->value(); - switchstatus<<=2; - switchstatus+=ui->switchC->value(); - switchstatus<<=2; - switchstatus+=ui->switchD->value(); - switchstatus<<=2; - switchstatus+=ui->switchE->value(); - switchstatus<<=2; - switchstatus+=ui->switchF->value(); - switchstatus<<=2; - switchstatus+=ui->switchG->value(); - switchstatus<<=2; - switchstatus+=ui->switchH->value(); -} - -void SimulatorDialogTaranis::restoreSwitches(void) -{ - // qDebug() << "SimulatorDialogTaranis::restoreSwitches()"; - ui->switchH->setValue(switchstatus & 0x3); - switchstatus>>=2; - ui->switchG->setValue(switchstatus & 0x3); - switchstatus>>=2; - ui->switchF->setValue(switchstatus & 0x3); - switchstatus>>=2; - ui->switchE->setValue(switchstatus & 0x3); - switchstatus>>=2; - ui->switchD->setValue(switchstatus & 0x3); - switchstatus>>=2; - ui->switchC->setValue(switchstatus & 0x3); - switchstatus>>=2; - ui->switchB->setValue(switchstatus & 0x3); - switchstatus>>=2; - ui->switchA->setValue(switchstatus & 0x3); -} - inline int chVal(int val) { return qMin(1024, qMax(-1024, val)); @@ -1136,5 +748,7 @@ void SimulatorDialog::onjoystickAxisValueChanged(int axis, int value) } #endif +#include "simulatordialog9x.cpp" +#include "simulatordialogtaranis.cpp" #include "simulatordialogflamenco.cpp" #include "simulatordialoghorus.cpp" diff --git a/companion/src/simulation/simulatordialog.h b/companion/src/simulation/simulatordialog.h index 44af808e6..c63ba6d0b 100644 --- a/companion/src/simulation/simulatordialog.h +++ b/companion/src/simulation/simulatordialog.h @@ -27,7 +27,7 @@ namespace Ui { // TODO rename + move? class LcdWidget; -class mySlider; +class SliderWidget; #define SIMULATOR_FLAGS_NOTX 1 #define SIMULATOR_FLAGS_STICK_MODE_LEFT 2 @@ -67,7 +67,7 @@ class SimulatorDialog : public QDialog QVector potValues; QVector sliders; - mySlider * trimHLeft, * trimVLeft, * trimHRight, * trimVRight; + SliderWidget * trimHLeft, * trimVLeft, * trimHRight, * trimVRight; QLabel * leftXPerc, * rightXPerc, * leftYPerc, * rightYPerc; QTabWidget * tabWidget; QVector logicalSwitchLabels; diff --git a/companion/src/simulation/simulatordialog9x.cpp b/companion/src/simulation/simulatordialog9x.cpp new file mode 100644 index 000000000..3b84c8064 --- /dev/null +++ b/companion/src/simulation/simulatordialog9x.cpp @@ -0,0 +1,225 @@ +#include "ui_simulatordialog-9x.h" + +uint32_t SimulatorDialog9X::switchstatus = 0; + +SimulatorDialog9X::SimulatorDialog9X(QWidget * parent, SimulatorInterface *simulator, unsigned int flags): + SimulatorDialog(parent, simulator, flags), + ui(new Ui::SimulatorDialog9X), + beepShow(0) +{ + QPolygon polygon; + + lcdWidth = 128; + lcdHeight = 64; + lcdDepth = 1; + + initUi(ui); + + polygon.setPoints(6, 68, 83, 28, 45, 51, 32, 83, 32, 105, 45, 68, 83); + ui->leftbuttons->addArea(polygon, Qt::Key_Up, "9xcursup.png"); + polygon.setPoints(6, 74, 90, 114, 51, 127, 80, 127, 106, 114, 130, 74, 90); + ui->leftbuttons->addArea(polygon, Qt::Key_Right, "9xcursmin.png"); + polygon.setPoints(6, 68, 98, 28, 137, 51, 151, 83, 151, 105, 137, 68, 98); + ui->leftbuttons->addArea(polygon, Qt::Key_Down, "9xcursdown.png"); + polygon.setPoints(6, 80, 90, 20, 51, 7, 80, 7, 106, 20, 130, 80, 90); + ui->leftbuttons->addArea(polygon, Qt::Key_Left, "9xcursplus.png"); + ui->leftbuttons->addArea(5, 148, 39, 182, Qt::Key_Print, "9xcursphoto.png"); + + ui->rightbuttons->addArea(25, 60, 71, 81, Qt::Key_Enter, "9xmenumenu.png"); + ui->rightbuttons->addArea(25, 117, 71, 139, Qt::Key_Escape, "9xmenuexit.png"); + + // install simulator TRACE hook + simulator->installTraceHook(traceCb); + + backLight = g.backLight(); + if (backLight > 4) backLight = 0; + switch (backLight) { + case 1: + ui->lcd->setBackgroundColor(166,247,159); + break; + case 2: + ui->lcd->setBackgroundColor(247,159,166); + break; + case 3: + ui->lcd->setBackgroundColor(255,195,151); + break; + case 4: + ui->lcd->setBackgroundColor(247,242,159); + break; + default: + ui->lcd->setBackgroundColor(159,165,247); + break; + } + + //restore switches + if (g.simuSW()) + restoreSwitches(); + + ui->trimHR_L->setText(QString::fromUtf8(leftArrow)); + ui->trimHR_R->setText(QString::fromUtf8(rightArrow)); + ui->trimVR_U->setText(QString::fromUtf8(upArrow)); + ui->trimVR_D->setText(QString::fromUtf8(downArrow)); + ui->trimHL_L->setText(QString::fromUtf8(leftArrow)); + ui->trimHL_R->setText(QString::fromUtf8(rightArrow)); + ui->trimVL_U->setText(QString::fromUtf8(upArrow)); + ui->trimVL_D->setText(QString::fromUtf8(downArrow)); + for (int i=0; isetProperty("index", i); + connect(pots[i], SIGNAL(valueChanged(int)), this, SLOT(dialChanged(int))); + } + connect(ui->leftbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); + connect(ui->rightbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); + connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimHR_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimVR_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimVR_D, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimHL_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimHL_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimVL_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimVL_D, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimHR_L, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimHR_R, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimVR_U, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimVR_D, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimHL_R, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimHL_L, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimVL_U, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimVL_D, SIGNAL(released()), this, SLOT(onTrimReleased())); +} + +SimulatorDialog9X::~SimulatorDialog9X() +{ + saveSwitches(); + delete ui; +} + +void SimulatorDialog9X::dialChanged(int value) +{ + int index = sender()->property("index").toInt(); + potValues[index]->setText(QString("%1 %").arg((value*100)/1024)); +} + +void SimulatorDialog9X::setLightOn(bool enable) +{ + QString bg = ""; + if (enable) { + QStringList list; + list << "bl" << "gr" << "rd" << "or" << "yl"; + bg = QString("-") + list[backLight]; + } + ui->top->setStyleSheet(QString("background:url(:/images/9xdt%1.png);").arg(bg)); + ui->bottom->setStyleSheet(QString("background:url(:/images/9xdb%1.png);").arg(bg)); + ui->left->setStyleSheet(QString("background:url(:/images/9xdl%1.png);").arg(bg)); + ui->right->setStyleSheet(QString("background:url(:/images/9xdr%1.png);").arg(bg)); +} + +void SimulatorDialog9X::updateBeepButton() +{ + #define CBEEP_ON "QLabel { background-color: #FF364E }" + #define CBEEP_OFF "QLabel { }" + + if (beepVal) { + beepShow = 20; + } + + ui->label_beep->setStyleSheet(beepShow ? CBEEP_ON : CBEEP_OFF); + + if (beepShow) { + beepShow--; + } +} + + +void SimulatorDialog9X::getValues() +{ + TxInputs inputs = { + { + int(1024*nodeLeft->getX()), // LEFT HORZ + int(-1024*nodeLeft->getY()), // LEFT VERT + int(-1024*nodeRight->getY()), // RGHT VERT + int(1024*nodeRight->getX()) // RGHT HORZ + }, + + { + pots[0]->value(), + pots[1]->value(), + pots[2]->value() + }, + + { + ui->switchTHR->isChecked(), + ui->switchRUD->isChecked(), + ui->switchELE->isChecked(), + ui->switchID2->isChecked() ? 1 : (ui->switchID1->isChecked() ? 0 : -1), + ui->switchAIL->isChecked(), + ui->switchGEA->isChecked(), + ui->switchTRN->isDown(), + 0, 0, 0 + }, + + { + buttonPressed == Qt::Key_Enter, + buttonPressed == Qt::Key_Escape, + buttonPressed == Qt::Key_Down, + buttonPressed == Qt::Key_Up, + buttonPressed == Qt::Key_Right, + buttonPressed == Qt::Key_Left, + }, + + middleButtonPressed, + + { + trimPressed == TRIM_LH_L, + trimPressed == TRIM_LH_R, + trimPressed == TRIM_LV_DN, + trimPressed == TRIM_LV_UP, + trimPressed == TRIM_RV_DN, + trimPressed == TRIM_RV_UP, + trimPressed == TRIM_RH_L, + trimPressed == TRIM_RH_R + } + }; + + simulator->setValues(inputs); +} + +void SimulatorDialog9X::saveSwitches(void) +{ + // qDebug() << "SimulatorDialog9X::saveSwitches()"; + switchstatus=ui->switchTHR->isChecked(); + switchstatus<<=1; + switchstatus+=(ui->switchRUD->isChecked()&0x1); + switchstatus<<=1; + switchstatus+=(ui->switchID2->isChecked()&0x1); + switchstatus<<=1; + switchstatus+=(ui->switchID1->isChecked()&0x1); + switchstatus<<=1; + switchstatus+=(ui->switchID0->isChecked()&0x1); + switchstatus<<=1; + switchstatus+=(ui->switchGEA->isChecked()&0x1); + switchstatus<<=1; + switchstatus+=(ui->switchELE->isChecked()&0x1); + switchstatus<<=1; + switchstatus+=(ui->switchAIL->isChecked()&0x1); +} + +void SimulatorDialog9X::restoreSwitches(void) +{ + // qDebug() << "SimulatorDialog9X::restoreSwitches()"; + ui->switchAIL->setChecked(switchstatus & 0x1); + switchstatus >>=1; + ui->switchELE->setChecked(switchstatus & 0x1); + switchstatus >>=1; + ui->switchGEA->setChecked(switchstatus & 0x1); + switchstatus >>=1; + ui->switchID0->setChecked(switchstatus & 0x1); + switchstatus >>=1; + ui->switchID1->setChecked(switchstatus & 0x1); + switchstatus >>=1; + ui->switchID2->setChecked(switchstatus & 0x1); + switchstatus >>=1; + ui->switchRUD->setChecked(switchstatus & 0x1); + switchstatus >>=1; + ui->switchTHR->setChecked(switchstatus & 0x1); +} + diff --git a/companion/src/simulation/simulatordialogflamenco.cpp b/companion/src/simulation/simulatordialogflamenco.cpp index 364c5a819..c3ecac913 100644 --- a/companion/src/simulation/simulatordialogflamenco.cpp +++ b/companion/src/simulation/simulatordialogflamenco.cpp @@ -34,8 +34,8 @@ SimulatorDialogFlamenco::SimulatorDialogFlamenco(QWidget * parent, SimulatorInte ui->trimVL_U->setText(QString::fromUtf8(upArrow)); ui->trimVL_D->setText(QString::fromUtf8(downArrow)); - connect(ui->cursor, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); - connect(ui->menu, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); + connect(ui->leftbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); + connect(ui->rightbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); connect(ui->trimHR_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); connect(ui->trimVR_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); diff --git a/companion/src/simulation/simulatordialoghorus.cpp b/companion/src/simulation/simulatordialoghorus.cpp index df64a61b0..3bd7733bb 100644 --- a/companion/src/simulation/simulatordialoghorus.cpp +++ b/companion/src/simulation/simulatordialoghorus.cpp @@ -8,12 +8,27 @@ SimulatorDialogHorus::SimulatorDialogHorus(QWidget * parent, SimulatorInterface SimulatorDialog(parent, simulator, flags), ui(new Ui::SimulatorDialogHorus) { + QPolygon polygon; + lcdWidth = 480; lcdHeight = 270; lcdDepth = 16; initUi(ui); + polygon.setPoints(6, 68, 83, 28, 45, 51, 32, 83, 32, 105, 45, 68, 83); + ui->rightbuttons->addArea(polygon, Qt::Key_Up, "9xcursup.png"); + polygon.setPoints(6, 74, 90, 114, 51, 127, 80, 127, 106, 114, 130, 74, 90); + ui->rightbuttons->addArea(polygon, Qt::Key_Right, "9xcursmin.png"); + polygon.setPoints(6, 68, 98, 28, 137, 51, 151, 83, 151, 105, 137, 68, 98); + ui->rightbuttons->addArea(polygon, Qt::Key_Down, "9xcursdown.png"); + polygon.setPoints(6, 80, 90, 20, 51, 7, 80, 7, 106, 20, 130, 80, 90); + ui->rightbuttons->addArea(polygon, Qt::Key_Left, "9xcursplus.png"); + ui->rightbuttons->addArea(5, 148, 39, 182, Qt::Key_Print, "9xcursphoto.png"); + + ui->leftbuttons->addArea(25, 60, 71, 81, Qt::Key_PageUp, "9xmenumenu.png"); + ui->leftbuttons->addArea(25, 117, 71, 139, Qt::Key_Escape, "9xmenuexit.png"); + // install simulator TRACE hook simulator->installTraceHook(traceCb); @@ -34,8 +49,8 @@ SimulatorDialogHorus::SimulatorDialogHorus(QWidget * parent, SimulatorInterface ui->trimVL_U->setText(QString::fromUtf8(upArrow)); ui->trimVL_D->setText(QString::fromUtf8(downArrow)); - connect(ui->cursor, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); - connect(ui->menu, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); + connect(ui->leftbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); + connect(ui->rightbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); connect(ui->trimHR_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); connect(ui->trimVR_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); @@ -103,9 +118,10 @@ void SimulatorDialogHorus::getValues() buttonPressed == Qt::Key_PageUp, buttonPressed == Qt::Key_Escape, buttonPressed == Qt::Key_Enter, - buttonPressed == Qt::Key_PageDown, - buttonPressed == Qt::Key_Plus, - buttonPressed == Qt::Key_Minus + buttonPressed == Qt::Key_Up, + buttonPressed == Qt::Key_Down, + buttonPressed == Qt::Key_Right, + buttonPressed == Qt::Key_Left }, middleButtonPressed, diff --git a/companion/src/simulation/simulatordialogtaranis.cpp b/companion/src/simulation/simulatordialogtaranis.cpp new file mode 100644 index 000000000..432601a65 --- /dev/null +++ b/companion/src/simulation/simulatordialogtaranis.cpp @@ -0,0 +1,201 @@ +#include "ui_simulatordialog-taranis.h" + +uint32_t SimulatorDialogTaranis::switchstatus = 0; + +SimulatorDialogTaranis::SimulatorDialogTaranis(QWidget * parent, SimulatorInterface *simulator, unsigned int flags): + SimulatorDialog(parent, simulator, flags), + ui(new Ui::SimulatorDialogTaranis) +{ + QPolygon polygon; + + lcdWidth = 212; + lcdHeight = 64; + lcdDepth = 4; + + initUi(ui); + + polygon.setPoints(6, 20, 59, 27, 50, 45, 52, 56, 59, 50, 71, 26, 72); + ui->leftbuttons->addArea(polygon, Qt::Key_PageUp, "x9l1.png"); + polygon.setPoints(6, 23, 107, 30, 99, 46, 100, 55, 106, 47, 117, 28, 117); + ui->leftbuttons->addArea(polygon, Qt::Key_PageDown, "x9l2.png"); + polygon.setPoints(6, 24, 154, 32, 144, 46, 146, 57, 156, 46, 167, 29, 166); + ui->leftbuttons->addArea(polygon, Qt::Key_Escape, "x9l3.png"); + ui->leftbuttons->addArea(90, 177, 118, 197, Qt::Key_Print, "x9l4.png"); + polygon.setPoints(6, 64, 60, 71, 50, 90, 50, 100, 60, 90, 73, 72, 73); + ui->rightbuttons->addArea(polygon, Qt::Key_Plus, "x9r1.png"); + polygon.setPoints(6, 63, 109, 73, 100, 88, 100, 98, 109, 88, 119, 72, 119); + ui->rightbuttons->addArea(polygon, Qt::Key_Minus, "x9r2.png"); + polygon.setPoints(6, 63, 155, 72, 146, 90, 146, 98, 155, 88, 166, 72, 166); + ui->rightbuttons->addArea(polygon, Qt::Key_Enter, "x9r3.png"); + + // install simulator TRACE hook + simulator->installTraceHook(traceCb); + + ui->lcd->setBackgroundColor(47, 123, 227); + + // restore switches + if (g.simuSW()) { + restoreSwitches(); + } + + for (int i=0; isetValue(-1024); + pots[i]->setSingleStep(2048/5); + pots[i]->setPageStep(2048/5); + } + else if (!(flags & (SIMULATOR_FLAGS_S1 << i))) { + pots[i]->hide(); + potLabels[i]->hide(); + } + } + + ui->trimHR_L->setText(QString::fromUtf8(leftArrow)); + ui->trimHR_R->setText(QString::fromUtf8(rightArrow)); + ui->trimVR_U->setText(QString::fromUtf8(upArrow)); + ui->trimVR_D->setText(QString::fromUtf8(downArrow)); + ui->trimHL_L->setText(QString::fromUtf8(leftArrow)); + ui->trimHL_R->setText(QString::fromUtf8(rightArrow)); + ui->trimVL_U->setText(QString::fromUtf8(upArrow)); + ui->trimVL_D->setText(QString::fromUtf8(downArrow)); + + connect(ui->leftbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); + connect(ui->rightbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); + connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimHR_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimVR_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimVR_D, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimHL_R, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimHL_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimVL_U, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimVL_D, SIGNAL(pressed()), this, SLOT(onTrimPressed())); + connect(ui->trimHR_L, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimHR_R, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimVR_U, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimVR_D, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimHL_R, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimHL_L, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimVL_U, SIGNAL(released()), this, SLOT(onTrimReleased())); + connect(ui->trimVL_D, SIGNAL(released()), this, SLOT(onTrimReleased())); +} + +SimulatorDialogTaranis::~SimulatorDialogTaranis() +{ + saveSwitches(); + delete ui; +} + + +void SimulatorDialogTaranis::resetSH() +{ + ui->switchH->setValue(0); +} + +void SimulatorDialogTaranis::on_switchH_sliderReleased() +{ + QTimer::singleShot(400, this, SLOT(resetSH())); +} + +void SimulatorDialogTaranis::getValues() +{ + for (int i=0; ivalue()+1024)/(2048.0/5))*(2048.0/5)-1024; + pots[i]->setValue(s1); + } + } + + TxInputs inputs = { + { + int(1024*nodeLeft->getX()), // LEFT HORZ + int(-1024*nodeLeft->getY()), // LEFT VERT + int(-1024*nodeRight->getY()), // RGHT VERT + int(1024*nodeRight->getX()) // RGHT HORZ + }, + + { + -pots[0]->value(), + pots[1]->value(), + ((flags && SIMULATOR_FLAGS_S3) ? pots[2]->value() : 0), + -sliders[0]->value(), + sliders[1]->value() + }, + + { + ui->switchA->value() - 1, + ui->switchB->value() - 1, + ui->switchC->value() - 1, + ui->switchD->value() - 1, + ui->switchE->value() - 1, + ui->switchF->value(), + ui->switchG->value() - 1, + ui->switchH->value(), 0, 0 + }, + + { + buttonPressed == Qt::Key_PageUp, + buttonPressed == Qt::Key_Escape, + buttonPressed == Qt::Key_Enter, + buttonPressed == Qt::Key_PageDown, + buttonPressed == Qt::Key_Plus, + buttonPressed == Qt::Key_Minus + }, + + middleButtonPressed, + + { + trimPressed == TRIM_LH_L, + trimPressed == TRIM_LH_R, + trimPressed == TRIM_LV_DN, + trimPressed == TRIM_LV_UP, + trimPressed == TRIM_RV_DN, + trimPressed == TRIM_RV_UP, + trimPressed == TRIM_RH_L, + trimPressed == TRIM_RH_R + } + }; + + simulator->setValues(inputs); +} + +void SimulatorDialogTaranis::saveSwitches(void) +{ + // qDebug() << "SimulatorDialogTaranis::saveSwitches()"; + switchstatus=ui->switchA->value(); + switchstatus<<=2; + switchstatus+=ui->switchB->value(); + switchstatus<<=2; + switchstatus+=ui->switchC->value(); + switchstatus<<=2; + switchstatus+=ui->switchD->value(); + switchstatus<<=2; + switchstatus+=ui->switchE->value(); + switchstatus<<=2; + switchstatus+=ui->switchF->value(); + switchstatus<<=2; + switchstatus+=ui->switchG->value(); + switchstatus<<=2; + switchstatus+=ui->switchH->value(); +} + +void SimulatorDialogTaranis::restoreSwitches(void) +{ + // qDebug() << "SimulatorDialogTaranis::restoreSwitches()"; + ui->switchH->setValue(switchstatus & 0x3); + switchstatus>>=2; + ui->switchG->setValue(switchstatus & 0x3); + switchstatus>>=2; + ui->switchF->setValue(switchstatus & 0x3); + switchstatus>>=2; + ui->switchE->setValue(switchstatus & 0x3); + switchstatus>>=2; + ui->switchD->setValue(switchstatus & 0x3); + switchstatus>>=2; + ui->switchC->setValue(switchstatus & 0x3); + switchstatus>>=2; + ui->switchB->setValue(switchstatus & 0x3); + switchstatus>>=2; + ui->switchA->setValue(switchstatus & 0x3); +} + + diff --git a/companion/src/simulation/sliderwidget.h b/companion/src/simulation/sliderwidget.h new file mode 100644 index 000000000..90f094cb6 --- /dev/null +++ b/companion/src/simulation/sliderwidget.h @@ -0,0 +1,30 @@ +#ifndef _SLIDERWIDGET_H_ +#define _SLIDERWIDGET_H_ + +#include +#include + +class SliderWidget : public QSlider +{ + Q_OBJECT + + public: + + explicit SliderWidget(QFrame * parent = 0): + QSlider(parent) + { + } + + protected: + + void mousePressEvent(QMouseEvent * event) + { + if (event->button() == Qt::RightButton && event->type() == QEvent::MouseButtonDblClick) { + setValue(0); + event->accept(); + } + QSlider::mousePressEvent(event); + } +}; + +#endif // _SLIDERWIDGET_H_ diff --git a/companion/src/simulation/xcursorwidget.h b/companion/src/simulation/xcursorwidget.h deleted file mode 100644 index 36c024149..000000000 --- a/companion/src/simulation/xcursorwidget.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -#ifndef XCURSORWIDGET_H -#define XCURSORWIDGET_H - -#include -#include - -class xcursorWidget : public QWidget { - - Q_OBJECT - - public: - - explicit xcursorWidget(QWidget * parent = 0): - QWidget(parent) - { - } - - protected: - - virtual void mousePressEvent(QMouseEvent * event) - { - float p1x[] = {20,27,45,56,50,26}; - float p1y[] = {59,50,52,59,71,72}; - float p2x[] = {23,30,46,55,47,28}; - float p2y[] = {107,99,100,106,117,117}; - float p3x[] = {24,32,46,57,46,29}; - float p3y[] = {154,144,146,156,167,166}; - - int x=event->x(); - int y=event->y(); - setFocus(); - if (event->button()==Qt::LeftButton) { - if (pnpoly(6,p1x,p1y,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/x9l1.png);"); - emit buttonPressed(Qt::Key_PageUp); - } - else if (pnpoly(6,p2x,p2y,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/x9l2.png);"); - emit buttonPressed(Qt::Key_PageDown); - } - else if (pnpoly(6,p3x,p3y,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/x9l3.png);"); - emit buttonPressed(Qt::Key_Escape); - } else if ((x>90 && x<118) && (y>177 && y<197)) { - setStyleSheet("background:url(:/images/x9l4.png);"); - emit buttonPressed(Qt::Key_Print); - } - } - // QWidget::mousePressEvent(event); - } - - virtual void mouseReleaseEvent(QMouseEvent * event) - { - setStyleSheet("background:url(:/images/x9l0.png);"); - emit buttonPressed(0); - setFocus(); - //QWidget::mouseReleaseEvent(event); - } - - void paintEvent(QPaintEvent *) - { - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); - } - - inline int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) - { - int i, j, c = 0; - for (i = 0, j = nvert-1; i < nvert; j = i++) { - if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) - c = !c; - } - return c; - } - - signals: - void buttonPressed(int button); - -}; - - -#endif /* CURSORWIDGET_H */ - diff --git a/companion/src/simulation/xmenuwidget.h b/companion/src/simulation/xmenuwidget.h deleted file mode 100644 index 6bcf7795c..000000000 --- a/companion/src/simulation/xmenuwidget.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -#ifndef XMENUWIDGET_H -#define XMENUWIDGET_H - -#include -#include - -class xmenuWidget : public QWidget { - - Q_OBJECT - - public: - - explicit xmenuWidget(QWidget * parent = 0): - QWidget(parent) - { - } - - protected: - - virtual void mousePressEvent(QMouseEvent * event) - { - float p1x[] = {64,71,90,100,90,72}; - float p1y[] = {60,50,50,60,73,73}; - float p2x[] = {63,73,88,98,88,72}; - float p2y[] = {109,100,100,109,119,119}; - float p3x[] = {63,72,90,98,88,72}; - float p3y[] = {155,146,146,155,166,166}; - - int x=event->x(); - int y=event->y(); - setFocus(); - if (event->button()==Qt::LeftButton) { - if (pnpoly(6,p1x,p1y,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/x9r1.png);"); - emit buttonPressed(Qt::Key_Plus); - } - else if (pnpoly(6,p2x,p2y,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/x9r2.png);"); - emit buttonPressed(Qt::Key_Minus); - } - else if (pnpoly(6,p3x,p3y,(float)x,(float)y)==1) { - setStyleSheet("background:url(:/images/x9r3.png);"); - emit buttonPressed(Qt::Key_Enter); - } - } - // QWidget::mousePressEvent(event); - } - - virtual void mouseReleaseEvent(QMouseEvent * event) - { - setStyleSheet("background:url(:/images/x9r0.png);"); - setFocus(); - emit buttonPressed(0); - // QWidget::mouseReleaseEvent(event); - } - - void paintEvent(QPaintEvent *) - { - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); - } - - inline int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy) - { - int i, j, c = 0; - for (i = 0, j = nvert-1; i < nvert; j = i++) { - if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) - c = !c; - } - return c; - } - - signals: - void buttonPressed(int button); - -}; -#endif /* XMENUWIDGET_H */ - diff --git a/radio/src/simu.cpp b/radio/src/simu.cpp index 81aad43fe..d8616ed19 100644 --- a/radio/src/simu.cpp +++ b/radio/src/simu.cpp @@ -378,7 +378,6 @@ long Open9xSim::onTimeout(FXObject*, FXSelector, void*) #endif #if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBHORUS) - extern rotenc_t rotencValue; static bool rotencAction = false; if (getApp()->getKeyState(KEY_G)) { if (!rotencAction) ROTENC_VALUE += ROTARY_ENCODER_GRANULARITY; diff --git a/radio/util/font2png.py b/radio/util/font2png.py index 135671542..a44dbcb25 100755 --- a/radio/util/font2png.py +++ b/radio/util/font2png.py @@ -6,9 +6,9 @@ from PyQt4 import Qt, QtCore, QtGui import glob try: - app = Qt.QApplication(sys.argv) + app = Qt.QApplication(sys.argv) except: - pass + app = Qt.QCoreApplication(sys.argv) for f in glob.glob("fonts/*.ttf"): QtGui.QFontDatabase.addApplicationFont(f)