From 67cd3214000ee7dd10ca22caaba0ed06c34248fa Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Mon, 1 Jun 2015 20:53:01 +0200 Subject: [PATCH] Re #2260: class Profile dependency removed from simulatorinterface --- .../er9x/simulator/er9xsimulator.cpp | 2 +- .../firmwares/er9x/simulator/er9xsimulator.h | 2 +- .../ersky9x/simulator/ersky9xsimulator.cpp | 2 +- .../ersky9x/simulator/ersky9xsimulator.h | 2 +- .../opentx/simulator/opentxsimulator.cpp | 26 ++++++++++++------- .../opentx/simulator/opentxsimulator.h | 11 ++++++-- companion/src/simulation/simulatordialog.cpp | 6 +++-- companion/src/simulation/simulatorinterface.h | 9 ++++--- companion/src/simulator.cpp | 4 ++- 9 files changed, 43 insertions(+), 21 deletions(-) diff --git a/companion/src/firmwares/er9x/simulator/er9xsimulator.cpp b/companion/src/firmwares/er9x/simulator/er9xsimulator.cpp index 9b45ab81d..10fd339c9 100644 --- a/companion/src/firmwares/er9x/simulator/er9xsimulator.cpp +++ b/companion/src/firmwares/er9x/simulator/er9xsimulator.cpp @@ -182,7 +182,7 @@ bool Er9xSimulator::lcdChanged(bool & lightEnable) #include "simulatorimport.h" } -void Er9xSimulator::start(RadioData &radioData, const Profile & profile, bool tests) +void Er9xSimulator::start(RadioData &radioData, bool tests) { er9xInterface->save(&eeprom[0], radioData); StartMainThread(tests); diff --git a/companion/src/firmwares/er9x/simulator/er9xsimulator.h b/companion/src/firmwares/er9x/simulator/er9xsimulator.h index 0f4121740..f6fb7fad6 100644 --- a/companion/src/firmwares/er9x/simulator/er9xsimulator.h +++ b/companion/src/firmwares/er9x/simulator/er9xsimulator.h @@ -28,7 +28,7 @@ class Er9xSimulator : public SimulatorInterface { Er9xSimulator(Er9xInterface *); - virtual void start(RadioData & radioData, const Profile & profile, bool tests); + virtual void start(RadioData & radioData, bool tests); virtual void stop(); diff --git a/companion/src/firmwares/ersky9x/simulator/ersky9xsimulator.cpp b/companion/src/firmwares/ersky9x/simulator/ersky9xsimulator.cpp index 90e40b84d..868f81625 100644 --- a/companion/src/firmwares/ersky9x/simulator/ersky9xsimulator.cpp +++ b/companion/src/firmwares/ersky9x/simulator/ersky9xsimulator.cpp @@ -204,7 +204,7 @@ bool Ersky9xSimulator::lcdChanged(bool & lightEnable) #include "simulatorimport.h" } -void Ersky9xSimulator::start(RadioData &radioData, const Profile & profile, bool tests) +void Ersky9xSimulator::start(RadioData &radioData, bool tests) { ersky9xInterface->save(Ersky9x::eeprom, radioData); StartEepromThread(NULL); diff --git a/companion/src/firmwares/ersky9x/simulator/ersky9xsimulator.h b/companion/src/firmwares/ersky9x/simulator/ersky9xsimulator.h index 5b6a03fef..57737257d 100644 --- a/companion/src/firmwares/ersky9x/simulator/ersky9xsimulator.h +++ b/companion/src/firmwares/ersky9x/simulator/ersky9xsimulator.h @@ -28,7 +28,7 @@ class Ersky9xSimulator : public SimulatorInterface { Ersky9xSimulator(Ersky9xInterface *); - virtual void start(RadioData & radioData, const Profile & profile, bool tests); + virtual void start(RadioData & radioData, bool tests); virtual void stop(); diff --git a/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp b/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp index 8fba65343..a56b4beb9 100644 --- a/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp +++ b/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp @@ -339,6 +339,19 @@ OpenTxSimulator::OpenTxSimulator() { } +void OpenTxSimulator::setSdPath(const QString &sdPath) +{ +#if defined(SDCARD) + strncpy(simuSdDirectory, sdPath.toAscii().constData(), sizeof(simuSdDirectory)-1); + simuSdDirectory[sizeof(simuSdDirectory)-1] = '\0'; +#endif +} + +void OpenTxSimulator::setVolumeGain(int value) +{ + volumeGain = value; +} + bool OpenTxSimulator::timer10ms() { #define TIMER10MS_IMPORT @@ -357,19 +370,14 @@ bool OpenTxSimulator::lcdChanged(bool & lightEnable) #include "simulatorimport.h" } -void OpenTxSimulator::start(QByteArray & eeprom, const Profile & profile, bool tests) +void OpenTxSimulator::start(QByteArray & eeprom, bool tests) { memcpy(NAMESPACE::eeprom, eeprom.data(), std::min(sizeof(NAMESPACE::eeprom), eeprom.size())); - start((const char *)0, profile, tests); + start((const char *)0, tests); } -void OpenTxSimulator::start(const char * filename, const Profile & profile, bool tests) +void OpenTxSimulator::start(const char * filename, bool tests) { -#if defined(SDCARD) - strncpy(simuSdDirectory, profile.sdPath().toAscii().constData(), sizeof(simuSdDirectory)-1); - simuSdDirectory[sizeof(simuSdDirectory)-1] = '\0'; -#endif - #if defined(PCBSKY9X) && !defined(REVX) g_rotenc[0] = 0; #elif defined(PCBGRUVIN9X) @@ -378,7 +386,7 @@ void OpenTxSimulator::start(const char * filename, const Profile & profile, bool #endif StartEepromThread(filename); - StartAudioThread(profile.volumeGain()); + StartAudioThread(volumeGain); StartMainThread(tests); } diff --git a/companion/src/firmwares/opentx/simulator/opentxsimulator.h b/companion/src/firmwares/opentx/simulator/opentxsimulator.h index 4faea6694..d93918839 100644 --- a/companion/src/firmwares/opentx/simulator/opentxsimulator.h +++ b/companion/src/firmwares/opentx/simulator/opentxsimulator.h @@ -77,13 +77,20 @@ namespace NAMESPACE { class DLLEXPORT OpenTxSimulator : public SimulatorInterface { + private: + int volumeGain; + public: OpenTxSimulator(); - virtual void start(QByteArray & eeprom, const Profile & profile, bool tests=true); + virtual void setSdPath(const QString &sdPath); - virtual void start(const char * filename, const Profile & profile, bool tests=true); + virtual void setVolumeGain(int value); + + virtual void start(QByteArray & eeprom, bool tests=true); + + virtual void start(const char * filename, bool tests=true); virtual void stop(); diff --git a/companion/src/simulation/simulatordialog.cpp b/companion/src/simulation/simulatordialog.cpp index ed60831a7..c3cdb28f9 100644 --- a/companion/src/simulation/simulatordialog.cpp +++ b/companion/src/simulation/simulatordialog.cpp @@ -447,6 +447,8 @@ void SimulatorDialog::initUi(T * ui) windowName = tr("Simulating Radio (%1)").arg(GetCurrentFirmware()->getName()); setWindowTitle(windowName); + simulator->setSdPath(g.profile[g.id()].sdPath()); + simulator->setVolumeGain(g.profile[g.id()].volumeGain()); lcd->setData(simulator->getLcd(), lcdWidth, 64, lcdDepth); if (flags & SIMULATOR_FLAGS_STICK_MODE_LEFT) { @@ -694,7 +696,7 @@ void SimulatorDialog::start(QByteArray & eeprom) lastPhase = -1; numGvars = GetCurrentFirmware()->getCapability(Gvars); numFlightModes = GetCurrentFirmware()->getCapability(FlightModes); - simulator->start(eeprom, g.profile[g.id()], (flags & SIMULATOR_FLAGS_NOTX) ? false : true); + simulator->start(eeprom, (flags & SIMULATOR_FLAGS_NOTX) ? false : true); getValues(); setupTimer(); } @@ -704,7 +706,7 @@ void SimulatorDialog::start(const char * filename) lastPhase = -1; numGvars = GetCurrentFirmware()->getCapability(Gvars); numFlightModes = GetCurrentFirmware()->getCapability(FlightModes); - simulator->start(filename, g.profile[g.id()]); + simulator->start(filename); getValues(); setupTimer(); } diff --git a/companion/src/simulation/simulatorinterface.h b/companion/src/simulation/simulatorinterface.h index 270ed776a..48c67a4be 100644 --- a/companion/src/simulation/simulatorinterface.h +++ b/companion/src/simulation/simulatorinterface.h @@ -23,7 +23,6 @@ #include #include #include -#include "appdata.h" #if __GNUC__ #define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) @@ -66,9 +65,13 @@ class SimulatorInterface virtual ~SimulatorInterface() {}; - virtual void start(QByteArray &eeprom, const Profile & profile, bool tests=true) = 0; + virtual void setSdPath(const QString &sdPath) { }; - virtual void start(const char *filename, const Profile & profile, bool tests=true) = 0; + virtual void setVolumeGain(int value) { }; + + virtual void start(QByteArray &eeprom, bool tests=true) = 0; + + virtual void start(const char *filename, bool tests=true) = 0; virtual void stop() = 0; diff --git a/companion/src/simulator.cpp b/companion/src/simulator.cpp index 2f5f55818..ddc610c16 100644 --- a/companion/src/simulator.cpp +++ b/companion/src/simulator.cpp @@ -110,7 +110,9 @@ int main(int argc, char *argv[]) #ifdef SIMU_AUDIO sdlFlags |= SDL_INIT_AUDIO; #endif - SDL_Init(sdlFlags); + if (SDL_Init(sdlFlags) < 0) { + fprintf(stderr, "ERROR: couldn't initialize SDL: %s\n", SDL_GetError()); + } #endif SimulatorDialog *dialog;