1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-18 05:45:21 +03:00
Failsafe settings on individual channels
This commit is contained in:
bsongis 2015-05-11 06:43:26 +02:00
parent 218e6a77ba
commit 059ea49f2f
7 changed files with 156 additions and 43 deletions

View file

@ -119,6 +119,9 @@ void TimerPanel::on_name_editingFinished()
/******************************************************************************/ /******************************************************************************/
#define FAILSAFE_CHANNEL_HOLD 2000
#define FAILSAFE_CHANNEL_NOPULSE 2001
ModulePanel::ModulePanel(QWidget *parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx): ModulePanel::ModulePanel(QWidget *parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx):
ModelPanel(parent, model, generalSettings, firmware), ModelPanel(parent, model, generalSettings, firmware),
module(module), module(module),
@ -170,20 +173,29 @@ ModulePanel::ModulePanel(QWidget *parent, ModelData & model, ModuleData & module
} }
if (firmware->getCapability(HasFailsafe)) { if (firmware->getCapability(HasFailsafe)) {
for (int i=0; i<16; i++) { for (int i=0; i<maxChannels; i++) {
QLabel * label = new QLabel(this); QLabel * label = new QLabel(this);
label->setText(QString::number(i+1)); label->setText(QString::number(i+1));
QComboBox * combo = new QComboBox(this);
combo->setProperty("index", i);
combo->addItem(tr("Value"), 0);
combo->addItem(tr("Hold"), FAILSAFE_CHANNEL_HOLD);
combo->addItem(tr("No Pulse"), FAILSAFE_CHANNEL_NOPULSE);
QDoubleSpinBox * spinbox = new QDoubleSpinBox(this); QDoubleSpinBox * spinbox = new QDoubleSpinBox(this);
spinbox->setMinimumSize(QSize(20, 0)); spinbox->setMinimumSize(QSize(20, 0));
spinbox->setRange(-150, 150); spinbox->setRange(-150, 150);
spinbox->setSingleStep(0.1); spinbox->setSingleStep(0.1);
spinbox->setDecimals(1); spinbox->setDecimals(1);
spinbox->setValue(((double)module.failsafeChannels[i]*100)/1024);
label->setProperty("index", i); label->setProperty("index", i);
spinbox->setProperty("index", i); spinbox->setProperty("index", i);
failsafeSpins << spinbox; failsafeSpins << spinbox;
ui->failsafesLayout->addWidget(label, 2*(i/8), i%8, Qt::AlignHCenter); ui->failsafesLayout->addWidget(label, 3*(i/8), i%8, Qt::AlignHCenter);
ui->failsafesLayout->addWidget(spinbox, 1+2*(i/8), i%8, Qt::AlignHCenter); ui->failsafesLayout->addWidget(combo, 1+3*(i/8), i%8, Qt::AlignHCenter);
ui->failsafesLayout->addWidget(spinbox, 2+3*(i/8), i%8, Qt::AlignHCenter);
failsafeGroups[i].combo = combo;
failsafeGroups[i].spinbox = spinbox;
updateFailsafe(i);
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(onFailsafeComboIndexChanged(int)));
connect(spinbox, SIGNAL(valueChanged(double)), this, SLOT(onFailsafeSpinChanged(double))); connect(spinbox, SIGNAL(valueChanged(double)), this, SLOT(onFailsafeSpinChanged(double)));
} }
} }
@ -370,12 +382,46 @@ void ModulePanel::on_failsafeMode_currentIndexChanged(int value)
void ModulePanel::onFailsafeSpinChanged(double value) void ModulePanel::onFailsafeSpinChanged(double value)
{ {
if (!lock) { if (!lock) {
int index = sender()->property("index").toInt(); int channel = sender()->property("index").toInt();
module.failsafeChannels[index] = (value*1024)/100; module.failsafeChannels[channel] = (value*1024)/100;
emit modified(); emit modified();
} }
} }
void ModulePanel::onFailsafeComboIndexChanged(int index)
{
if (!lock) {
lock = true;
int channel = sender()->property("index").toInt();
module.failsafeChannels[channel] = ((QComboBox *)sender())->itemData(index).toInt();
updateFailsafe(channel);
emit modified();
lock = false;
}
}
void ModulePanel::updateFailsafe(int channel)
{
int failsafeValue = module.failsafeChannels[channel];
QComboBox * combo = failsafeGroups[channel].combo;
QDoubleSpinBox * spinbox = failsafeGroups[channel].spinbox;
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
combo->setCurrentIndex(1);
spinbox->setEnabled(false);
spinbox->setValue(0);
}
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
combo->setCurrentIndex(2);
spinbox->setEnabled(false);
spinbox->setValue(0);
}
else {
combo->setCurrentIndex(0);
spinbox->setEnabled(true);
spinbox->setValue(((double)failsafeValue*100)/1024);
}
}
/******************************************************************************/ /******************************************************************************/
SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware): SetupPanel::SetupPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):

