1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-26 09:45:16 +03:00

Ported from master to next:

#1489: TRACE() output intercepted and shown in Companion (shortcut F6)
#1270: simple Trainer Simulator (shortcut F5)
#1466: telemetry simulator (shorcut F5)
This commit is contained in:
Damjan Adamic 2015-01-04 18:57:45 +01:00
parent a2dc0040b0
commit bb921a0a7f
39 changed files with 865 additions and 96 deletions

View file

@ -9,6 +9,42 @@
#define RESX 1024
int SimulatorDialog::screenshotIdx = 0;
SimulatorDialog * traceCallbackInstance = 0;
void traceCb(const char * text) {
// divert C callback into simulator instance
if (traceCallbackInstance) {
traceCallbackInstance->traceCallback(text);
}
}
void SimulatorDialog::traceCallback(const char * text)
{
// this function is called from other threads
traceMutex.lock();
// limit the size of list
if (traceList.size() < 1000) {
traceList.append(QString(text));
}
traceMutex.unlock();
}
void SimulatorDialog::updateDebugOutput()
{
traceMutex.lock();
while (!traceList.isEmpty()) {
QString text = traceList.takeFirst();
traceBuffer.append(text);
// limit the size of traceBuffer
if (traceBuffer.size() > 10*1024) {
traceBuffer.remove(0, 1*1024);
}
if (DebugOut) {
DebugOut->traceCallback(QString(text));
}
}
traceMutex.unlock();
}
SimulatorDialog::SimulatorDialog(QWidget * parent, unsigned int flags):
QDialog(parent),
@ -19,10 +55,19 @@ SimulatorDialog::SimulatorDialog(QWidget * parent, unsigned int flags):
simulator(NULL),
lastPhase(-1),
beepVal(0),
TelemetrySimu(0),
TrainerSimu(0),
DebugOut(0),
buttonPressed(0),
trimPressed (TRIM_NONE),
middleButtonPressed(false)
{
//shorcut for telemetry simulator
// new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_T), this, SLOT(openTelemetrySimulator()));
new QShortcut(QKeySequence(Qt::Key_F4), this, SLOT(openTelemetrySimulator()));
new QShortcut(QKeySequence(Qt::Key_F5), this, SLOT(openTrainerSimulator()));
new QShortcut(QKeySequence(Qt::Key_F6), this, SLOT(openDebugOutput()));
traceCallbackInstance = this;
}
uint32_t SimulatorDialog9X::switchstatus = 0;
@ -37,6 +82,9 @@ SimulatorDialog9X::SimulatorDialog9X(QWidget * parent, unsigned int flags):
initUi<Ui::SimulatorDialog9X>(ui);
// install simulator TRACE hook
simulator->installTraceHook(traceCb);
backLight = g.backLight();
if (backLight > 4) backLight = 0;
switch (backLight) {
@ -109,6 +157,10 @@ SimulatorDialogTaranis::SimulatorDialogTaranis(QWidget * parent, unsigned int fl
lcdDepth = 4;
initUi<Ui::SimulatorDialogTaranis>(ui);
// install simulator TRACE hook
simulator->installTraceHook(traceCb);
dialP_4 = ui->dialP_4;
ui->lcd->setBackgroundColor(47, 123, 227);
@ -154,6 +206,7 @@ SimulatorDialogTaranis::~SimulatorDialogTaranis()
SimulatorDialog::~SimulatorDialog()
{
traceCallbackInstance = 0;
delete timer;
delete simulator;
}
@ -215,6 +268,28 @@ void SimulatorDialog::onTrimReleased()
trimPressed = TRIM_NONE;
}
void SimulatorDialog::openTelemetrySimulator()
{
TelemetrySimu = new TelemetrySimulator(this, simulator);
TelemetrySimu->setAttribute(Qt::WA_DeleteOnClose, true);
TelemetrySimu->show();
}
void SimulatorDialog::openTrainerSimulator()
{
TrainerSimu = new TrainerSimulator(this, simulator);
TrainerSimu->setAttribute(Qt::WA_DeleteOnClose, true);
TrainerSimu->show();
}
void SimulatorDialog::openDebugOutput()
{
DebugOut = new DebugOutput(this);
DebugOut->setAttribute(Qt::WA_DeleteOnClose, true);
DebugOut->traceCallback(traceBuffer);
DebugOut->show();
}
void SimulatorDialog::keyPressEvent (QKeyEvent *event)
{
switch (event->key()) {
@ -559,6 +634,8 @@ void SimulatorDialog::onTimerEvent()
QApplication::beep();
}
}
updateDebugOutput();
}
void SimulatorDialog::centerSticks()