187 lines
5.7 KiB
C++
187 lines
5.7 KiB
C++
/*
|
|
* Copyright (C) OpenTX
|
|
*
|
|
* Based on code named
|
|
* th9x - http://code.google.com/p/th9x
|
|
* er9x - http://code.google.com/p/er9x
|
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
|
*
|
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include "simulatordialog.h"
|
|
#include "ui_simulatordialog-flamenco.h"
|
|
#include "helpers.h"
|
|
|
|
uint32_t SimulatorDialogFlamenco::switchstatus = 0;
|
|
|
|
SimulatorDialogFlamenco::SimulatorDialogFlamenco(QWidget * parent, SimulatorInterface *simulator, unsigned int flags):
|
|
SimulatorDialog(parent, simulator, flags),
|
|
ui(new Ui::SimulatorDialogFlamenco)
|
|
{
|
|
lcdWidth = 320;
|
|
lcdHeight = 240;
|
|
lcdDepth = 12;
|
|
|
|
initUi<Ui::SimulatorDialogFlamenco>(ui);
|
|
|
|
// install simulator TRACE hook
|
|
simulator->installTraceHook(traceCb);
|
|
|
|
// TODO dialP_4 = ui->dialP_4;
|
|
|
|
ui->lcd->setBackgroundColor(47, 123, 227);
|
|
|
|
//restore switches
|
|
if (g.simuSW())
|
|
restoreSwitches();
|
|
|
|
ui->trimHR_L->setText(QString::fromUtf8(ARROW_LEFT));
|
|
ui->trimHR_R->setText(QString::fromUtf8(ARROW_RIGHT));
|
|
ui->trimVR_U->setText(QString::fromUtf8(ARROW_UP));
|
|
ui->trimVR_D->setText(QString::fromUtf8(ARROW_DOWN));
|
|
ui->trimHL_L->setText(QString::fromUtf8(ARROW_LEFT));
|
|
ui->trimHL_R->setText(QString::fromUtf8(ARROW_RIGHT));
|
|
ui->trimVL_U->setText(QString::fromUtf8(ARROW_UP));
|
|
ui->trimVL_D->setText(QString::fromUtf8(ARROW_DOWN));
|
|
|
|
connect(ui->leftbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int)));
|
|
connect(ui->rightbuttons, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int)));
|
|
connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
|
|
connect(ui->trimHR_R, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
|
|
connect(ui->trimVR_U, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
|
|
connect(ui->trimVR_D, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
|
|
connect(ui->trimHL_R, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
|
|
connect(ui->trimHL_L, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
|
|
connect(ui->trimVL_U, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
|
|
connect(ui->trimVL_D, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
|
|
connect(ui->trimHR_L, SIGNAL(released()), this, SLOT(onTrimReleased()));
|
|
connect(ui->trimHR_R, SIGNAL(released()), this, SLOT(onTrimReleased()));
|
|
connect(ui->trimVR_U, SIGNAL(released()), this, SLOT(onTrimReleased()));
|
|
connect(ui->trimVR_D, SIGNAL(released()), this, SLOT(onTrimReleased()));
|
|
connect(ui->trimHL_R, SIGNAL(released()), this, SLOT(onTrimReleased()));
|
|
connect(ui->trimHL_L, SIGNAL(released()), this, SLOT(onTrimReleased()));
|
|
connect(ui->trimVL_U, SIGNAL(released()), this, SLOT(onTrimReleased()));
|
|
connect(ui->trimVL_D, SIGNAL(released()), this, SLOT(onTrimReleased()));
|
|
}
|
|
|
|
SimulatorDialogFlamenco::~SimulatorDialogFlamenco()
|
|
{
|
|
saveSwitches();
|
|
delete ui;
|
|
}
|
|
|
|
void SimulatorDialogFlamenco::resetSH()
|
|
{
|
|
ui->switchH->setValue(0);
|
|
}
|
|
|
|
void SimulatorDialogFlamenco::on_switchH_sliderReleased()
|
|
{
|
|
QTimer::singleShot(400, this, SLOT(resetSH()));
|
|
}
|
|
|
|
void SimulatorDialogFlamenco::getValues()
|
|
{
|
|
TxInputs inputs = {
|
|
{
|
|
int(1024*nodeLeft->getX()), // LEFT HORZ
|
|
int(-1024*nodeLeft->getY()), // LEFT VERT
|
|
int(-1024*nodeRight->getY()), // RGHT VERT
|
|
int(1024*nodeRight->getX()) // RGHT HORZ
|
|
},
|
|
|
|
{
|
|
-ui->dialP_1->value(),
|
|
ui->dialP_2->value(),
|
|
0,
|
|
-ui->dialP_3->value(),
|
|
ui->dialP_4->value()
|
|
},
|
|
|
|
{
|
|
ui->switchA->value() - 1,
|
|
ui->switchB->value() - 1,
|
|
ui->switchC->value() - 1,
|
|
ui->switchD->value() - 1,
|
|
ui->switchE->value() - 1,
|
|
ui->switchF->value(),
|
|
ui->switchG->value() - 1,
|
|
ui->switchH->value(), 0, 0
|
|
},
|
|
|
|
{
|
|
buttonPressed == Qt::Key_PageUp,
|
|
buttonPressed == Qt::Key_Escape,
|
|
buttonPressed == Qt::Key_Enter,
|
|
buttonPressed == Qt::Key_PageDown,
|
|
buttonPressed == Qt::Key_Plus,
|
|
buttonPressed == Qt::Key_Minus
|
|
},
|
|
|
|
middleButtonPressed,
|
|
|
|
{
|
|
trimPressed == TRIM_LH_L,
|
|
trimPressed == TRIM_LH_R,
|
|
trimPressed == TRIM_LV_DN,
|
|
trimPressed == TRIM_LV_UP,
|
|
trimPressed == TRIM_RV_DN,
|
|
trimPressed == TRIM_RV_UP,
|
|
trimPressed == TRIM_RH_L,
|
|
trimPressed == TRIM_RH_R
|
|
}
|
|
};
|
|
|
|
simulator->setValues(inputs);
|
|
}
|
|
|
|
void SimulatorDialogFlamenco::saveSwitches(void)
|
|
{
|
|
// qDebug() << "SimulatorDialogTaranis::saveSwitches()";
|
|
switchstatus=ui->switchA->value();
|
|
switchstatus<<=2;
|
|
switchstatus+=ui->switchB->value();
|
|
switchstatus<<=2;
|
|
switchstatus+=ui->switchC->value();
|
|
switchstatus<<=2;
|
|
switchstatus+=ui->switchD->value();
|
|
switchstatus<<=2;
|
|
switchstatus+=ui->switchE->value();
|
|
switchstatus<<=2;
|
|
switchstatus+=ui->switchF->value();
|
|
switchstatus<<=2;
|
|
switchstatus+=ui->switchG->value();
|
|
switchstatus<<=2;
|
|
switchstatus+=ui->switchH->value();
|
|
}
|
|
|
|
void SimulatorDialogFlamenco::restoreSwitches(void)
|
|
{
|
|
// qDebug() << "SimulatorDialogTaranis::restoreSwitches()";
|
|
ui->switchH->setValue(switchstatus & 0x3);
|
|
switchstatus>>=2;
|
|
ui->switchG->setValue(switchstatus & 0x3);
|
|
switchstatus>>=2;
|
|
ui->switchF->setValue(switchstatus & 0x3);
|
|
switchstatus>>=2;
|
|
ui->switchE->setValue(switchstatus & 0x3);
|
|
switchstatus>>=2;
|
|
ui->switchD->setValue(switchstatus & 0x3);
|
|
switchstatus>>=2;
|
|
ui->switchC->setValue(switchstatus & 0x3);
|
|
switchstatus>>=2;
|
|
ui->switchB->setValue(switchstatus & 0x3);
|
|
switchstatus>>=2;
|
|
ui->switchA->setValue(switchstatus & 0x3);
|
|
}
|