Bsongis/issue 4400 (#4425)
[opentx.git] / companion / src / simulation / simulatorwidget.h
blob69e798ec37725330cd90b72bbb8d43dc77ee33e2
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _SIMULATORWIDGET_H_
22 #define _SIMULATORWIDGET_H_
24 #include "constants.h"
25 #include "helpers.h"
26 #include "radiodata.h"
27 #include "simulator.h"
29 #include <QWidget>
30 #include <QVector>
32 #define FLASH_DURATION 10
34 #define CBEEP_ON "QLabel { background-color: #FF364E }"
35 #define CBEEP_OFF "QLabel { }"
37 void traceCb(const char * text);
39 class Firmware;
40 class SimulatorInterface;
41 class SimulatedUIWidget;
42 class RadioWidget;
43 class RadioSwitchWidget;
44 class VirtualJoystickWidget;
45 #ifdef JOYSTICKS
46 class Joystick;
47 #endif
49 class QWidget;
50 class QSlider;
51 class QLabel;
52 class QFrame;
54 namespace Ui {
55 class SimulatorWidget;
58 using namespace Simulator;
60 class SimulatorWidget : public QWidget
62 Q_OBJECT
64 public:
65 explicit SimulatorWidget(QWidget * parent, SimulatorInterface *simulator, quint8 flags=0);
66 virtual ~SimulatorWidget();
68 void setSdPath(const QString & sdPath);
69 void setDataPath(const QString & dataPath);
70 void setPaths(const QString & sdPath, const QString & dataPath);
71 void setRadioSettings(const GeneralSettings settings);
72 bool setStartupData(const QByteArray & dataSource = NULL, bool fromFile = false);
73 bool setRadioData(RadioData * radioData);
74 bool setOptions(SimulatorOptions & options, bool withSave = true);
75 bool saveRadioData(RadioData * radioData, const QString & path = "", QString * error = NULL);
76 bool useTempDataPath(bool deleteOnClose = true);
77 bool saveTempData();
78 void deleteTempData();
79 void saveState();
80 void setUiAreaStyle(const QString & style);
81 void captureScreenshot(bool);
82 void setupJoysticks();
84 QString getSdPath() const { return sdCardPath; }
85 QString getDataPath() const { return radioDataPath; }
86 QVector<keymapHelp_t> * getKeymapHelp() { return &keymapHelp; }
88 public slots:
89 void start();
90 void stop();
91 void restart();
92 void shutdown();
94 private:
95 void setRadioProfileId(int value);
96 void setupRadioWidgets();
97 void setupTimer();
98 void restoreRadioWidgetsState();
99 QList<QByteArray> saveRadioWidgetsState();
101 void setValues();
102 void getValues();
103 void setTrims();
106 Ui::SimulatorWidget * ui;
107 SimulatorInterface * simulator;
108 Firmware * firmware;
109 GeneralSettings radioSettings;
111 QTimer * timer;
112 QString windowName;
113 QVector<keymapHelp_t> keymapHelp;
115 SimulatedUIWidget * radioUiWidget;
116 VirtualJoystickWidget * vJoyLeft;
117 VirtualJoystickWidget * vJoyRight;
119 QVector<RadioSwitchWidget *> switches;
120 QVector<RadioWidget *> analogs;
122 QString sdCardPath;
123 QString radioDataPath;
124 QByteArray startupData;
125 Board::Type m_board;
126 quint8 flags;
127 int radioProfileId;
128 int lastPhase;
129 int buttonPressed;
130 int trimPressed;
131 bool startupFromFile;
132 bool deleteTempRadioData;
133 bool saveTempRadioData;
134 bool middleButtonPressed;
135 bool firstShow;
137 #ifdef JOYSTICKS
138 Joystick *joystick;
139 int jscal[8][4];
140 int jsmap[8];
141 #endif
143 private slots:
144 //virtual void showEvent(QShowEvent *);
145 //virtual void closeEvent(QCloseEvent *);
146 virtual void mousePressEvent(QMouseEvent *event);
147 virtual void mouseReleaseEvent(QMouseEvent *event);
148 virtual void wheelEvent(QWheelEvent *event);
150 void onTimerEvent();
151 void onTrimPressed(int which);
152 void onTrimReleased();
153 void onTrimSliderMoved(int which, int value);
154 void centerSticks();
155 void onjoystickAxisValueChanged(int axis, int value);
159 #endif // _SIMULATORWIDGET_H_