View file

@ -40,14 +40,23 @@ class TimerPanel : public ModelPanel
class ModulePanel : public ModelPanel class ModulePanel : public ModelPanel
{ {
static const int maxChannels = 16;
struct ChannelFailsafeWidgetsGroup {
QComboBox * combo;
QDoubleSpinBox * spinbox;
};
Q_OBJECT Q_OBJECT
public: public:
ModulePanel(QWidget *parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx); ModulePanel(QWidget *parent, ModelData & model, ModuleData & module, GeneralSettings & generalSettings, Firmware * firmware, int moduleIdx);
virtual ~ModulePanel(); virtual ~ModulePanel();
virtual void update(); virtual void update();
protected:
void updateFailsafe(int channel);
private slots: private slots:
void on_trainerMode_currentIndexChanged(int index); void on_trainerMode_currentIndexChanged(int index);
void on_protocol_currentIndexChanged(int index); void on_protocol_currentIndexChanged(int index);
@ -59,6 +68,7 @@ class ModulePanel : public ModelPanel
void on_ppmFrameLength_editingFinished(); void on_ppmFrameLength_editingFinished();
void on_rxNumber_editingFinished(); void on_rxNumber_editingFinished();
void on_failsafeMode_currentIndexChanged(int value); void on_failsafeMode_currentIndexChanged(int value);
void onFailsafeComboIndexChanged(int index);
void onFailsafeSpinChanged(double value); void onFailsafeSpinChanged(double value);
private: private:
@ -66,6 +76,7 @@ class ModulePanel : public ModelPanel
int moduleIdx; int moduleIdx;
Ui::Module *ui; Ui::Module *ui;
QVector<QDoubleSpinBox *> failsafeSpins; QVector<QDoubleSpinBox *> failsafeSpins;
ChannelFailsafeWidgetsGroup failsafeGroups[maxChannels];
}; };
class SetupPanel : public ModelPanel class SetupPanel : public ModelPanel

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 B

After

Width:  |  Height:  |  Size: 346 B

Before After
Before After

View file

@ -187,7 +187,7 @@ void lcd_putcAtt(coord_t x, coord_t y, const unsigned char c, LcdFlags flags)
lcdPutPattern(x, y, q, 5, 6, flags); lcdPutPattern(x, y, q, 5, 6, flags);
} }
else if (fontsize == TINSIZE) { else if (fontsize == TINSIZE) {
q = &font_3x5[((uint16_t)c-0x2d)*3]; q = &font_3x5[((uint16_t)c-0x20)*3];
lcdPutPattern(x, y, q, 3, 5, flags); lcdPutPattern(x, y, q, 3, 5, flags);
} }
#if defined(BOLD_FONT) #if defined(BOLD_FONT)

View file

