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.
22 #include "trainersimu.h"
23 #include "ui_trainersimu.h"
25 #include "virtualjoystickwidget.h"
27 #define TRAINERSIMU_HEARTBEAT_PERIOD 500 // [ms]
29 TrainerSimulator::TrainerSimulator(QWidget
* parent
, SimulatorInterface
* simulator
):
31 ui(new Ui::TrainerSimulator
),
37 vJoyLeft
= new VirtualJoystickWidget(this, 'L', false);
38 vJoyLeft
->setStickColor(Qt::cyan
);
39 vJoyLeft
->setStickScale(512);
40 ui
->leftStickLayout
->addWidget(vJoyLeft
);
42 vJoyRight
= new VirtualJoystickWidget(this, 'R', false);
43 vJoyRight
->setStickColor(Qt::cyan
);
44 vJoyRight
->setStickScale(512);
45 ui
->rightStickLayout
->addWidget(vJoyRight
);
47 connect(vJoyLeft
, &VirtualJoystickWidget::valueChange
, this, &TrainerSimulator::onRadioWidgetValueChange
);
48 connect(vJoyRight
, &VirtualJoystickWidget::valueChange
, this, &TrainerSimulator::onRadioWidgetValueChange
);
50 connect(this, &TrainerSimulator::trainerHeartbeat
, simulator
, &SimulatorInterface::setTrainerTimeout
);
51 connect(this, &TrainerSimulator::trainerChannelChange
, simulator
, &SimulatorInterface::setTrainerInput
);
52 connect(simulator
, &SimulatorInterface::started
, this, &TrainerSimulator::onSimulatorStarted
);
53 connect(simulator
, &SimulatorInterface::stopped
, this, &TrainerSimulator::onSimulatorStopped
);
55 timer
.setInterval(TRAINERSIMU_HEARTBEAT_PERIOD
- 10);
56 connect(&timer
, &QTimer::timeout
, this, &TrainerSimulator::emitHeartbeat
);
59 TrainerSimulator::~TrainerSimulator()
69 void TrainerSimulator::showEvent(QShowEvent
*event
)
74 void TrainerSimulator::hideEvent(QHideEvent
*event
)
79 void TrainerSimulator::start()
84 void TrainerSimulator::stop()
89 void TrainerSimulator::onSimulatorStarted()
94 void TrainerSimulator::onSimulatorStopped()
96 m_simuStarted
= false;
100 void TrainerSimulator::emitHeartbeat()
102 emit
trainerHeartbeat(TRAINERSIMU_HEARTBEAT_PERIOD
);
105 void TrainerSimulator::onRadioWidgetValueChange(RadioWidget::RadioWidgetType type
, int index
, int value
)
107 if (type
== RadioWidget::RADIO_WIDGET_STICK
&& m_simuStarted
&& timer
.isActive()) {
108 emit
trainerChannelChange(index
, value
);