mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-25 17:25:10 +03:00
[Companion] Sensor switches support added
+ some refactoring to hide irrelevant switches in the combobox More refactoring to come: - have only one SwitchModel per model instead of one per tab - only do the update work if something has changed
This commit is contained in:
parent
b814f997f8
commit
b55070f939
18 changed files with 290 additions and 111 deletions
|
@ -622,7 +622,7 @@ bool RawSource::isSlider(int * sliderIndex) const
|
|||
* RawSwitch
|
||||
*/
|
||||
|
||||
QString RawSwitch::toString(Board::Type board, const GeneralSettings * const generalSettings) const
|
||||
QString RawSwitch::toString(Board::Type board, const GeneralSettings * const generalSettings, const ModelData * const modelData) const
|
||||
{
|
||||
if (board == Board::BOARD_UNKNOWN) {
|
||||
board = getCurrentBoard();
|
||||
|
@ -662,7 +662,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
|
|||
<< CPN_STR_SW_INDICATOR_DN;
|
||||
|
||||
if (index < 0) {
|
||||
return CPN_STR_SW_INDICATOR_REV % RawSwitch(type, -index).toString(board, generalSettings);
|
||||
return CPN_STR_SW_INDICATOR_REV % RawSwitch(type, -index).toString(board, generalSettings, modelData);
|
||||
}
|
||||
else {
|
||||
QString swName;
|
||||
|
@ -718,6 +718,15 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
|
|||
case SWITCH_TYPE_TIMER_MODE:
|
||||
return CHECK_IN_ARRAY(timerModes, index);
|
||||
|
||||
case SWITCH_TYPE_SENSOR:
|
||||
if (modelData && index <= CPN_MAX_SENSORS && strlen(modelData->sensorData[index-1].label) > 0)
|
||||
return QObject::tr("Sensor%1 (%2)").arg(index).arg(modelData->sensorData[index-1].label);
|
||||
else
|
||||
return QObject::tr("Sensor%1").arg(index);
|
||||
|
||||
case SWITCH_TYPE_TELEMETRY:
|
||||
return QObject::tr("Telemetry");
|
||||
|
||||
default:
|
||||
return QObject::tr("???");
|
||||
}
|
||||
|
@ -1745,6 +1754,24 @@ int ModelData::getChannelsMax(bool forceExtendedLimits) const
|
|||
return 100;
|
||||
}
|
||||
|
||||
bool ModelData::isAvailable(const RawSwitch & swtch) const
|
||||
{
|
||||
unsigned index = abs(swtch.index) - 1;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_VIRTUAL) {
|
||||
return logicalSw[index].func != LS_FN_OFF;
|
||||
}
|
||||
else if (swtch.type == SWITCH_TYPE_FLIGHT_MODE) {
|
||||
return index == 0 || flightModeData[index].swtch.type != SWITCH_TYPE_NONE;
|
||||
}
|
||||
else if (swtch.type == SWITCH_TYPE_SENSOR) {
|
||||
return strlen(sensorData[index].label) > 0;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
QList<EEPROMInterface *> eepromInterfaces;
|
||||
|
||||
void unregisterEEpromInterfaces()
|
||||
|
|
|
@ -133,6 +133,7 @@ class SwitchesConversionTable: public ConversionTable {
|
|||
|
||||
addConversion(RawSwitch(SWITCH_TYPE_OFF), -val+offset);
|
||||
addConversion(RawSwitch(SWITCH_TYPE_ON), val++);
|
||||
|
||||
if (version >= 216) {
|
||||
addConversion(RawSwitch(SWITCH_TYPE_ONE, -1), -val+offset);
|
||||
addConversion(RawSwitch(SWITCH_TYPE_ONE, 1), val++);
|
||||
|
@ -144,6 +145,15 @@ class SwitchesConversionTable: public ConversionTable {
|
|||
}
|
||||
}
|
||||
|
||||
if (IS_ARM(board) && version >= 218) {
|
||||
addConversion(RawSwitch(SWITCH_TYPE_TELEMETRY, -1), -val+offset);
|
||||
addConversion(RawSwitch(SWITCH_TYPE_TELEMETRY, 1), val++);
|
||||
for (int i=1; i<=CPN_MAX_SENSORS; i++) {
|
||||
addConversion(RawSwitch(SWITCH_TYPE_SENSOR, -i), -val+offset);
|
||||
addConversion(RawSwitch(SWITCH_TYPE_SENSOR, i), val++);
|
||||
}
|
||||
}
|
||||
|
||||
if (version < 216) {
|
||||
// previous "moment" switches
|
||||
for (int i=1; i<=MAX_SWITCHES_POSITION(board, version); i++) {
|
||||
|
|
|
@ -404,84 +404,6 @@ void Helpers::getFileComboBoxValue(QComboBox * b, char * dest, int length)
|
|||
}
|
||||
}
|
||||
|
||||
void Helpers::addRawSwitchItems(QStandardItemModel * itemModel, const RawSwitchType & type, int count, const GeneralSettings * const generalSettings)
|
||||
{
|
||||
// Most RawSwitch() indices are one-based (vs. typical zero); these are exceptions to the rule:
|
||||
const static QVector<int> rawSwitchIndexBaseZeroTypes = QVector<int>() << SWITCH_TYPE_NONE << SWITCH_TYPE_ON << SWITCH_TYPE_OFF << SWITCH_TYPE_TIMER_MODE;
|
||||
|
||||
int rawIdxAdj = 0;
|
||||
const Board::Type board = getCurrentBoard();
|
||||
int i = (count < 0 ? count : 1);
|
||||
const int maxCount = (i < 0 ? 0 : count + i);
|
||||
|
||||
// handle exceptions in RawSwitch() index values
|
||||
if (rawSwitchIndexBaseZeroTypes.contains(type))
|
||||
rawIdxAdj = -1;
|
||||
|
||||
for ( ; i < maxCount; ++i) {
|
||||
if (generalSettings) {
|
||||
if (type == SWITCH_TYPE_SWITCH && IS_HORUS_OR_TARANIS(board) && !generalSettings->switchPositionAllowedTaranis(abs(i)))
|
||||
continue;
|
||||
if (type == SWITCH_TYPE_MULTIPOS_POT) {
|
||||
int pot = div(abs(i) - 1, getCurrentFirmware()->getCapability(MultiposPotsPositions)).quot;
|
||||
if (!generalSettings->isPotAvailable(pot) || generalSettings->potConfig[pot] != Board::POT_MULTIPOS_SWITCH)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
RawSwitch rs(type, i + rawIdxAdj);
|
||||
QStandardItem * modelItem = new QStandardItem(rs.toString(board, generalSettings));
|
||||
modelItem->setData(rs.toValue(), Qt::UserRole);
|
||||
itemModel->appendRow(modelItem);
|
||||
}
|
||||
}
|
||||
|
||||
QStandardItemModel * Helpers::getRawSwitchItemModel(const GeneralSettings * const generalSettings, SwitchContext context)
|
||||
{
|
||||
QStandardItemModel * itemModel = new QStandardItemModel();
|
||||
Boards board = Boards(getCurrentBoard());
|
||||
Board::Type btype = board.getBoardType();
|
||||
Firmware * fw = getCurrentFirmware();
|
||||
|
||||
// Descending switch direction: NOT (!) switches
|
||||
|
||||
if (context != MixesContext && context != GlobalFunctionsContext && IS_ARM(btype)) {
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes), generalSettings);
|
||||
}
|
||||
if (context != GlobalFunctionsContext) {
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches), generalSettings);
|
||||
}
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_ROTARY_ENCODER, -fw->getCapability(RotaryEncoders), generalSettings);
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_TRIM, -board.getCapability(Board::NumTrimSwitches), generalSettings);
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_MULTIPOS_POT, -(fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions)), generalSettings);
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_SWITCH, -board.getCapability(Board::SwitchPositions), generalSettings);
|
||||
|
||||
// Ascending switch direction (including zero)
|
||||
|
||||
if (context == TimersContext) {
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_TIMER_MODE, 5, generalSettings);
|
||||
}
|
||||
else {
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_NONE, 1);
|
||||
}
|
||||
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_SWITCH, board.getCapability(Board::SwitchPositions), generalSettings);
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_MULTIPOS_POT, fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions), generalSettings);
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_TRIM, board.getCapability(Board::NumTrimSwitches), generalSettings);
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders), generalSettings);
|
||||
if (context != GlobalFunctionsContext) {
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches), generalSettings);
|
||||
}
|
||||
if (context != MixesContext && context != GlobalFunctionsContext && IS_ARM(btype)) {
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes), generalSettings);
|
||||
}
|
||||
if (context == SpecialFunctionsContext || context == GlobalFunctionsContext) {
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_ON, 1);
|
||||
addRawSwitchItems(itemModel, SWITCH_TYPE_ONE, 1);
|
||||
}
|
||||
|
||||
return itemModel;
|
||||
}
|
||||
|
||||
void Helpers::addRawSourceItems(QStandardItemModel * itemModel, const RawSourceType & type, int count, const GeneralSettings * const generalSettings,
|
||||
const ModelData * const model, const int start, const QList<int> exclude)
|
||||
{
|
||||
|
|
|
@ -129,18 +129,6 @@ class CurveGroup : public QObject {
|
|||
|
||||
namespace Helpers
|
||||
{
|
||||
enum SwitchContext
|
||||
{
|
||||
LogicalSwitchesContext,
|
||||
SpecialFunctionsContext,
|
||||
GlobalFunctionsContext,
|
||||
TimersContext,
|
||||
MixesContext
|
||||
};
|
||||
|
||||
void addRawSwitchItems(QStandardItemModel * itemModel, const RawSwitchType & type, int count, const GeneralSettings * const generalSettings = NULL);
|
||||
QStandardItemModel * getRawSwitchItemModel(const GeneralSettings * const generalSettings = NULL, SwitchContext context = LogicalSwitchesContext);
|
||||
|
||||
void addRawSourceItems(QStandardItemModel * itemModel, const RawSourceType & type, int count, const GeneralSettings * const generalSettings = NULL,
|
||||
const ModelData * const model = NULL, const int start = 0, const QList<int> exclude = QList<int>());
|
||||
QStandardItemModel * getRawSourceItemModel(const GeneralSettings * const generalSettings = NULL, const ModelData * const model = NULL, unsigned int flags = 0);
|
||||
|
|
|
@ -16,6 +16,7 @@ set(modeledit_NAMES
|
|||
)
|
||||
|
||||
set(modeledit_SRCS
|
||||
switchitemmodel.cpp
|
||||
flightmodes.cpp
|
||||
inputs.cpp
|
||||
mixes.cpp
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
|
||||
#include "customfunctions.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "helpers.h"
|
||||
#include "appdata.h"
|
||||
|
||||
|
@ -73,8 +74,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
|||
lock = true;
|
||||
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
|
||||
|
||||
rawSwitchItemModel = Helpers::getRawSwitchItemModel(&generalSettings, model ? Helpers::SpecialFunctionsContext : Helpers::GlobalFunctionsContext);
|
||||
rawSwitchItemModel->setParent(this);
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? SpecialFunctionsContext : GlobalFunctionsContext);
|
||||
rawSrcInputsItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_TRIMS|POPULATE_SWITCHES);
|
||||
rawSrcInputsItemModel->setParent(this);
|
||||
rawSrcAllItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_SWITCHES|POPULATE_GVARS|POPULATE_TRIMS|POPULATE_TELEMETRY|POPULATE_TELEMETRYEXT|POPULATE_SCRIPT_OUTPUTS);
|
||||
|
@ -584,6 +584,8 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
|||
|
||||
void CustomFunctionsPanel::update()
|
||||
{
|
||||
rawSwitchItemModel->update();
|
||||
|
||||
lock = true;
|
||||
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
|
||||
for (int i=0; i<num_fsw; i++) {
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
#ifndef _CUSTOMFUNCTIONS_H_
|
||||
#define _CUSTOMFUNCTIONS_H_
|
||||
|
||||
#include <QMediaPlayer>
|
||||
#include "modeledit.h"
|
||||
#include "eeprominterface.h"
|
||||
#include <QMediaPlayer>
|
||||
|
||||
class RawSwitchFilterItemModel;
|
||||
|
||||
class RepeatComboBox: public QComboBox
|
||||
{
|
||||
|
@ -74,7 +76,7 @@ class CustomFunctionsPanel : public GenericPanel
|
|||
void populateFuncCB(QComboBox *b, unsigned int value);
|
||||
void populateGVmodeCB(QComboBox *b, unsigned int value);
|
||||
void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0);
|
||||
QStandardItemModel * rawSwitchItemModel;
|
||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||
QStandardItemModel * rawSrcInputsItemModel;
|
||||
QStandardItemModel * rawSrcAllItemModel;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "expodialog.h"
|
||||
#include "ui_expodialog.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "helpers.h"
|
||||
|
||||
ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, GeneralSettings & generalSettings,
|
||||
|
@ -61,7 +62,7 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, G
|
|||
curveGroup = new CurveGroup(ui->curveTypeCB, ui->curveGVarCB, ui->curveValueCB, ui->curveValueSB, ed->curve, model,
|
||||
firmware->getCapability(HasInputDiff) ? 0 : (HIDE_DIFF | HIDE_NEGATIVE_CURVES));
|
||||
|
||||
ui->switchesCB->setModel(Helpers::getRawSwitchItemModel(&generalSettings, Helpers::MixesContext));
|
||||
ui->switchesCB->setModel(new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext));
|
||||
ui->switchesCB->setCurrentIndex(ui->switchesCB->findData(ed->swtch.toValue()));
|
||||
|
||||
ui->sideCB->setCurrentIndex(ed->mode-1);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "flightmodes.h"
|
||||
#include "ui_flightmode.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "helpers.h"
|
||||
|
||||
FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseIdx, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
|
@ -28,7 +29,8 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
|
|||
phaseIdx(phaseIdx),
|
||||
phase(model.flightModeData[phaseIdx]),
|
||||
reCount(firmware->getCapability(RotaryEncoders)),
|
||||
gvCount(firmware->getCapability(Gvars))
|
||||
gvCount(firmware->getCapability(Gvars)),
|
||||
rawSwitchItemModel(NULL)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -50,7 +52,8 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
|
|||
|
||||
// Phase switch
|
||||
if (phaseIdx > 0) {
|
||||
ui->swtch->setModel(Helpers::getRawSwitchItemModel(&generalSettings, Helpers::MixesContext));
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext);
|
||||
ui->swtch->setModel(rawSwitchItemModel);
|
||||
ui->swtch->setCurrentIndex(ui->swtch->findData(phase.swtch.toValue()));
|
||||
connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int)));
|
||||
}
|
||||
|
@ -228,6 +231,10 @@ FlightModePanel::~FlightModePanel()
|
|||
|
||||
void FlightModePanel::update()
|
||||
{
|
||||
if (rawSwitchItemModel) {
|
||||
rawSwitchItemModel->update();
|
||||
}
|
||||
|
||||
ui->name->setText(phase.name);
|
||||
|
||||
int scale = firmware->getCapability(SlowScale);
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "modeledit.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
class RawSwitchFilterItemModel;
|
||||
|
||||
namespace Ui {
|
||||
class FlightMode;
|
||||
}
|
||||
|
@ -74,6 +76,7 @@ class FlightModePanel : public ModelPanel
|
|||
QVector<QComboBox *> trimsUse;
|
||||
QVector<QSpinBox *> trimsValue;
|
||||
QVector<QSlider *> trimsSlider;
|
||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||
|
||||
void trimUpdate(unsigned int trim);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
|
||||
#include "logicalswitches.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "helpers.h"
|
||||
|
||||
LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
|
@ -28,8 +29,7 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
|||
Stopwatch s1("LogicalSwitchesPanel");
|
||||
|
||||
int channelsMax = model.getChannelsMax(true);
|
||||
rawSwitchItemModel = Helpers::getRawSwitchItemModel(&generalSettings, Helpers::LogicalSwitchesContext);
|
||||
rawSwitchItemModel->setParent(this);
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, LogicalSwitchesContext);
|
||||
int srcFlags = POPULATE_NONE | POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0);
|
||||
rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, &model, srcFlags);
|
||||
rawSourceItemModel->setParent(this);
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
#define _LOGICALSWITCHES_H_
|
||||
|
||||
#include "modeledit.h"
|
||||
#include "eeprominterface.h"
|
||||
#include "radiodata.h"
|
||||
|
||||
class RawSwitchFilterItemModel;
|
||||
|
||||
class LogicalSwitchesPanel : public ModelPanel
|
||||
{
|
||||
|
@ -58,7 +60,7 @@ class LogicalSwitchesPanel : public ModelPanel
|
|||
QDoubleSpinBox * cswitchDelay[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QComboBox * cswitchSource1[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QComboBox * cswitchSource2[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QStandardItemModel * rawSwitchItemModel;
|
||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||
QStandardItemModel * rawSourceItemModel;
|
||||
void setSwitchWidgetVisibility(int i);
|
||||
int selectedSwitch;
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
|
||||
#include "mixerdialog.h"
|
||||
#include "ui_mixerdialog.h"
|
||||
#include "eeprominterface.h"
|
||||
#include "radiodata.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "helpers.h"
|
||||
|
||||
MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata, GeneralSettings & generalSettings, Firmware * firmware) :
|
||||
|
@ -103,7 +104,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData *mixdata, G
|
|||
}
|
||||
}
|
||||
|
||||
ui->switchesCB->setModel(Helpers::getRawSwitchItemModel(&generalSettings, Helpers::MixesContext));
|
||||
ui->switchesCB->setModel(new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext));
|
||||
ui->switchesCB->setCurrentIndex(ui->switchesCB->findData(md->swtch.toValue()));
|
||||
ui->warningCB->setCurrentIndex(md->mixWarn);
|
||||
ui->mltpxCB->setCurrentIndex(md->mltpx);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "ui_setup.h"
|
||||
#include "ui_setup_timer.h"
|
||||
#include "ui_setup_module.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "helpers.h"
|
||||
#include "appdata.h"
|
||||
#include "modelprinter.h"
|
||||
|
@ -50,7 +51,8 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
|
|||
}
|
||||
|
||||
// Mode
|
||||
ui->mode->setModel(Helpers::getRawSwitchItemModel(&generalSettings, Helpers::TimersContext));
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, TimersContext);
|
||||
ui->mode->setModel(rawSwitchItemModel);
|
||||
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
|
||||
|
||||
if (!firmware->getCapability(PermTimers)) {
|
||||
|
@ -91,6 +93,8 @@ TimerPanel::~TimerPanel()
|
|||
|
||||
void TimerPanel::update()
|
||||
{
|
||||
rawSwitchItemModel->update();
|
||||
|
||||
int hour = timer.val / 3600;
|
||||
int min = (timer.val - (hour * 3600)) / 60;
|
||||
int sec = (timer.val - (hour * 3600)) % 60;
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "modeledit.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
class RawSwitchFilterItemModel;
|
||||
|
||||
namespace Ui {
|
||||
class Setup;
|
||||
class Timer;
|
||||
|
@ -50,6 +52,7 @@ class TimerPanel : public ModelPanel
|
|||
private:
|
||||
TimerData & timer;
|
||||
Ui::Timer * ui;
|
||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||
};
|
||||
|
||||
class ModulePanel : public ModelPanel
|
||||
|
|
144
companion/src/modeledit/switchitemmodel.cpp
Normal file
144
companion/src/modeledit/switchitemmodel.cpp
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* 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 "switchitemmodel.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData):
|
||||
generalSettings(generalSettings),
|
||||
modelData(modelData)
|
||||
{
|
||||
Boards board = Boards(getCurrentBoard());
|
||||
Board::Type btype = board.getBoardType();
|
||||
Firmware * fw = getCurrentFirmware();
|
||||
|
||||
// Descending switch direction: NOT (!) switches
|
||||
if (IS_ARM(btype)) {
|
||||
add(SWITCH_TYPE_SENSOR, -CPN_MAX_SENSORS);
|
||||
add(SWITCH_TYPE_TELEMETRY, -1);
|
||||
add(SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes));
|
||||
}
|
||||
add(SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches));
|
||||
add(SWITCH_TYPE_ROTARY_ENCODER, -fw->getCapability(RotaryEncoders));
|
||||
add(SWITCH_TYPE_TRIM, -board.getCapability(Board::NumTrimSwitches));
|
||||
add(SWITCH_TYPE_MULTIPOS_POT, -(fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions)));
|
||||
add(SWITCH_TYPE_SWITCH, -board.getCapability(Board::SwitchPositions));
|
||||
|
||||
// Ascending switch direction (including zero)
|
||||
add(SWITCH_TYPE_TIMER_MODE, 5);
|
||||
add(SWITCH_TYPE_NONE, 1);
|
||||
add(SWITCH_TYPE_SWITCH, board.getCapability(Board::SwitchPositions));
|
||||
add(SWITCH_TYPE_MULTIPOS_POT, fw->getCapability(MultiposPots) * fw->getCapability(MultiposPotsPositions));
|
||||
add(SWITCH_TYPE_TRIM, board.getCapability(Board::NumTrimSwitches));
|
||||
add(SWITCH_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders));
|
||||
add(SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches));
|
||||
if (IS_ARM(btype)) {
|
||||
add(SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes));
|
||||
add(SWITCH_TYPE_TELEMETRY, 1);
|
||||
add(SWITCH_TYPE_SENSOR, CPN_MAX_SENSORS);
|
||||
}
|
||||
add(SWITCH_TYPE_ON, 1);
|
||||
add(SWITCH_TYPE_ONE, 1);
|
||||
}
|
||||
|
||||
void RawSwitchItemModel::add(const RawSwitchType & type, int count)
|
||||
{
|
||||
// Most RawSwitch() indices are one-based (vs. typical zero); these are exceptions to the rule:
|
||||
const static QVector<int> rawSwitchIndexBaseZeroTypes = QVector<int>() << SWITCH_TYPE_NONE << SWITCH_TYPE_ON << SWITCH_TYPE_OFF << SWITCH_TYPE_TIMER_MODE;
|
||||
|
||||
int rawIdxAdj = 0;
|
||||
const Board::Type board = getCurrentBoard();
|
||||
int i = (count < 0 ? count : 1);
|
||||
const int maxCount = (i < 0 ? 0 : count + i);
|
||||
|
||||
// handle exceptions in RawSwitch() index values
|
||||
if (rawSwitchIndexBaseZeroTypes.contains(type))
|
||||
rawIdxAdj = -1;
|
||||
|
||||
for ( ; i < maxCount; ++i) {
|
||||
if (generalSettings) {
|
||||
if (type == SWITCH_TYPE_SWITCH && IS_HORUS_OR_TARANIS(board) && !generalSettings->switchPositionAllowedTaranis(abs(i)))
|
||||
continue;
|
||||
if (type == SWITCH_TYPE_MULTIPOS_POT) {
|
||||
int pot = div(abs(i) - 1, getCurrentFirmware()->getCapability(MultiposPotsPositions)).quot;
|
||||
if (!generalSettings->isPotAvailable(pot) || generalSettings->potConfig[pot] != Board::POT_MULTIPOS_SWITCH)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
RawSwitch rs(type, i + rawIdxAdj);
|
||||
QStandardItem * modelItem = new QStandardItem(rs.toString(board, generalSettings, modelData));
|
||||
modelItem->setData(rs.toValue(), Qt::UserRole);
|
||||
appendRow(modelItem);
|
||||
}
|
||||
}
|
||||
|
||||
void RawSwitchItemModel::update()
|
||||
{
|
||||
for (int i=0; i<rowCount(); i++) {
|
||||
QStandardItem * modelItem = item(i, 0);
|
||||
RawSwitch swtch(modelItem->data(Qt::UserRole).toInt());
|
||||
modelItem->setText(swtch.toString(getCurrentBoard(), generalSettings, modelData));
|
||||
}
|
||||
}
|
||||
|
||||
RawSwitchFilterItemModel::RawSwitchFilterItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, SwitchContext context):
|
||||
generalSettings(generalSettings),
|
||||
modelData(modelData),
|
||||
context(context),
|
||||
parent(new RawSwitchItemModel(generalSettings, modelData))
|
||||
{
|
||||
setSourceModel(parent);
|
||||
setDynamicSortFilter(false);
|
||||
}
|
||||
|
||||
bool RawSwitchFilterItemModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||
{
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
RawSwitch swtch(sourceModel()->data(index, Qt::UserRole).toInt());
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_FLIGHT_MODE && (context == MixesContext || context == GlobalFunctionsContext))
|
||||
return false;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_VIRTUAL && context == GlobalFunctionsContext)
|
||||
return false;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_TIMER_MODE && context != TimersContext)
|
||||
return false;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_NONE && context == TimersContext)
|
||||
return false;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_SENSOR && context == GlobalFunctionsContext)
|
||||
return false;
|
||||
|
||||
if ((swtch.type == SWITCH_TYPE_ON || swtch.type == SWITCH_TYPE_ONE) && (context != SpecialFunctionsContext && context != GlobalFunctionsContext))
|
||||
return false;
|
||||
|
||||
if (!modelData->isAvailable(swtch))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RawSwitchFilterItemModel::update()
|
||||
{
|
||||
parent->update();
|
||||
invalidate();
|
||||
}
|
58
companion/src/modeledit/switchitemmodel.h
Normal file
58
companion/src/modeledit/switchitemmodel.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 <QStandardItemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "radiodata.h"
|
||||
|
||||
enum SwitchContext
|
||||
{
|
||||
LogicalSwitchesContext,
|
||||
SpecialFunctionsContext,
|
||||
GlobalFunctionsContext,
|
||||
TimersContext,
|
||||
MixesContext
|
||||
};
|
||||
|
||||
class RawSwitchItemModel: public QStandardItemModel {
|
||||
public:
|
||||
RawSwitchItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData);
|
||||
void update();
|
||||
|
||||
protected:
|
||||
void add(const RawSwitchType & type, int count);
|
||||
|
||||
const GeneralSettings * generalSettings;
|
||||
const ModelData * modelData;
|
||||
};
|
||||
|
||||
class RawSwitchFilterItemModel: public QSortFilterProxyModel {
|
||||
public:
|
||||
RawSwitchFilterItemModel(const GeneralSettings * const generalSettings = NULL, const ModelData * const modelData = NULL, SwitchContext context = LogicalSwitchesContext);
|
||||
void update();
|
||||
|
||||
protected:
|
||||
const GeneralSettings * generalSettings;
|
||||
const ModelData * modelData;
|
||||
SwitchContext context;
|
||||
RawSwitchItemModel * parent;
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||
};
|
|
@ -250,7 +250,9 @@ enum RawSwitchType {
|
|||
SWITCH_TYPE_OFF,
|
||||
SWITCH_TYPE_ONE,
|
||||
SWITCH_TYPE_FLIGHT_MODE,
|
||||
SWITCH_TYPE_TIMER_MODE
|
||||
SWITCH_TYPE_TIMER_MODE,
|
||||
SWITCH_TYPE_TELEMETRY,
|
||||
SWITCH_TYPE_SENSOR,
|
||||
};
|
||||
|
||||
class RawSwitch {
|
||||
|
@ -278,7 +280,7 @@ class RawSwitch {
|
|||
return index >= 0 ? (type * 256 + index) : -(type * 256 - index);
|
||||
}
|
||||
|
||||
QString toString(Board::Type board = Board::BOARD_UNKNOWN, const GeneralSettings * const generalSettings = NULL) const;
|
||||
QString toString(Board::Type board = Board::BOARD_UNKNOWN, const GeneralSettings * const generalSettings = NULL, const ModelData * const modelData = NULL) const;
|
||||
|
||||
bool operator== ( const RawSwitch& other) {
|
||||
return (this->type == other.type) && (this->index == other.index);
|
||||
|
@ -1110,6 +1112,8 @@ class ModelData {
|
|||
|
||||
int getChannelsMax(bool forceExtendedLimits=false) const;
|
||||
|
||||
bool isAvailable(const RawSwitch & swtch) const;
|
||||
|
||||
protected:
|
||||
void removeGlobalVar(int & var);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue