[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:
Max Paperno
2017-04-02 12:17:37 +02:00
committed by Bertrand Songis
parent 36bb951314
commit 57dc0159d6
46 changed files with 2058 additions and 1321 deletions
@@ -18,51 +18,66 @@
* GNU General Public License for more details.
*/
#include "radiouiaction.h"
#include "radiowidget.h"
RadioWidget::RadioWidget(QWidget * parent, Qt::WindowFlags f) :
QWidget(parent, f),
m_gridLayout(NULL),
m_controlWidget(NULL),
m_nameLabel(NULL),
m_action(NULL),
m_value(0),
m_flags(0),
m_invertValue(false),
m_valueReset(false),
m_showLabel(false),
m_labelText(""),
m_type(RADIO_WIDGET_NONE)
m_labelText("")
{
init();
qRegisterMetaType<RadioWidgetState>();
setIndex(-1);
setType(RADIO_WIDGET_NONE);
}
RadioWidget::RadioWidget(RadioUiAction * action, QWidget * parent, Qt::WindowFlags f) :
RadioWidget(parent, f)
{
setAction(action);
}
RadioWidget::RadioWidget(const QString & labelText, int value, QWidget * parent, Qt::WindowFlags f) :
QWidget(parent, f),
m_value(value),
m_flags(0),
m_invertValue(false),
m_showLabel(true),
m_labelText(labelText),
m_type(RADIO_WIDGET_NONE)
RadioWidget(parent, f)
{
init();
setValue(value);
setLabelText(labelText);
}
void RadioWidget::setIndex(int index)
void RadioWidget::setIndex(const int & index)
{
m_index = index;
}
void RadioWidget::setInvertValue(bool invertValue)
void RadioWidget::setType(const RadioWidgetType & type)
{
m_invertValue = invertValue;
m_type = type;
}
void RadioWidget::setValue(int value)
void RadioWidget::setValue(const int & value)
{
if (value != m_value) {
if (value != m_value || m_valueReset) {
m_value = value;
m_valueReset = false;
emit valueChanged(value);
emit valueChange(m_type, m_index, value);
}
}
void RadioWidget::setFlags(quint16 flags)
void RadioWidget::setValueQual(const RadioWidget::RadioWidgetType & type, const int & index, const int & value)
{
if (type == m_type && index == m_index)
setValue(value);
}
void RadioWidget::setFlags(const quint16 & flags)
{
if (flags != m_flags) {
m_flags = flags;
@@ -70,7 +85,7 @@ void RadioWidget::setFlags(quint16 flags)
}
}
void RadioWidget::setShowLabel(bool show)
void RadioWidget::setShowLabel(const bool show)
{
if (show != m_showLabel) {
m_showLabel = show;
@@ -85,13 +100,12 @@ void RadioWidget::setLabelText(const QString & labelText, bool showLabel)
addLabel();
}
void RadioWidget::setStateData(const QByteArray & data)
void RadioWidget::setStateData(const RadioWidgetState & state)
{
RadioWidgetState state;
QDataStream stream(data);
stream >> state;
if (state.type != m_type || state.index != m_index)
return;
//setIndex(state.index);
m_valueReset = true;
setValue(state.value);
setFlags(state.flags);
}
@@ -109,9 +123,26 @@ void RadioWidget::changeVisibility(bool visible)
}
}
void RadioWidget::setAction(RadioUiAction * action)
{
if (m_action) {
disconnect(m_action, 0, this, 0);
delete m_action;
m_action = NULL;
}
m_action = action;
if (m_action) {
if (m_action->getIndex() > -1)
setIndex(m_action->getIndex());
connect(m_action, &RadioUiAction::toggled, this, &RadioWidget::onActionToggled);
}
}
int RadioWidget::getValue() const
{
return m_value * (m_invertValue ? -1 : 1);
return m_value;
}
int RadioWidget::getIndex() const
@@ -134,25 +165,34 @@ QByteArray RadioWidget::getStateData() const
RadioWidget::RadioWidgetState RadioWidget::getState() const
{
return RadioWidgetState(quint8(m_type), qint8(m_index), qint16(m_value), quint16(m_flags));;
return RadioWidgetState(quint8(m_type), qint8(m_index), qint16(m_value), quint16(m_flags));
}
void RadioWidget::init()
RadioUiAction * RadioWidget::getAction() const
{
setIndex(0);
m_controlWidget = NULL;
m_nameLabel = NULL;
return m_action;
}
m_gridLayout= new QGridLayout(this);
void RadioWidget::onActionToggled(int index, bool active)
{
emit valueChange(m_type, index, getValue());
}
void RadioWidget::addLayout()
{
if (m_gridLayout)
return;
m_gridLayout = new QGridLayout(this);
m_gridLayout->setContentsMargins(0, 0, 0, 0);
m_gridLayout->setVerticalSpacing(4);
m_gridLayout->setHorizontalSpacing(0);
addLabel();
}
void RadioWidget::addLabel()
{
addLayout();
if (m_nameLabel) {
m_gridLayout->removeWidget(m_nameLabel);
m_nameLabel->deleteLater();
@@ -168,6 +208,7 @@ void RadioWidget::addLabel()
void RadioWidget::setWidget(QWidget * widget, Qt::Alignment align)
{
addLayout();
if (m_controlWidget) {
m_gridLayout->removeWidget(m_controlWidget);
m_controlWidget->deleteLater();