@ -104,7 +104,7 @@ enum menuModelSetupItems {
#define MODEL_SETUP_2ND_COLUMN (LCD_W-17*FW-MENUS_SCROLLBAR_WIDTH-1) #define MODEL_SETUP_2ND_COLUMN (LCD_W-17*FW-MENUS_SCROLLBAR_WIDTH-1)
#define MODEL_SETUP_BIND_OFS 3*FW-2 #define MODEL_SETUP_BIND_OFS 3*FW-2
#define MODEL_SETUP_RANGE_OFS 7*FW #define MODEL_SETUP_RANGE_OFS 7*FW
#define MODEL_SETUP_SET_FAILSAFE_OFS 10*FW #define MODEL_SETUP_SET_FAILSAFE_OFS 10*FW-2
void copySelection(char *dst, const char *src, uint8_t size) void copySelection(char *dst, const char *src, uint8_t size)
{ {
@ -778,12 +778,27 @@ void menuModelFailsafe(uint8_t event)
bool newLongNames = false; bool newLongNames = false;
uint8_t ch = 0; uint8_t ch = 0;
if (event == EVT_KEY_LONG(KEY_ENTER) && s_editMode) { if (event == EVT_KEY_LONG(KEY_ENTER)) {
s_noHi = NO_HI_LEN; killEvents(event);
g_model.moduleData[g_moduleIdx].failsafeChannels[m_posVert] = channelOutputs[m_posVert]; event = 0;
eeDirty(EE_MODEL); if (s_editMode) {
AUDIO_WARNING1(); g_model.moduleData[g_moduleIdx].failsafeChannels[m_posVert] = channelOutputs[m_posVert];
SEND_FAILSAFE_NOW(g_moduleIdx); eeDirty(EE_MODEL);
AUDIO_WARNING1();
SEND_FAILSAFE_NOW(g_moduleIdx);
}
else {
int16_t & failsafe = g_model.moduleData[g_moduleIdx].failsafeChannels[m_posVert];
if (failsafe < FAILSAFE_CHANNEL_HOLD)
failsafe = FAILSAFE_CHANNEL_HOLD;
else if (failsafe == FAILSAFE_CHANNEL_HOLD)
failsafe = FAILSAFE_CHANNEL_NOPULSE;
else
failsafe = channelOutputs[m_posVert];
eeDirty(EE_MODEL);
AUDIO_WARNING1();
SEND_FAILSAFE_NOW(g_moduleIdx);
}
} }
SIMPLE_SUBMENU_NOTITLE(NUM_CHNOUT); SIMPLE_SUBMENU_NOTITLE(NUM_CHNOUT);
@ -795,28 +810,30 @@ void menuModelFailsafe(uint8_t event)
// Column separator // Column separator
lcd_vline(LCD_W/2, FH, LCD_H-FH); lcd_vline(LCD_W/2, FH, LCD_H-FH);
if (m_posVert > 16) { if (m_posVert >= 16) {
ch = 16; ch = 16;
} }
lcd_putsCenter(0*FH, FAILSAFESET); lcd_putsCenter(0*FH, FAILSAFESET);
lcd_invert_line(0); lcd_invert_line(0);
unsigned int lim = g_model.extendedLimits ? 640*2 : 512*2;
for (uint8_t col=0; col<2; col++) { for (uint8_t col=0; col<2; col++) {
coord_t x = col*COL_W+1; coord_t x = col*COL_W+1;
// Channels // Channels
for (uint8_t line=0; line<8; line++) { for (uint8_t line=0; line<8; line++) {
coord_t y = 9+line*7; coord_t y = 9+line*7;
int32_t val; int32_t channelValue = channelOutputs[ch];
int32_t failsafeValue = 0;
bool failsafeEditable = false;
uint8_t ofs = (col ? 0 : 1); uint8_t ofs = (col ? 0 : 1);
if (ch < g_model.moduleData[g_moduleIdx].channelsStart || ch >= NUM_CHANNELS(g_moduleIdx) + g_model.moduleData[g_moduleIdx].channelsStart) if (ch >= g_model.moduleData[g_moduleIdx].channelsStart && ch < NUM_CHANNELS(g_moduleIdx) + g_model.moduleData[g_moduleIdx].channelsStart) {
val = 0; failsafeValue = g_model.moduleData[g_moduleIdx].failsafeChannels[8*col+line];
else if (s_editMode && m_posVert == ch) failsafeEditable = true;
val = channelOutputs[ch]; }
else
val = g_model.moduleData[g_moduleIdx].failsafeChannels[8*col+line];
// Channel name if present, number if not // Channel name if present, number if not
uint8_t lenLabel = ZLEN(g_model.limitData[ch].name); uint8_t lenLabel = ZLEN(g_model.limitData[ch].name);
@ -831,31 +848,53 @@ void menuModelFailsafe(uint8_t event)
// Value // Value
LcdFlags flags = TINSIZE; LcdFlags flags = TINSIZE;
if (m_posVert == ch && !s_noHi) { if (m_posVert == ch) {
flags |= INVERS; flags |= INVERS;
if (s_editMode) if (s_editMode) {
flags |= BLINK; if (!failsafeEditable || failsafeValue == FAILSAFE_CHANNEL_HOLD || failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
s_editMode = 0;
}
else {
flags |= BLINK;
CHECK_INCDEC_MODELVAR(event, g_model.moduleData[g_moduleIdx].failsafeChannels[8*col+line], -lim, +lim);
}
}
} }
#if defined(PPM_UNIT_US)
uint8_t wbar = (longNames ? SLIDER_W-10 : SLIDER_W); #if defined(PPM_UNIT_PERCENT_PREC1)
lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, PPM_CH_CENTER(ch)+val/2, flags);
#elif defined(PPM_UNIT_PERCENT_PREC1)
uint8_t wbar = (longNames ? SLIDER_W-16 : SLIDER_W-6); uint8_t wbar = (longNames ? SLIDER_W-16 : SLIDER_W-6);
lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, calcRESXto1000(val), PREC1|flags);
#else #else
uint8_t wbar = (longNames ? SLIDER_W-10 : SLIDER_W); uint8_t wbar = (longNames ? SLIDER_W-10 : SLIDER_W);
lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, calcRESXto1000(val)/10, flags);
#endif #endif
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
lcd_putsAtt(x+COL_W-4-wbar-ofs-16, y, "HOLD", flags);
failsafeValue = 0;
}
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
lcd_putsAtt(x+COL_W-4-wbar-ofs-16, y, "NONE", flags);
failsafeValue = 0;
}
else {
#if defined(PPM_UNIT_US)
lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, PPM_CH_CENTER(ch)+failsafeValue/2, flags);
#elif defined(PPM_UNIT_PERCENT_PREC1)
lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, calcRESXto1000(failsafeValue), PREC1|flags);
#else
lcd_outdezAtt(x+COL_W-4-wbar-ofs, y, calcRESXto1000(failsafeValue)/10, flags);
#endif
}
// Gauge // Gauge
lcd_rect(x+COL_W-3-wbar-ofs, y, wbar+1, 6); lcd_rect(x+COL_W-3-wbar-ofs, y, wbar+1, 6);
uint16_t lim = g_model.extendedLimits ? 640*2 : 512*2; unsigned int lenChannel = limit((uint8_t)1, uint8_t((abs(channelValue) * wbar/2 + lim/2) / lim), uint8_t(wbar/2));
uint8_t len = limit((uint8_t)1, uint8_t((abs(val) * wbar/2 + lim/2) / lim), uint8_t(wbar/2)); unsigned int lenFailsafe = limit((uint8_t)1, uint8_t((abs(failsafeValue) * wbar/2 + lim/2) / lim), uint8_t(wbar/2));
coord_t x0 = (val>0) ? x+COL_W-ofs-3-wbar/2 : x+COL_W-ofs-2-wbar/2-len; coord_t xChannel = (channelValue>0) ? x+COL_W-ofs-3-wbar/2 : x+COL_W-ofs-2-wbar/2-lenChannel;
lcd_hline(x0, y+1, len); coord_t xFailsafe = (failsafeValue>0) ? x+COL_W-ofs-3-wbar/2 : x+COL_W-ofs-2-wbar/2-lenFailsafe;
lcd_hline(x0, y+2, len); lcd_hlineStip(xChannel, y+1, lenChannel, DOTTED, 0);
lcd_hline(x0, y+3, len); lcd_hlineStip(xChannel, y+2, lenChannel, DOTTED, 0);
lcd_hline(x0, y+4, len); lcd_hline(xFailsafe, y+3, lenFailsafe);
lcd_hline(xFailsafe, y+4, lenFailsafe);
ch++; ch++;
} }

