[Simulator] Further Simulator improvements. (#4282)

* Refactor CompStoreObj to use templates. Clean up some formatting.

* [Simulator] Add SimulatorOptions type to replace individual simulator options; Fix storage handler for custom types; Cleanup some redundant code.

* [Simulator][Joystick] Rework the joystick options/calibration dialog.  Can now enable/disable/select the Joystick from there. Delay start of calibration until Start is pressed (otherwise looks like last calibration didn't work). And generally refactor a lot of it to be smarter.

* Cosmetics.

* [Simulator] Add state handling for RadioWidget class. Split code to cpp file.

* [Simulator] Add SimulatorStartupDialog as its own UI class.

* [Simulator] Multiple changes and new features:
    All Horus data source options are now fully supported with data properly saved after use (SD path, .otx file, or custom data path);
    Loading .otx files now works for all radio types (but not saving data back to .otx);
    Switch and knob/slider states are now saved to per radio profile;
    Joystick configuration/calibration is now available directly from inside Simulator;
    Due to refactoring, all previously saved per-profile simulator settings are now invalid;
    Further consolidated simulator dialog startup/shutdown, now handles temp. paths internally, etc;
    With WIN_USE_CONSOLE defined, Simulator and Companion when started from Windows command line will now use that console for all messages (instead of opening a new one). This allows full debug output to be seen at all stages of execution and after exit.

* [Simulator] Fix build w/out SDL Joystick support.

* [Simulator] Fix bogus throttle warning on simulator start; Add forgotten RadioWidgetState flags to stream handlers; Add debug state saver in SimulatorOptions.
This commit is contained in:
Max Paperno
2017-01-25 16:20:45 +01:00
committed by Bertrand Songis
parent b53ec7392c
commit 6e2474081f
22 changed files with 2869 additions and 1785 deletions
+18 -27
View File
@@ -816,18 +816,17 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
SimulatorInterface * simulator = getCurrentSimulator();
if (simulator) {
#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO)
AllocConsole();
SetConsoleTitle("Companion Console");
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
bool freeConsoleOnClose = false;
if (!GetConsoleWindow()) {
AllocConsole();
SetConsoleTitle("Companion Console");
freeConsoleOnClose = true;
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);
}
#endif
Firmware * firmware = getCurrentFirmware();
RadioData * simuData = new RadioData(radioData);
Board::Type board = getCurrentBoard();
QByteArray eeprom = QByteArray();
QString sdPath = g.profile[g.id()].sdPath();
QString settingsPath = "";
unsigned int flags = 0;
if (modelIdx >= 0) {
@@ -835,29 +834,21 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
simuData->setCurrentModel(modelIdx);
}
if (IS_HORUS(board)) {
QTemporaryDir tmpDir(QDir::tempPath() + "/otx-XXXXXX");
settingsPath = tmpDir.path();
tmpDir.setAutoRemove(false);
}
qDebug() << "Starting" << firmware->getName() << "simulation with SD path" << sdPath << "and models/settings path" << settingsPath;
SimulatorDialog * dialog = new SimulatorDialog(parent, simulator, flags);
dialog->setPaths(sdPath, settingsPath);
if (IS_HORUS(getCurrentBoard()) && !dialog->useTempDataPath(true)) {
QMessageBox::critical(NULL, QObject::tr("Data Load Error"), QObject::tr("Error: Could not create temporary directory in '%1'").arg(QDir::tempPath()));
return;
}
dialog->setRadioData(simuData);
qDebug() << __FILE__ << __LINE__ << "Starting" << getCurrentFirmware()->getName() << "simulation with SD path" << dialog->getSdPath() << "and models/settings path" << dialog->getDataPath();
dialog->start();
dialog->exec();
dialog->deleteLater();
if (!settingsPath.isEmpty()) {
// TODO either delete tmp directory and its contents OR use it to get back data from the simulation
qDebug() << "Simulation finished, deleting temporary settings directory" << settingsPath;
QDir tmp(settingsPath);
tmp.removeRecursively();
}
delete simuData;
// TODO Horus tmp directory is deleted on simulator close OR we could use it to get back data from the simulation
delete simuData; // TODO same with simuData, could read it back and update the file data
#if defined(WIN32) && defined(WIN_USE_CONSOLE_STDIO)
FreeConsole();
if (freeConsoleOnClose)
FreeConsole();
#endif
}
else {