[Simulator] Asynchronous SimulatorInterface & a few new features. (#4738)
* [Simulator] Create RadioKeyWidget class for UI buttons & refactor ButtonsWidget; Refactor SimulatedUIWidget (and subtypes) to use new RadioKeyWidgets/ButtonsWidget; Centralize help text for key mappings and get creative with some icons; Simplify some radio UI setups with rectangular buttons.
* [Simulator] Convert all simulator data I/O to signals/slots mechanism:
* SimulatorInterface/OpenTxSimulator:
- Now inherits from QObject to allow signal/slot interface;
- Allows data exchange on a per-item basis (eg. each I/O value is treated separately instead of sending whole arrays or structs of data);
- Checks for data changes and only emits signals when change is detected (GUI can now assume only new values are being sent);
- Manages its own 10ms timer (doesn't rely on GUI to do that);
- Sends "heartbeat" signals @ 1Hz for status monitoring;
* Simulator GUI:
- All data is exchanged between GUI elements as well as SimulatorInterface via signals/slots using standardized methods;
- Data is sent immediately, and only, when actually changed (eg. a control is moved) instead of in bulk at specific time intervals;
- Similarly, an asynchronous method is used for reading incoming data, w/out timers or loops;
- Improve VirtualJoystickWidget to be more encapsulated and configurable;
- Pause telemetry simulator if window is hidden;
* [Simulator] Move SimulatorInterface instance to separate thread, ensure safe asynchronous operations & proper timer interactions; Protect/remove some functions, & reorganize the order (cosmetics).
* [Simulator] Traces are now delivered to OpenTxSimulator and one or more QIODevice(s) can be added as recipient(s); Add SimulatorInterface::getCapability() for compile-time settings; Remove reversed POT1/SLIDER1 mixer exception (Taranis) requirement for SIMU; Fix plus/minus key delay on wheel event w/out encoder.
* [Simulator] Add current knob/slider/trim input value in tool-tips (KnobWidget and SliderWidget).
* [Simulator] Fix trims widget internal value not properly updating, and remove trim influence on virtual joystick X/Y value display (closes #4671).
* [SimulatorInterface] Add handling of transmitter input voltage, including a rough conversion of volts to ADC value for different boards, and default battery volts lookup function; Clear analogs array before starting.
* [Simulator] Add SimulatorInterface::init() method to separate pre-startup tasks; Report actual trim range, not just extended on/off; Change how radio widget states are restored; VirtualJoystickWidget: Connect trim changes directly from simulator, connect joystick events directly, report stick mode directly instead of setting values/constraints externally.
* [Simulator] Calculate default Tx V input based on configured range in radio settings (or warning V+2 for radios which don't support a range).
* [Simulator] Add functional aux. trims for Horus (closes #4699).
* [Companion] Remove problematic QMessageLogContext from AppDebugMessageHandler::messageOutput().
* [Simulator] Prevent trim change via slider if disabled for flight mode (closes #4600).
* [OpenTxSimulator] Fixes for Qt < 5.4.
* [OpenTxSimulator] Fix slot name.
This commit is contained in:
committed by
Bertrand Songis
parent
36bb951314
commit
57dc0159d6
@@ -21,11 +21,11 @@
|
||||
#define GBALL_SIZE 25
|
||||
#define GBALL_SIZE_MN 20
|
||||
#define GBALL_SIZE_MX 35
|
||||
#define CENTER_INTERVAL 50 // ms
|
||||
|
||||
#include "virtualjoystickwidget.h"
|
||||
|
||||
#include "boards.h"
|
||||
#include "constants.h"
|
||||
#include "modeledit/node.h"
|
||||
#include "helpers.h"
|
||||
#include "radiotrimwidget.h"
|
||||
@@ -43,6 +43,7 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
|
||||
btnFixY(NULL),
|
||||
nodeLabelX(NULL),
|
||||
nodeLabelY(NULL),
|
||||
m_stickScale(1024),
|
||||
m_stickPressed(false)
|
||||
{
|
||||
ar = (float)size.width() / size.height();
|
||||
@@ -135,12 +136,18 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
|
||||
layout->addItem(new QSpacerItem(0, 0), 1, 4, 2, 1); // r1-2 c4: right h spacer
|
||||
layout->addItem(new QSpacerItem(0, 0), 3, 0, 1, 5); // r4 c0-4: bot v spacer
|
||||
|
||||
connect(node, &Node::xChanged, this, &VirtualJoystickWidget::updateNodeValueLabels);
|
||||
connect(node, &Node::yChanged, this, &VirtualJoystickWidget::updateNodeValueLabels);
|
||||
setStickIndices(getStickIndex('H'), getStickIndex('V'));
|
||||
|
||||
connect(node, &Node::xChanged, this, &VirtualJoystickWidget::onNodeXChanged);
|
||||
connect(node, &Node::yChanged, this, &VirtualJoystickWidget::onNodeYChanged);
|
||||
|
||||
connect(scene, &CustomGraphicsScene::mouseEvent, this, &VirtualJoystickWidget::onGsMouseEvent);
|
||||
|
||||
setSize(prefSize, frameSize());
|
||||
|
||||
centerStickTimer.setInterval(CENTER_INTERVAL);
|
||||
connect(¢erStickTimer, &QTimer::timeout, this, &VirtualJoystickWidget::centerStick);
|
||||
centerStickTimer.start();
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setStickX(qreal x)
|
||||
@@ -158,6 +165,31 @@ void VirtualJoystickWidget::setStickPos(QPointF xy)
|
||||
node->setPos(xy);
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setStickAxisValue(int index, int value)
|
||||
{
|
||||
using namespace Board;
|
||||
qreal rvalue = value / 1024.0f;
|
||||
|
||||
switch (index) {
|
||||
case STICK_AXIS_LH :
|
||||
if (stickSide == 'L')
|
||||
setStickX(rvalue);
|
||||
break;
|
||||
case STICK_AXIS_RH :
|
||||
if (stickSide == 'R')
|
||||
setStickX(rvalue);
|
||||
break;
|
||||
case STICK_AXIS_LV :
|
||||
if (stickSide == 'L')
|
||||
setStickY(rvalue);
|
||||
break;
|
||||
case STICK_AXIS_RV :
|
||||
if (stickSide == 'R')
|
||||
setStickY(rvalue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::centerStick()
|
||||
{
|
||||
node->stepToCenter();
|
||||
@@ -178,20 +210,55 @@ QPointF VirtualJoystickWidget::getStickPos()
|
||||
return QPointF(node->getX(), node->getY());
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setTrimValue(int which, int value)
|
||||
void VirtualJoystickWidget::setTrimsRange(int min, int max)
|
||||
{
|
||||
RadioTrimWidget * trim = getTrimWidget(which);
|
||||
if (hTrimWidget)
|
||||
hTrimWidget->setTrimRange(min, max);
|
||||
if (vTrimWidget)
|
||||
vTrimWidget->setTrimRange(min, max);
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setTrimsRange(int rng)
|
||||
{
|
||||
setTrimsRange(-rng, rng);
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setTrimRange(int index, int min, int max)
|
||||
{
|
||||
if (index == Board::TRIM_AXIS_COUNT) {
|
||||
setTrimsRange(min, max);
|
||||
return;
|
||||
}
|
||||
RadioTrimWidget * trim = getTrimWidget(index);
|
||||
if (trim) {
|
||||
trim->setTrimRange(min, max);
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setTrimValue(int index, int value)
|
||||
{
|
||||
RadioTrimWidget * trim = getTrimWidget(index);
|
||||
if (trim) {
|
||||
trim->setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setTrimRange(int which, int min, int max)
|
||||
int VirtualJoystickWidget::getStickScale() const
|
||||
{
|
||||
RadioTrimWidget * trim = getTrimWidget(which);
|
||||
if (trim) {
|
||||
trim->setTrimRange(min, max);
|
||||
}
|
||||
return m_stickScale;
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setStickScale(int stickScale)
|
||||
{
|
||||
m_stickScale = stickScale;
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setWidgetValue(const RadioWidget::RadioWidgetType type, const int index, const int value)
|
||||
{
|
||||
if (type == RadioWidget::RADIO_WIDGET_TRIM)
|
||||
setTrimValue(index, value);
|
||||
else if (type == RadioWidget::RADIO_WIDGET_STICK)
|
||||
setStickAxisValue(index, value);
|
||||
}
|
||||
|
||||
int VirtualJoystickWidget::getTrimValue(int which)
|
||||
@@ -203,27 +270,25 @@ int VirtualJoystickWidget::getTrimValue(int which)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setStickConstraint(int which, bool active)
|
||||
void VirtualJoystickWidget::setStickIndices(int xIdx, int yIdx)
|
||||
{
|
||||
if (btnHoldX == NULL)
|
||||
m_xIndex = xIdx;
|
||||
m_yIndex = yIdx;
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setStickConstraint(quint8 index, bool active)
|
||||
{
|
||||
if (btnHoldX == NULL || !index)
|
||||
return; // no buttons
|
||||
|
||||
switch (which) {
|
||||
case HOLD_X:
|
||||
btnHoldX->setChecked(active);
|
||||
break;
|
||||
case HOLD_Y:
|
||||
btnHoldY->setChecked(active);
|
||||
break;
|
||||
case FIX_X:
|
||||
btnFixX->setChecked(active);
|
||||
break;
|
||||
case FIX_Y:
|
||||
btnFixY->setChecked(active);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (index & HOLD_X)
|
||||
btnHoldX->setChecked(active);
|
||||
if (index & HOLD_Y)
|
||||
btnHoldY->setChecked(active);
|
||||
if (index & FIX_X)
|
||||
btnFixX->setChecked(active);
|
||||
if (index & FIX_Y)
|
||||
btnFixY->setChecked(active);
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setStickColor(const QColor & color)
|
||||
@@ -231,6 +296,15 @@ void VirtualJoystickWidget::setStickColor(const QColor & color)
|
||||
node->setColor(color);
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::loadDefaultsForMode(const unsigned mode)
|
||||
{
|
||||
if (((mode & 1) && stickSide == 'L') || (!(mode & 1) && stickSide == 'R')) {
|
||||
setStickConstraint(HOLD_Y, true);
|
||||
setStickY(1.0);
|
||||
onNodeYChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QSize VirtualJoystickWidget::sizeHint() const {
|
||||
return prefSize;
|
||||
}
|
||||
@@ -241,6 +315,18 @@ void VirtualJoystickWidget::resizeEvent(QResizeEvent * event)
|
||||
setSize(event->size(), event->oldSize());
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::onNodeXChanged()
|
||||
{
|
||||
emit valueChange(RadioWidget::RADIO_WIDGET_STICK, m_xIndex, int(m_stickScale * getStickX()));
|
||||
updateNodeValueLabels();
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::onNodeYChanged()
|
||||
{
|
||||
emit valueChange(RadioWidget::RADIO_WIDGET_STICK, m_yIndex, int(-m_stickScale * getStickY()));
|
||||
updateNodeValueLabels();
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::setSize(const QSize & size, const QSize &)
|
||||
{
|
||||
float thisAspectRatio = (float)size.width() / size.height();
|
||||
@@ -301,9 +387,7 @@ RadioTrimWidget * VirtualJoystickWidget::createTrimWidget(QChar type)
|
||||
RadioTrimWidget * trimWidget = new RadioTrimWidget(type == 'H' ? Qt::Horizontal : Qt::Vertical);
|
||||
trimWidget->setIndices(getTrimSliderType(type), getTrimButtonType(type, 0), getTrimButtonType(type, 1));
|
||||
|
||||
connect(trimWidget, &RadioTrimWidget::trimButtonPressed, this, &VirtualJoystickWidget::trimButtonPressed);
|
||||
connect(trimWidget, &RadioTrimWidget::trimButtonReleased, this, &VirtualJoystickWidget::trimButtonReleased);
|
||||
connect(trimWidget, &RadioTrimWidget::trimSliderMoved, this, &VirtualJoystickWidget::trimSliderMoved);
|
||||
connect(trimWidget, &RadioTrimWidget::valueChange, this, &VirtualJoystickWidget::valueChange);
|
||||
|
||||
return trimWidget;
|
||||
}
|
||||
@@ -371,6 +455,24 @@ QLayout *VirtualJoystickWidget::createNodeValueLayout(QChar type, QLabel *& valL
|
||||
return layout;
|
||||
}
|
||||
|
||||
int VirtualJoystickWidget::getStickIndex(QChar type)
|
||||
{
|
||||
using namespace Board;
|
||||
|
||||
if (stickSide == 'L') {
|
||||
if (type == 'H')
|
||||
return STICK_AXIS_LH;
|
||||
else
|
||||
return STICK_AXIS_LV;
|
||||
}
|
||||
else {
|
||||
if (type == 'H')
|
||||
return STICK_AXIS_RH;
|
||||
else
|
||||
return STICK_AXIS_RV;
|
||||
}
|
||||
}
|
||||
|
||||
int VirtualJoystickWidget::getTrimSliderType(QChar type)
|
||||
{
|
||||
using namespace Board;
|
||||
@@ -426,10 +528,12 @@ int VirtualJoystickWidget::getTrimButtonType(QChar type, int pos)
|
||||
|
||||
RadioTrimWidget * VirtualJoystickWidget::getTrimWidget(int which)
|
||||
{
|
||||
if (which == Board::TRIM_AXIS_LH || which == Board::TRIM_AXIS_RH)
|
||||
if ((stickSide == 'L' && which == Board::TRIM_AXIS_LH) || (stickSide == 'R' && which == Board::TRIM_AXIS_RH))
|
||||
return hTrimWidget;
|
||||
else
|
||||
else if ((stickSide == 'L' && which == Board::TRIM_AXIS_LV) || (stickSide == 'R' && which == Board::TRIM_AXIS_RV))
|
||||
return vTrimWidget;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::onButtonChange(bool checked)
|
||||
@@ -456,9 +560,9 @@ void VirtualJoystickWidget::onButtonChange(bool checked)
|
||||
void VirtualJoystickWidget::updateNodeValueLabels()
|
||||
{
|
||||
if (nodeLabelX)
|
||||
nodeLabelX->setText(QString("%1").arg((qreal)node->getX() * 100 + getTrimValue(0) / 5, 2, 'f', 0));
|
||||
nodeLabelX->setText(QString("%1").arg(node->getX() * 100.0f, 2, 'f', 0));
|
||||
if (nodeLabelY)
|
||||
nodeLabelY->setText(QString("%1").arg((qreal)node->getY() * -100 + getTrimValue(1) / 5, 2, 'f', 0));
|
||||
nodeLabelY->setText(QString("%1").arg(node->getY() * -100.0f, 2, 'f', 0));
|
||||
}
|
||||
|
||||
void VirtualJoystickWidget::onGsMouseEvent(QGraphicsSceneMouseEvent * event)
|
||||
|
||||
Reference in New Issue
Block a user