View file

@ -406,6 +406,9 @@ enum BeeperMode {
#define EXTRA_GENERAL_FIELDS #define EXTRA_GENERAL_FIELDS
#endif #endif
#define FAILSAFE_CHANNEL_HOLD 2000
#define FAILSAFE_CHANNEL_NOPULSE 2001
#if defined(PCBSKY9X) && defined(REVX) #if defined(PCBSKY9X) && defined(REVX)
PACK(typedef struct { PACK(typedef struct {
int8_t rfProtocol; int8_t rfProtocol;

View file

@ -230,10 +230,24 @@ void setupPulsesPXX(unsigned int port)
chan = (i < sendUpperChannels ? 2048 : 0); chan = (i < sendUpperChannels ? 2048 : 0);
} }
else { else {
if (i < sendUpperChannels) if (i < sendUpperChannels) {
chan = limit(2049, PPM_CH_CENTER(8+g_model.moduleData[port].channelsStart+i) - PPM_CENTER + (g_model.moduleData[port].failsafeChannels[8+g_model.moduleData[port].channelsStart+i] * 512 / 682) + 3072, 4094); int16_t failsafeValue = g_model.moduleData[port].failsafeChannels[8+g_model.moduleData[port].channelsStart+i];
else if (failsafeValue == FAILSAFE_CHANNEL_HOLD)
chan = limit(1, PPM_CH_CENTER(g_model.moduleData[port].channelsStart+i) - PPM_CENTER + (g_model.moduleData[port].failsafeChannels[g_model.moduleData[port].channelsStart+i] * 512 / 682) + 1024, 2046); chan = 4095;
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE)
chan = 2048;
else
chan = limit(2049, PPM_CH_CENTER(8+g_model.moduleData[port].channelsStart+i) - PPM_CENTER + (failsafeValue * 512 / 682) + 3072, 4094);
}
else {
int16_t failsafeValue = g_model.moduleData[port].failsafeChannels[g_model.moduleData[port].channelsStart+i];
if (failsafeValue == FAILSAFE_CHANNEL_HOLD)
chan = 2047;
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE)
chan = 0;
else
chan = limit(1, PPM_CH_CENTER(g_model.moduleData[port].channelsStart+i) - PPM_CENTER + (failsafeValue * 512 / 682) + 1024, 2046);
}
} }
} }
else { else {