Update CREDITS.txt
[opentx.git] / companion / src / simulation / simulatorwidget.h
blobe3377084b868457148f42f88bc56923575dda7ca
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 "radiowidget.h"
28 #include "simulator.h"
29 #include "simulatorinterface.h"
31 #include <QElapsedTimer>
32 #include <QTimer>
33 #include <QWidget>
34 #include <QVector>
36 void traceCb(const char * text);
38 class Firmware;
39 class SimulatorInterface;
40 class SimulatedUIWidget;
41 class VirtualJoystickWidget;
42 #ifdef JOYSTICKS
43 class Joystick;
44 #endif
46 class QWidget;
47 class QSlider;
48 class QLabel;
49 class QFrame;
51 namespace Ui {
52 class SimulatorWidget;
55 class SimulatorWidget : public QWidget
57 Q_OBJECT
59 public:
60 explicit SimulatorWidget(QWidget * parent, SimulatorInterface *simulator, quint8 flags=0);
61 virtual ~SimulatorWidget();
63 void setSdPath(const QString & sdPath);
64 void setDataPath(const QString & dataPath);
65 void setPaths(const QString & sdPath, const QString & dataPath);
66 void setRadioSettings(const GeneralSettings settings);
67 bool setStartupData(const QByteArray & dataSource = NULL, bool fromFile = false);
68 bool setRadioData(RadioData * radioData);
69 bool setOptions(SimulatorOptions & options, bool withSave = true);
70 bool saveRadioData(RadioData * radioData, const QString & path = "", QString * error = NULL);
71 bool useTempDataPath(bool deleteOnClose = true);
72 bool saveTempData();
73 void deleteTempData();
74 void saveState();
75 void setUiAreaStyle(const QString & style);
76 void captureScreenshot(bool);
77 void setupJoysticks();
79 QString getSdPath() const { return sdCardPath; }
80 QString getDataPath() const { return radioDataPath; }
81 QVector<Simulator::keymapHelp_t> getKeymapHelp() const { return keymapHelp; }
83 public slots:
84 void start();
85 void stop();
86 void restart();
87 void shutdown();
89 signals:
90 void stickValueChange(int axis, int value);
91 void stickModeChange(const unsigned mode);
92 void widgetValueChange(const RadioWidget::RadioWidgetType type, const int index, const int value);
93 void widgetStateChange(const RadioWidget::RadioWidgetState & state);
94 void inputValueChange(int type, quint8 index, qint16 value);
95 void simulatorSetData(const QByteArray & data);
96 void simulatorInit();
97 void simulatorStart(const char * filename, bool tests);
98 void simulatorStop();
99 void simulatorSdPathChange(const QString & sdPath, const QString & dataPath);
100 void simulatorVolumeGainChange(const int gain);
102 private slots:
103 virtual void mousePressEvent(QMouseEvent *event);
104 virtual void mouseReleaseEvent(QMouseEvent *event);
105 virtual void wheelEvent(QWheelEvent *event);
107 void onTimerEvent();
108 void onSimulatorStarted();
109 void onSimulatorStopped();
110 void onSimulatorHeartbeat(qint32 loops, qint64 timestamp);
111 void onPhaseChanged(qint32 phase, const QString & name);
112 void onSimulatorError(const QString & error);
113 void onRadioWidgetValueChange(const RadioWidget::RadioWidgetType type, const int index, int value);
114 void onjoystickAxisValueChanged(int axis, int value);
116 void setRadioProfileId(int value);
117 void setupRadioWidgets();
118 void restoreRadioWidgetsState();
120 private:
121 void saveRadioWidgetsState(QList<QByteArray> & state);
123 Ui::SimulatorWidget * ui;
124 SimulatorInterface * simulator;
125 Firmware * firmware;
126 GeneralSettings radioSettings;
128 QTimer m_timer;
129 QString windowName;
130 QVector<Simulator::keymapHelp_t> keymapHelp;
131 QElapsedTimer m_heartbeatTimer;
133 SimulatedUIWidget * radioUiWidget;
134 VirtualJoystickWidget * vJoyLeft;
135 VirtualJoystickWidget * vJoyRight;
136 QVector<RadioWidget *> m_radioWidgets;
138 QString sdCardPath;
139 QString radioDataPath;
140 QByteArray startupData;
141 Board::Type m_board;
142 quint8 flags;
143 int radioProfileId;
144 bool startupFromFile;
145 bool deleteTempRadioData;
146 bool saveTempRadioData;
148 #ifdef JOYSTICKS
149 Joystick *joystick;
150 #endif
154 #endif // _SIMULATORWIDGET_H_