[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
@@ -18,7 +18,23 @@
|
||||
#include "opentx.h"
|
||||
#include "simulcd.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#if !defined(MAX_LOGICAL_SWITCHES) && defined(NUM_CSW)
|
||||
#define MAX_LOGICAL_SWITCHES NUM_CSW
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
#define GET_SWITCH_BOOL(sw__) getSwitch((sw__), 0);
|
||||
#else
|
||||
#define GET_SWITCH_BOOL(sw__) getSwitch(sw__);
|
||||
#endif
|
||||
|
||||
#define OTXS_DBG qDebug() << "(" << simuTimerMicros() << "us)"
|
||||
|
||||
int16_t g_anas[Analogs::NUM_ANALOGS];
|
||||
QVector<QIODevice *> OpenTxSimulator::tracebackDevices;
|
||||
|
||||
uint16_t anaIn(uint8_t chan)
|
||||
{
|
||||
@@ -30,36 +46,135 @@ uint16_t getAnalogValue(uint8_t index)
|
||||
return anaIn(index);
|
||||
}
|
||||
|
||||
bool hasExtendedTrims()
|
||||
void firmwareTraceCb(const char * text)
|
||||
{
|
||||
return g_model.extendedTrims;
|
||||
foreach (QIODevice * dev, OpenTxSimulator::tracebackDevices) {
|
||||
if (dev)
|
||||
dev->write(text);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getStickMode()
|
||||
OpenTxSimulator::OpenTxSimulator() :
|
||||
SimulatorInterface(),
|
||||
m_timer10ms(NULL),
|
||||
m_resetOutputsData(true),
|
||||
m_stopRequested(false)
|
||||
{
|
||||
return limit<uint8_t>(0, g_eeGeneral.stickMode, 3);
|
||||
tracebackDevices.clear();
|
||||
traceCallback = firmwareTraceCb;
|
||||
}
|
||||
|
||||
|
||||
OpenTxSimulator::OpenTxSimulator()
|
||||
OpenTxSimulator::~OpenTxSimulator()
|
||||
{
|
||||
traceCallback = NULL;
|
||||
tracebackDevices.clear();
|
||||
|
||||
if (m_timer10ms)
|
||||
delete m_timer10ms;
|
||||
|
||||
if (isRunning()) {
|
||||
stop();
|
||||
QElapsedTimer tmout;
|
||||
tmout.start();
|
||||
while (isRunning() && !tmout.hasExpired(1000))
|
||||
;
|
||||
}
|
||||
//qDebug() << "Deleting OpenTxSimulator";
|
||||
}
|
||||
|
||||
QString OpenTxSimulator::name()
|
||||
{
|
||||
return QString(SIMULATOR_FLAVOUR);
|
||||
}
|
||||
|
||||
bool OpenTxSimulator::isRunning()
|
||||
{
|
||||
QMutexLocker lckr(&m_mtxSimuMain);
|
||||
return (bool)main_thread_running;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::init()
|
||||
{
|
||||
if (isRunning())
|
||||
return;
|
||||
OTXS_DBG;
|
||||
|
||||
if (!m_timer10ms) {
|
||||
// make sure we create & control the timer from current thread
|
||||
m_timer10ms = new QTimer();
|
||||
m_timer10ms->setInterval(10);
|
||||
connect(m_timer10ms, &QTimer::timeout, this, &OpenTxSimulator::run);
|
||||
connect(this, SIGNAL(started()), m_timer10ms, SLOT(start()));
|
||||
connect(this, SIGNAL(stopped()), m_timer10ms, SLOT(stop()));
|
||||
}
|
||||
|
||||
m_resetOutputsData = true;
|
||||
setStopRequested(false);
|
||||
|
||||
QMutexLocker lckr(&m_mtxSimuMain);
|
||||
memset(g_anas, 0, sizeof(g_anas));
|
||||
simuInit();
|
||||
}
|
||||
|
||||
void OpenTxSimulator::start(const char * filename, bool tests)
|
||||
{
|
||||
if (isRunning())
|
||||
return;
|
||||
OTXS_DBG << "file:" << filename << "tests:" << tests;
|
||||
|
||||
QMutexLocker lckr(&m_mtxSimuMain);
|
||||
QMutexLocker slckr(&m_mtxSettings);
|
||||
StartEepromThread(filename);
|
||||
StartAudioThread(volumeGain);
|
||||
StartSimu(tests, simuSdDirectory.toLatin1().constData(), simuSettingsDirectory.toLatin1().constData());
|
||||
|
||||
emit started();
|
||||
QTimer::singleShot(0, this, SLOT(run())); // old style for Qt < 5.4
|
||||
}
|
||||
|
||||
void OpenTxSimulator::stop()
|
||||
{
|
||||
if (!isRunning())
|
||||
return;
|
||||
OTXS_DBG;
|
||||
|
||||
setStopRequested(true);
|
||||
|
||||
QMutexLocker lckr(&m_mtxSimuMain);
|
||||
StopSimu();
|
||||
StopAudioThread();
|
||||
StopEepromThread();
|
||||
|
||||
emit stopped();
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setSdPath(const QString & sdPath, const QString & settingsPath)
|
||||
{
|
||||
QMutexLocker lckr(&m_mtxSettings);
|
||||
simuSdDirectory = sdPath;
|
||||
simuSettingsDirectory = settingsPath;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setVolumeGain(int value)
|
||||
void OpenTxSimulator::setVolumeGain(const int value)
|
||||
{
|
||||
QMutexLocker lckr(&m_mtxSettings);
|
||||
volumeGain = value;
|
||||
}
|
||||
|
||||
bool OpenTxSimulator::timer10ms()
|
||||
void OpenTxSimulator::setRadioData(const QByteArray & data)
|
||||
{
|
||||
#define TIMER10MS_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
#if defined(EEPROM_SIZE)
|
||||
QMutexLocker lckr(&m_mtxRadioData);
|
||||
memcpy(eeprom, data.data(), qMin<int>(EEPROM_SIZE, data.size()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenTxSimulator::readRadioData(QByteArray & dest)
|
||||
{
|
||||
#if defined(EEPROM_SIZE)
|
||||
QMutexLocker lckr(&m_mtxRadioData);
|
||||
memcpy(dest.data(), eeprom, std::min<int>(EEPROM_SIZE, dest.size()));
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t * OpenTxSimulator::getLcd()
|
||||
@@ -67,100 +182,364 @@ uint8_t * OpenTxSimulator::getLcd()
|
||||
return (uint8_t *)simuLcdBuf;
|
||||
}
|
||||
|
||||
bool OpenTxSimulator::lcdChanged(bool & lightEnable)
|
||||
void OpenTxSimulator::setAnalogValue(uint8_t index, int16_t value)
|
||||
{
|
||||
#define LCDCHANGED_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
static int dim = DIM(g_anas);
|
||||
if (index < dim)
|
||||
g_anas[index] = value;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::start(QByteArray & ee, bool tests)
|
||||
void OpenTxSimulator::setSwitch(uint8_t swtch, int8_t state)
|
||||
{
|
||||
#if defined(EEPROM_SIZE)
|
||||
memcpy(eeprom, ee.data(), std::min<int>(EEPROM_SIZE, ee.size()));
|
||||
#endif
|
||||
start((const char *)0, tests);
|
||||
simuSetSwitch(swtch, state);
|
||||
}
|
||||
|
||||
void OpenTxSimulator::start(const char * filename, bool tests)
|
||||
void OpenTxSimulator::setKey(uint8_t key, bool state)
|
||||
{
|
||||
if (main_thread_running)
|
||||
return;
|
||||
|
||||
StartEepromThread(filename);
|
||||
StartAudioThread(volumeGain);
|
||||
StartSimu(tests, simuSdDirectory.toLatin1().constData(), simuSettingsDirectory.toLatin1().constData());
|
||||
simuSetKey(key, state);
|
||||
}
|
||||
|
||||
void OpenTxSimulator::stop()
|
||||
void OpenTxSimulator::setTrimSwitch(uint8_t trim, bool state)
|
||||
{
|
||||
if (!main_thread_running)
|
||||
return;
|
||||
|
||||
StopSimu();
|
||||
#if defined(CPUARM)
|
||||
StopAudioThread();
|
||||
#endif
|
||||
StopEepromThread();
|
||||
}
|
||||
|
||||
void OpenTxSimulator::readEepromData(QByteArray & dest)
|
||||
{
|
||||
#if defined(EEPROM_SIZE)
|
||||
memcpy(dest.data(), eeprom, std::min<int>(EEPROM_SIZE, dest.size()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenTxSimulator::getValues(TxOutputs &outputs)
|
||||
{
|
||||
#define GETVALUES_IMPORT
|
||||
#define g_chans512 channelOutputs
|
||||
#include "simulatorimport.h"
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setValues(TxInputs &inputs)
|
||||
{
|
||||
#define SETVALUES_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
simuSetTrim(trim, state);
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setTrim(unsigned int idx, int value)
|
||||
{
|
||||
idx = modn12x3[4*getStickMode() + idx];
|
||||
uint8_t phase = getTrimFlightMode(getFlightMode(), idx);
|
||||
setTrimValue(phase, idx, value);
|
||||
unsigned i = idx;
|
||||
if (i < 4) // swap axes
|
||||
i = modn12x3[4 * getStickMode() + idx];
|
||||
uint8_t phase = getTrimFlightMode(getFlightMode(), i);
|
||||
|
||||
if (!setTrimValue(phase, i, value)) {
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setSingleShot(true);
|
||||
connect(timer, &QTimer::timeout, [=]() {
|
||||
emit trimValueChange(idx, 0);
|
||||
emit outputValueChange(OUTPUT_SRC_TRIM_VALUE, idx, 0);
|
||||
timer->deleteLater();
|
||||
});
|
||||
timer->start(350);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenTxSimulator::getTrims(Trims & trims)
|
||||
void OpenTxSimulator::setTrainerInput(unsigned int inputNumber, int16_t value)
|
||||
{
|
||||
uint8_t phase = getFlightMode();
|
||||
trims.extended = hasExtendedTrims();
|
||||
for (uint8_t idx=0; idx < CPN_MAX_TRIMS; idx++) {
|
||||
trims.values[idx] = getTrimValue(getTrimFlightMode(phase, idx), idx);
|
||||
}
|
||||
static unsigned dim = DIM(ppmInput);
|
||||
//setTrainerTimeout(100);
|
||||
if (inputNumber < dim)
|
||||
ppmInput[inputNumber] = qMin(qMax((int16_t)-512, value), (int16_t)512);
|
||||
}
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
uint8_t idx = modn12x3[4*getStickMode() + i];
|
||||
int16_t tmp = trims.values[i];
|
||||
trims.values[i] = trims.values[idx];
|
||||
trims.values[idx] = tmp;
|
||||
void OpenTxSimulator::setInputValue(int type, uint8_t index, int16_t value)
|
||||
{
|
||||
//qDebug() << type << index << value << this->thread();
|
||||
switch (type) {
|
||||
case INPUT_SRC_ANALOG :
|
||||
case INPUT_SRC_STICK :
|
||||
setAnalogValue(index, value);
|
||||
break;
|
||||
case INPUT_SRC_KNOB :
|
||||
setAnalogValue(index + NUM_STICKS, value);
|
||||
break;
|
||||
case INPUT_SRC_SLIDER :
|
||||
setAnalogValue(index + NUM_STICKS + NUM_POTS, value);
|
||||
break;
|
||||
case INPUT_SRC_TXVIN :
|
||||
setAnalogValue(Analogs::TX_VOLTAGE, voltageToAdc(value));
|
||||
break;
|
||||
case INPUT_SRC_SWITCH :
|
||||
setSwitch(index, (int8_t)value);
|
||||
break;
|
||||
case INPUT_SRC_TRIM_SW :
|
||||
setTrimSwitch(index, (bool)value);
|
||||
break;
|
||||
case INPUT_SRC_TRIM :
|
||||
setTrim(index, value);
|
||||
break;
|
||||
case INPUT_SRC_KEY :
|
||||
setKey(index, (bool)value);
|
||||
break;
|
||||
case INPUT_SRC_TRAINER :
|
||||
setTrainerInput(index, value);
|
||||
break;
|
||||
case INPUT_SRC_ROTENC : // TODO
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenTxSimulator::wheelEvent(int steps)
|
||||
void OpenTxSimulator::rotaryEncoderEvent(int steps)
|
||||
{
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
ROTARY_ENCODER_NAVIGATION_VALUE += steps * ROTARY_ENCODER_GRANULARITY;
|
||||
#else
|
||||
// TODO : this should probably be handled in the GUI
|
||||
int key;
|
||||
if (steps > 0)
|
||||
simuSetKey(KEY_MINUS, 1);
|
||||
key = KEY_MINUS;
|
||||
else if (steps < 0)
|
||||
simuSetKey(KEY_PLUS, 1);
|
||||
key = KEY_PLUS;
|
||||
|
||||
setKey(key, 1);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
|
||||
QTimer::singleShot(10, [this, key]() { setKey(key, 0); });
|
||||
#else
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setSingleShot(true);
|
||||
connect(timer, &QTimer::timeout, [=]() {
|
||||
setKey(key, 0);
|
||||
timer->deleteLater();
|
||||
} );
|
||||
timer->start(10);
|
||||
#endif
|
||||
#endif // defined(ROTARY_ENCODER_NAVIGATION)
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setTrainerTimeout(uint16_t ms)
|
||||
{
|
||||
ppmInputValidityTimer = ms;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::sendTelemetry(uint8_t * data, unsigned int len)
|
||||
{
|
||||
Q_UNUSED(len)
|
||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||
sportProcessTelemetryPacket(data);
|
||||
#else
|
||||
Q_UNUSED(data)
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned int OpenTxSimulator::getPhase()
|
||||
uint8_t OpenTxSimulator::getSensorInstance(uint16_t id, uint8_t defaultValue)
|
||||
{
|
||||
return getFlightMode();
|
||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isTelemetryFieldAvailable(i)) {
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[i];
|
||||
if (sensor->id == id) {
|
||||
return sensor->instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(id)
|
||||
#endif
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
uint16_t OpenTxSimulator::getSensorRatio(uint16_t id)
|
||||
{
|
||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isTelemetryFieldAvailable(i)) {
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[i];
|
||||
if (sensor->id == id) {
|
||||
return sensor->custom.ratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(id)
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int OpenTxSimulator::getCapability(Capability cap)
|
||||
{
|
||||
int ret = 0;
|
||||
switch(cap) {
|
||||
case CAP_LUA :
|
||||
#ifdef LUA
|
||||
ret = 1;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case CAP_ROTARY_ENC :
|
||||
#ifdef ROTARY_ENCODERS
|
||||
ret = ROTARY_ENCODERS;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case CAP_ROTARY_ENC_NAV :
|
||||
#ifdef ROTARY_ENCODER_NAVIGATION
|
||||
ret = 1;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case CAP_TELEM_FRSKY_SPORT :
|
||||
#ifdef TELEMETRY_FRSKY_SPORT
|
||||
ret = 1;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setLuaStateReloadPermanentScripts()
|
||||
{
|
||||
#if defined(LUA)
|
||||
luaState = INTERPRETER_RELOAD_PERMANENT_SCRIPTS;
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenTxSimulator::addTracebackDevice(QIODevice * device)
|
||||
{
|
||||
QMutexLocker lckr(&m_mtxTbDevices);
|
||||
if (device && !tracebackDevices.contains(device))
|
||||
tracebackDevices.append(device);
|
||||
}
|
||||
|
||||
void OpenTxSimulator::removeTracebackDevice(QIODevice * device)
|
||||
{
|
||||
if (device) {
|
||||
QMutexLocker lckr(&m_mtxTbDevices);
|
||||
// no QVector::removeAll() in Qt < 5.4
|
||||
int i = 0;
|
||||
foreach (QIODevice * d, tracebackDevices) {
|
||||
if (d == device)
|
||||
tracebackDevices.remove(i);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*** Protected classes ***/
|
||||
|
||||
void OpenTxSimulator::run()
|
||||
{
|
||||
static uint32_t loops = 0;
|
||||
static QElapsedTimer ts;
|
||||
|
||||
if (!loops)
|
||||
ts.start();
|
||||
|
||||
if (isStopRequested()) {
|
||||
return;
|
||||
}
|
||||
if (!isRunning()) {
|
||||
QString err(getError());
|
||||
emit runtimeError(err);
|
||||
emit stopped();
|
||||
return;
|
||||
}
|
||||
|
||||
++loops;
|
||||
|
||||
per10ms();
|
||||
|
||||
checkLcdChanged();
|
||||
|
||||
if (!(loops % 5)) {
|
||||
checkOutputsChanged();
|
||||
}
|
||||
|
||||
if (!(loops % (SIMULATOR_INTERFACE_HEARTBEAT_PERIOD / 10))) {
|
||||
emit heartbeat(loops, simuTimerMicros() / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenTxSimulator::isStopRequested()
|
||||
{
|
||||
QMutexLocker lckr(&m_mtxStopReq);
|
||||
return m_stopRequested;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setStopRequested(bool stop)
|
||||
{
|
||||
QMutexLocker lckr(&m_mtxStopReq);
|
||||
m_stopRequested = stop;
|
||||
}
|
||||
|
||||
bool OpenTxSimulator::checkLcdChanged()
|
||||
{
|
||||
if (simuLcdRefresh) {
|
||||
simuLcdRefresh = false;
|
||||
emit lcdChange(isBacklightEnabled());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::checkOutputsChanged()
|
||||
{
|
||||
static TxOutputs lastOutputs;
|
||||
static size_t chansDim = DIM(channelOutputs);
|
||||
qint32 tmpVal;
|
||||
uint8_t i, idx;
|
||||
uint8_t phase = getFlightMode(); // opentx.cpp
|
||||
uint8_t mode = getStickMode();
|
||||
|
||||
for (i=0; i < chansDim; i++) {
|
||||
if (lastOutputs.chans[i] != channelOutputs[i] || m_resetOutputsData) {
|
||||
emit channelOutValueChange(i, channelOutputs[i]);
|
||||
emit channelMixValueChange(i, ex_chans[i]);
|
||||
emit outputValueChange(OUTPUT_SRC_CHAN_OUT, i, channelOutputs[i]);
|
||||
emit outputValueChange(OUTPUT_SRC_CHAN_MIX, i, ex_chans[i]);
|
||||
lastOutputs.chans[i] = channelOutputs[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i < MAX_LOGICAL_SWITCHES; i++) {
|
||||
tmpVal = (qint32)GET_SWITCH_BOOL(SWSRC_SW1+i);
|
||||
if (lastOutputs.vsw[i] != (bool)tmpVal || m_resetOutputsData) {
|
||||
emit virtualSwValueChange(i, tmpVal);
|
||||
emit outputValueChange(OUTPUT_SRC_VIRTUAL_SW, i, tmpVal);
|
||||
lastOutputs.vsw[i] = tmpVal;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i < Board::TRIM_AXIS_COUNT; i++) {
|
||||
if (i < 4) // swap axes
|
||||
idx = modn12x3[4 * mode + i];
|
||||
else
|
||||
idx = i;
|
||||
|
||||
tmpVal = getTrimValue(getTrimFlightMode(phase, idx), idx);
|
||||
if (lastOutputs.trims[i] != tmpVal || m_resetOutputsData) {
|
||||
emit trimValueChange(i, tmpVal);
|
||||
emit outputValueChange(OUTPUT_SRC_TRIM_VALUE, i, tmpVal);
|
||||
lastOutputs.trims[i] = tmpVal;
|
||||
}
|
||||
}
|
||||
|
||||
tmpVal = g_model.extendedTrims ? TRIM_EXTENDED_MAX : TRIM_MAX;
|
||||
if (lastOutputs.trimRange != tmpVal || m_resetOutputsData) {
|
||||
emit trimRangeChange(Board::TRIM_AXIS_COUNT, -tmpVal, tmpVal);
|
||||
emit outputValueChange(OUTPUT_SRC_TRIM_RANGE, Board::TRIM_AXIS_COUNT, tmpVal);
|
||||
lastOutputs.trimRange = tmpVal;
|
||||
}
|
||||
|
||||
if (lastOutputs.phase != phase || m_resetOutputsData) {
|
||||
emit phaseChanged(phase, getCurrentPhaseName());
|
||||
emit outputValueChange(OUTPUT_SRC_PHASE, 0, qint16(phase));
|
||||
lastOutputs.phase = phase;
|
||||
}
|
||||
|
||||
#if defined(GVAR_VALUE) && defined(GVARS)
|
||||
gVarMode_t gvar;
|
||||
for (uint8_t fm=0; fm < MAX_FLIGHT_MODES; fm++) {
|
||||
gvar.mode = fm;
|
||||
for (uint8_t gv=0; gv < MAX_GVARS; gv++) {
|
||||
tmpVal = GVAR_VALUE(gv, getGVarFlightMode(fm, gv));
|
||||
if (lastOutputs.gvars[fm][gv] != tmpVal || m_resetOutputsData) {
|
||||
lastOutputs.gvars[fm][gv] = tmpVal;
|
||||
gvar.value = (int16_t)tmpVal;
|
||||
tmpVal = gvar;
|
||||
emit gVarValueChange(gv, tmpVal);
|
||||
emit outputValueChange(OUTPUT_SRC_GVAR, gv, tmpVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
m_resetOutputsData = false;
|
||||
}
|
||||
|
||||
uint8_t OpenTxSimulator::getStickMode()
|
||||
{
|
||||
return limit<uint8_t>(0, g_eeGeneral.stickMode, 3);
|
||||
}
|
||||
|
||||
const char * OpenTxSimulator::getPhaseName(unsigned int phase)
|
||||
@@ -170,66 +549,39 @@ const char * OpenTxSimulator::getPhaseName(unsigned int phase)
|
||||
return buff;
|
||||
}
|
||||
|
||||
const QString OpenTxSimulator::getCurrentPhaseName()
|
||||
{
|
||||
unsigned phase = getFlightMode();
|
||||
QString name(getPhaseName(phase));
|
||||
if (name.isEmpty())
|
||||
name = QString::number(phase);
|
||||
return name;
|
||||
}
|
||||
|
||||
const char * OpenTxSimulator::getError()
|
||||
{
|
||||
#define GETERROR_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
return main_thread_error;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::sendTelemetry(uint8_t * data, unsigned int len)
|
||||
const int OpenTxSimulator::voltageToAdc(const int volts)
|
||||
{
|
||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||
sportProcessTelemetryPacket(data);
|
||||
int ret = 0;
|
||||
#if defined(PCBHORUS) || defined(PCBX7)
|
||||
ret = (float)volts * 16.2f;
|
||||
#elif defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBSKY9X)
|
||||
ret = (float)volts * 13.3f;
|
||||
#elif defined(PCBGRUVIN9X)
|
||||
ret = (float)volts * 1.63f;
|
||||
#else
|
||||
ret = (float)volts * 14.15f;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t OpenTxSimulator::getSensorInstance(uint16_t id, uint8_t defaultValue)
|
||||
{
|
||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||
for (int i = 0; i<MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isTelemetryFieldAvailable(i)) {
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[i];
|
||||
if (sensor->id == id) {
|
||||
return sensor->instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
uint16_t OpenTxSimulator::getSensorRatio(uint16_t id)
|
||||
{
|
||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||
for (int i = 0; i<MAX_TELEMETRY_SENSORS; i++) {
|
||||
if (isTelemetryFieldAvailable(i)) {
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[i];
|
||||
if (sensor->id == id) {
|
||||
return sensor->custom.ratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setTrainerInput(unsigned int inputNumber, int16_t value)
|
||||
{
|
||||
#define SETTRAINER_IMPORT
|
||||
#include "simulatorimport.h"
|
||||
}
|
||||
|
||||
void OpenTxSimulator::setLuaStateReloadPermanentScripts()
|
||||
{
|
||||
#if defined(LUA)
|
||||
luaState = INTERPRETER_RELOAD_PERMANENT_SCRIPTS;
|
||||
#endif
|
||||
}
|
||||
|
||||
void OpenTxSimulator::installTraceHook(void (*callback)(const char *))
|
||||
{
|
||||
traceCallback = callback;
|
||||
}
|
||||
/*
|
||||
* OpenTxSimulatorFactory
|
||||
*/
|
||||
|
||||
class OpenTxSimulatorFactory: public SimulatorFactory
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user