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:
@@ -1,10 +1,16 @@
|
||||
set(simulation_SRCS
|
||||
simulatordialog.cpp
|
||||
telemetrysimu.cpp
|
||||
trainersimu.cpp
|
||||
debugoutput.cpp
|
||||
)
|
||||
|
||||
set(simulation_UIS
|
||||
simulatordialog-9x.ui
|
||||
simulatordialog-taranis.ui
|
||||
telemetrysimu.ui
|
||||
trainersimu.ui
|
||||
debugoutput.ui
|
||||
)
|
||||
|
||||
set(simulation_HDRS
|
||||
@@ -14,6 +20,9 @@ set(simulation_HDRS
|
||||
xcursorwidget.h
|
||||
xmenuwidget.h
|
||||
myslider.h
|
||||
telemetrysimu.h
|
||||
trainersimu.h
|
||||
debugoutput.h
|
||||
)
|
||||
|
||||
if(SDL_FOUND)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#include <QtGui>
|
||||
#include <stdint.h>
|
||||
#include "debugoutput.h"
|
||||
#include "ui_debugoutput.h"
|
||||
|
||||
DebugOutput::DebugOutput(QWidget * parent):
|
||||
QDialog(parent),
|
||||
ui(new Ui::DebugOutput)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
#ifdef __APPLE__
|
||||
QFont newFont("Courier", 13);
|
||||
ui->Output->setFont(newFont);
|
||||
ui->Output->setAttribute(Qt::WA_MacNormalSize);
|
||||
#endif
|
||||
#if defined WIN32 || !defined __GNUC__
|
||||
QFont newFont("Courier", 9);
|
||||
ui->Output->setFont(newFont);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
DebugOutput::~DebugOutput()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DebugOutput::traceCallback(const QString & text)
|
||||
{
|
||||
// ui->Output->appendPlainText(text);
|
||||
QTextCursor cursor(ui->Output->textCursor());
|
||||
|
||||
// is the scrollbar at the end?
|
||||
bool atEnd = (ui->Output->verticalScrollBar()->value() == ui->Output->verticalScrollBar()->maximum());
|
||||
|
||||
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor, 1);
|
||||
cursor.insertText(text);
|
||||
|
||||
if (atEnd) {
|
||||
ui->Output->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef debugoutput_h
|
||||
#define debugoutput_h
|
||||
|
||||
|
||||
#include <QDialog>
|
||||
#include "simulatorinterface.h"
|
||||
|
||||
namespace Ui {
|
||||
class DebugOutput;
|
||||
}
|
||||
|
||||
|
||||
class DebugOutput : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DebugOutput(QWidget * parent);
|
||||
virtual ~DebugOutput();
|
||||
void traceCallback(const QString & text);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
Ui::DebugOutput * ui;
|
||||
|
||||
private slots:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DebugOutput</class>
|
||||
<widget class="QDialog" name="DebugOutput">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>711</width>
|
||||
<height>470</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Debug Output</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../companion.qrc">
|
||||
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="Output">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOn</enum>
|
||||
</property>
|
||||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../companion.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -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()
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include <QDialog>
|
||||
#include "modeledit/node.h"
|
||||
#include "eeprominterface.h"
|
||||
#include "telemetrysimu.h"
|
||||
#include "trainersimu.h"
|
||||
#include "debugoutput.h"
|
||||
|
||||
#ifdef JOYSTICKS
|
||||
#include "joystick.h"
|
||||
@@ -38,6 +41,7 @@ class SimulatorDialog : public QDialog
|
||||
|
||||
void start(const char * filename);
|
||||
void start(QByteArray & eeprom);
|
||||
virtual void traceCallback(const char * text);
|
||||
|
||||
protected:
|
||||
template <class T> void initUi(T * ui);
|
||||
@@ -95,6 +99,14 @@ class SimulatorDialog : public QDialog
|
||||
|
||||
int lcdWidth;
|
||||
int lcdDepth;
|
||||
TelemetrySimulator * TelemetrySimu;
|
||||
TrainerSimulator * TrainerSimu;
|
||||
DebugOutput * DebugOut;
|
||||
|
||||
QString traceBuffer;
|
||||
QMutex traceMutex;
|
||||
QList<QString> traceList;
|
||||
void updateDebugOutput();
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *);
|
||||
@@ -125,6 +137,9 @@ class SimulatorDialog : public QDialog
|
||||
void onTimerEvent();
|
||||
void onTrimPressed();
|
||||
void onTrimReleased();
|
||||
void openTelemetrySimulator();
|
||||
void openTrainerSimulator();
|
||||
void openDebugOutput();
|
||||
|
||||
#ifdef JOYSTICKS
|
||||
void onjoystickAxisValueChanged(int axis, int value);
|
||||
|
||||
@@ -101,4 +101,9 @@ return lcd_buf;
|
||||
return main_thread_error;
|
||||
#endif
|
||||
|
||||
#ifdef SETTRAINER_IMPORT
|
||||
#undef SETTRAINER_IMPORT
|
||||
ppmInValid = 100;
|
||||
g_ppmIns[inputNumber] = LIMIT<int16_t>(-512, value, 512);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -80,6 +80,11 @@ class SimulatorInterface {
|
||||
|
||||
virtual const char * getError() = 0;
|
||||
|
||||
virtual void sendTelemetry(uint8_t * data, unsigned int len) = 0;
|
||||
|
||||
virtual void setTrainerInput(unsigned int inputNumber, int16_t value) = 0;
|
||||
|
||||
virtual void installTraceHook(void (*callback)(const char *)) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#include <stdint.h>
|
||||
#include "telemetrysimu.h"
|
||||
#include "ui_telemetrysimu.h"
|
||||
#include "radio/src/telemetry/frsky.h"
|
||||
|
||||
TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator):
|
||||
QDialog(parent),
|
||||
ui(new Ui::TelemetrySimulator),
|
||||
simulator(simulator)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent()));
|
||||
timer->start(100);
|
||||
}
|
||||
|
||||
TelemetrySimulator::~TelemetrySimulator()
|
||||
{
|
||||
timer->stop();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TelemetrySimulator::onTimerEvent()
|
||||
{
|
||||
if (ui->Simulate->isChecked()) {
|
||||
generateTelemetryFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void setSportPacketCrc(uint8_t * packet)
|
||||
{
|
||||
short crc = 0;
|
||||
for (int i=1; i<FRSKY_SPORT_PACKET_SIZE-1; i++) {
|
||||
crc += packet[i]; //0-1FF
|
||||
crc += crc >> 8; //0-100
|
||||
crc &= 0x00ff;
|
||||
crc += crc >> 8; //0-0FF
|
||||
crc &= 0x00ff;
|
||||
}
|
||||
packet[FRSKY_SPORT_PACKET_SIZE-1] = 0xFF - (crc & 0x00ff);
|
||||
//TRACE("crc set: %x", packet[FRSKY_SPORT_PACKET_SIZE-1]);
|
||||
}
|
||||
|
||||
void generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data)
|
||||
{
|
||||
packet[0] = dataId;
|
||||
packet[1] = prim;
|
||||
*((uint16_t *)(packet+2)) = appId;
|
||||
*((int32_t *)(packet+4)) = data;
|
||||
setSportPacketCrc(packet);
|
||||
}
|
||||
|
||||
void TelemetrySimulator::generateTelemetryFrame()
|
||||
{
|
||||
static int item = 0;
|
||||
uint8_t buffer[FRSKY_SPORT_PACKET_SIZE];
|
||||
|
||||
switch(item++) {
|
||||
case 0:
|
||||
generateSportPacket(buffer, 1, DATA_FRAME, RSSI_ID, LIMIT<uint32_t>(0, ui->Rssi->text().toInt(), 0xFF));
|
||||
break;
|
||||
|
||||
case 1:
|
||||
generateSportPacket(buffer, 1, DATA_FRAME, XJT_VERSION_ID, 11);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
generateSportPacket(buffer, 1, DATA_FRAME, SWR_ID, LIMIT<uint32_t>(0, ui->Swr->text().toInt(), 0xFF));
|
||||
break;
|
||||
|
||||
case 3:
|
||||
generateSportPacket(buffer, 1, DATA_FRAME, ADC1_ID, LIMIT<uint32_t>(0, ui->A1->text().toInt(), 0xFF));
|
||||
break;
|
||||
|
||||
case 4:
|
||||
generateSportPacket(buffer, 1, DATA_FRAME, ADC2_ID, LIMIT<uint32_t>(0, ui->A2->text().toInt(), 0xFF));
|
||||
break;
|
||||
|
||||
default:
|
||||
item = 0;
|
||||
return;
|
||||
}
|
||||
simulator->sendTelemetry(buffer, 9);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef telemetrysimu_h
|
||||
#define telemetrysimu_h
|
||||
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
#include "simulatorinterface.h"
|
||||
|
||||
namespace Ui {
|
||||
class TelemetrySimulator;
|
||||
}
|
||||
|
||||
|
||||
class TelemetrySimulator : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator);
|
||||
virtual ~TelemetrySimulator();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
Ui::TelemetrySimulator * ui;
|
||||
QTimer * timer;
|
||||
SimulatorInterface *simulator;
|
||||
|
||||
void generateTelemetryFrame();
|
||||
|
||||
private slots:
|
||||
void onTimerEvent();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TelemetrySimulator</class>
|
||||
<widget class="QDialog" name="TelemetrySimulator">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>184</width>
|
||||
<height>165</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Telemetry Simulator</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="3" column="3">
|
||||
<widget class="QLineEdit" name="Swr"/>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QLineEdit" name="A1"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>RSSI</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="Rssi"/>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>A1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>SWR</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QCheckBox" name="Simulate">
|
||||
<property name="text">
|
||||
<string>simulate</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>A2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="3">
|
||||
<widget class="QLineEdit" name="A2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,113 @@
|
||||
#include <stdint.h>
|
||||
#include "trainersimu.h"
|
||||
#include "ui_trainersimu.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#define GBALL_SIZE 20
|
||||
#define RESX 512
|
||||
|
||||
TrainerSimulator::TrainerSimulator(QWidget * parent, SimulatorInterface * simulator):
|
||||
QDialog(parent),
|
||||
ui(new Ui::TrainerSimulator),
|
||||
simulator(simulator)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
leftStick = ui->leftStick;
|
||||
rightStick = ui->rightStick;
|
||||
|
||||
setupSticks();
|
||||
|
||||
// resize(0, 0); // to force min height, min width
|
||||
setFixedSize(width(), height());
|
||||
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent()));
|
||||
timer->start(10);
|
||||
}
|
||||
|
||||
TrainerSimulator::~TrainerSimulator()
|
||||
{
|
||||
timer->stop();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TrainerSimulator::centerSticks()
|
||||
{
|
||||
if (leftStick->scene())
|
||||
nodeLeft->stepToCenter();
|
||||
|
||||
if (rightStick->scene())
|
||||
nodeRight->stepToCenter();
|
||||
}
|
||||
|
||||
void TrainerSimulator::setupSticks()
|
||||
{
|
||||
QGraphicsScene *leftScene = new QGraphicsScene(leftStick);
|
||||
leftScene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
leftStick->setScene(leftScene);
|
||||
|
||||
// leftStick->scene()->addLine(0,10,20,30);
|
||||
|
||||
QGraphicsScene *rightScene = new QGraphicsScene(rightStick);
|
||||
rightScene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
rightStick->setScene(rightScene);
|
||||
|
||||
// rightStick->scene()->addLine(0,10,20,30);
|
||||
|
||||
nodeLeft = new Node();
|
||||
nodeLeft->setPos(-GBALL_SIZE/2,-GBALL_SIZE/2);
|
||||
nodeLeft->setBallSize(GBALL_SIZE);
|
||||
leftScene->addItem(nodeLeft);
|
||||
|
||||
nodeRight = new Node();
|
||||
nodeRight->setPos(-GBALL_SIZE/2,-GBALL_SIZE/2);
|
||||
nodeRight->setBallSize(GBALL_SIZE);
|
||||
rightScene->addItem(nodeRight);
|
||||
}
|
||||
|
||||
void TrainerSimulator::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (leftStick->scene()) {
|
||||
QRect qr = leftStick->contentsRect();
|
||||
qreal w = (qreal)qr.width() - GBALL_SIZE;
|
||||
qreal h = (qreal)qr.height() - GBALL_SIZE;
|
||||
qreal cx = (qreal)qr.width()/2;
|
||||
qreal cy = (qreal)qr.height()/2;
|
||||
leftStick->scene()->setSceneRect(-cx,-cy,w,h);
|
||||
|
||||
QPointF p = nodeLeft->pos();
|
||||
p.setX(qMin(cx, qMax(p.x(), -cx)));
|
||||
p.setY(qMin(cy, qMax(p.y(), -cy)));
|
||||
nodeLeft->setPos(p);
|
||||
}
|
||||
|
||||
if (rightStick->scene()) {
|
||||
QRect qr = rightStick->contentsRect();
|
||||
qreal w = (qreal)qr.width() - GBALL_SIZE;
|
||||
qreal h = (qreal)qr.height() - GBALL_SIZE;
|
||||
qreal cx = (qreal)qr.width()/2;
|
||||
qreal cy = (qreal)qr.height()/2;
|
||||
rightStick->scene()->setSceneRect(-cx,-cy,w,h);
|
||||
|
||||
QPointF p = nodeRight->pos();
|
||||
p.setX(qMin(cx, qMax(p.x(), -cx)));
|
||||
p.setY(qMin(cy, qMax(p.y(), -cy)));
|
||||
nodeRight->setPos(p);
|
||||
}
|
||||
QDialog::resizeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void TrainerSimulator::onTimerEvent()
|
||||
{
|
||||
centerSticks();
|
||||
setTrainerInputs();
|
||||
}
|
||||
|
||||
void TrainerSimulator::setTrainerInputs()
|
||||
{
|
||||
simulator->setTrainerInput(0, int( 512* nodeLeft->getX())); // LEFT HORZ
|
||||
simulator->setTrainerInput(1, int(-512* nodeLeft->getY())); // LEFT VERT
|
||||
simulator->setTrainerInput(2, int(-512*nodeRight->getY())); // RGHT VERT
|
||||
simulator->setTrainerInput(3, int( 512*nodeRight->getX())); // RGHT HORZ
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef trainersimu_h
|
||||
#define trainersimu_h
|
||||
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
#include "modeledit/node.h"
|
||||
#include "simulatorinterface.h"
|
||||
|
||||
namespace Ui {
|
||||
class TrainerSimulator;
|
||||
}
|
||||
|
||||
|
||||
class TrainerSimulator : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TrainerSimulator(QWidget * parent, SimulatorInterface * simulator);
|
||||
virtual ~TrainerSimulator();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
Ui::TrainerSimulator * ui;
|
||||
QTimer * timer;
|
||||
SimulatorInterface *simulator;
|
||||
|
||||
QGraphicsView * leftStick, * rightStick;
|
||||
Node *nodeLeft;
|
||||
Node *nodeRight;
|
||||
|
||||
void centerSticks();
|
||||
void setupSticks();
|
||||
void resizeEvent(QResizeEvent *event = 0);
|
||||
void setTrainerInputs();
|
||||
|
||||
private slots:
|
||||
void onTimerEvent();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TrainerSimulator</class>
|
||||
<widget class="QDialog" name="TrainerSimulator">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>566</width>
|
||||
<height>268</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Trainer simulator</string>
|
||||
</property>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>563</width>
|
||||
<height>267</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="margin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Minimum</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>17</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QGraphicsView" name="rightStick">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>245</width>
|
||||
<height>245</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QGraphicsView" name="leftStick">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>245</width>
|
||||
<height>245</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user