[Simulator] Asynchronous SimulatorInterface & a few new features. (#4738)
[opentx.git] / radio / src / targets / simu / opentxsimulator.h
blobd3ba6689af8eec45029336e47e754bb3a36cf194
1 /*
2 * Author - Bertrand Songis <bsongis@gmail.com>
4 * Based on th9x -> http://code.google.com/p/th9x/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #ifndef _OPENTX_SIMULATOR_H_
18 #define _OPENTX_SIMULATOR_H_
20 #include "simulatorinterface.h"
22 #include <QMutex>
23 #include <QObject>
24 #include <QTimer>
26 #if defined __GNUC__
27 #define DLLEXPORT
28 #else
29 #define DLLEXPORT __declspec(dllexport)
30 #endif
32 class DLLEXPORT OpenTxSimulator : public SimulatorInterface
34 Q_OBJECT
36 public:
38 OpenTxSimulator();
39 virtual ~OpenTxSimulator();
41 virtual QString name();
42 virtual bool isRunning();
43 virtual void readRadioData(QByteArray & dest);
44 virtual uint8_t * getLcd();
45 virtual uint8_t getSensorInstance(uint16_t id, uint8_t defaultValue = 0);
46 virtual uint16_t getSensorRatio(uint16_t id);
47 virtual const int getCapability(Capability cap);
49 static QVector<QIODevice *> tracebackDevices;
51 public slots:
53 virtual void init();
54 virtual void start(const char * filename = NULL, bool tests = true);
55 virtual void stop();
56 virtual void setSdPath(const QString & sdPath = "", const QString & settingsPath = "");
57 virtual void setVolumeGain(const int value);
58 virtual void setRadioData(const QByteArray & data);
59 virtual void setAnalogValue(uint8_t index, int16_t value);
60 virtual void setKey(uint8_t key, bool state);
61 virtual void setSwitch(uint8_t swtch, int8_t state);
62 virtual void setTrim(unsigned int idx, int value);
63 virtual void setTrimSwitch(uint8_t trim, bool state);
64 virtual void setTrainerInput(unsigned int inputNumber, int16_t value);
65 virtual void setInputValue(int type, uint8_t index, int16_t value);
66 virtual void rotaryEncoderEvent(int steps);
67 virtual void setTrainerTimeout(uint16_t ms);
68 virtual void sendTelemetry(uint8_t * data, unsigned int len);
69 virtual void setLuaStateReloadPermanentScripts();
70 virtual void addTracebackDevice(QIODevice * device);
71 virtual void removeTracebackDevice(QIODevice * device);
73 protected slots:
74 void run();
76 protected:
78 bool isStopRequested();
79 void setStopRequested(bool stop);
80 bool checkLcdChanged();
81 void checkOutputsChanged();
82 uint8_t getStickMode();
83 const char * getPhaseName(unsigned int phase);
84 const QString getCurrentPhaseName();
85 const char * getError();
86 const int voltageToAdc(const int volts);
88 QString simuSdDirectory;
89 QString simuSettingsDirectory;
90 QTimer * m_timer10ms;
91 QMutex m_mtxStopReq;
92 QMutex m_mtxSimuMain;
93 QMutex m_mtxRadioData;
94 QMutex m_mtxSettings;
95 QMutex m_mtxTbDevices;
96 int volumeGain;
97 bool m_resetOutputsData;
98 bool m_stopRequested;
102 #endif // _OPENTX_SIMULATOR_H_