Skip to content
Merged
5 changes: 3 additions & 2 deletions companion/src/firmwares/edgetx/yaml_generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Node convert<GeneralSettings>::encode(const GeneralSettings& rhs)
node["noJitterFilter"] = (int)rhs.noJitterFilter;
node["disableRtcWarning"] = (int)rhs.rtcCheckDisable; // TODO: verify
node["keysBacklight"] = (int)rhs.keysBacklight;
node["rotEncDirection"] = (int)rhs.rotEncDirection;
node["rotEncMode"] = (int)rhs.rotEncMode;
node["imperial"] = rhs.imperial;
node["ttsLanguage"] = rhs.ttsLanguage;
node["beepVolume"] = rhs.beepVolume + 2;
Expand Down Expand Up @@ -396,7 +396,8 @@ bool convert<GeneralSettings>::decode(const Node& node, GeneralSettings& rhs)
node["noJitterFilter"] >> rhs.noJitterFilter; // new, but don't write old
node["disableRtcWarning"] >> rhs.rtcCheckDisable; // TODO: verify
node["keysBacklight"] >> rhs.keysBacklight;
node["rotEncDirection"] >> rhs.rotEncDirection;
node["rotEncDirection"] >> rhs.rotEncMode; // PR2045: read old name and
node["rotEncMode"] >> rhs.rotEncMode; // new, but don't write old
node["imperial"] >> rhs.imperial;
node["ttsLanguage"] >> rhs.ttsLanguage;
node["beepVolume"] >> ioffset_int(rhs.beepVolume, 2);
Expand Down
2 changes: 1 addition & 1 deletion companion/src/firmwares/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class GeneralSettings {
bool noJitterFilter;
bool rtcCheckDisable;
bool keysBacklight;
bool rotEncDirection;
unsigned int rotEncMode;
unsigned int imperial;
char ttsLanguage[TTS_LANGUAGE_LEN + 1];
int beepVolume;
Expand Down
6 changes: 3 additions & 3 deletions companion/src/firmwares/opentx/opentxeeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3035,11 +3035,10 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type
internalField.Append(new BoolField<1>(this, generalData.rtcCheckDisable));
if (IS_JUMPER_T18(board)) {
internalField.Append(new BoolField<1>(this, generalData.keysBacklight));
internalField.Append(new BoolField<1>(this, generalData.rotEncDirection));
internalField.Append(new SpareBitsField<1>(this));
}
else {
internalField.Append(new SpareBitsField<1>(this));
internalField.Append(new BoolField<1>(this, generalData.rotEncDirection));
internalField.Append(new SpareBitsField<2>(this));
}

for (int i=0; i<4; i++) {
Expand Down Expand Up @@ -3350,6 +3349,7 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, Board::Type

if (version >= 220) {
internalField.Append(new SignedField<2>(this, generalData.uartSampleMode, "Uart Sample Mode"));
internalField.Append(new UnsignedField<2>(this, generalData.rotEncMode));
//internalField.Append(new SpareBitsField<6>(this)); // may need padding to end of 8 byte boundary
}
}
Expand Down
31 changes: 25 additions & 6 deletions companion/src/generaledit/generalsetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ ui(new Ui::GeneralSetup)
}

if (!firmware->getCapability(RotaryEncoderNavigation)) {
ui->invertRotary_CB->hide();
ui->invertRotary_label->hide();
ui->rotEncMode_CB->hide();
ui->rotEncMode_label->hide();
}
else {
ui->invertRotary_CB->setChecked(generalSettings.rotEncDirection);
populateRotEncModeCB();
}

if (!firmware->getCapability(HasPxxCountry)) {
Expand Down Expand Up @@ -483,10 +483,29 @@ void GeneralSetupPanel::on_faimode_CB_stateChanged(int)
emit modified();
}

void GeneralSetupPanel::on_invertRotary_CB_stateChanged(int)
void GeneralSetupPanel::populateRotEncModeCB()
{
generalSettings.rotEncDirection = ui->invertRotary_CB->isChecked();
emit modified();
QComboBox * b = ui->rotEncMode_CB;
QString strings[] = { tr("Normal"), tr("Inverted"), tr("Vertical Inverted, Horizontal Normal"), tr("Vertical Inverted, Horizontal Alternate") };
int itemCount = 4;

if (Boards::getCapability(firmware->getBoard(), Board::HasColorLcd)) {
itemCount = 2;
}

b->clear();
for (uint8_t i=0; i < itemCount; i++) {
b->addItem(strings[i], 0);
}
b->setCurrentIndex(generalSettings.rotEncMode);
}

void GeneralSetupPanel::on_rotEncMode_CB_currentIndexChanged(int index)
{
if (!lock) {
generalSettings.rotEncMode = index;
emit modified();
}
}

void GeneralSetupPanel::on_speakerPitchSB_editingFinished()
Expand Down
3 changes: 2 additions & 1 deletion companion/src/generaledit/generalsetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GeneralSetupPanel : public GeneralPanel
void on_countrycode_CB_currentIndexChanged(int index);
void on_units_CB_currentIndexChanged(int index);
void on_faimode_CB_stateChanged(int );
void on_invertRotary_CB_stateChanged(int);
void on_rotEncMode_CB_currentIndexChanged(int index);
void on_speakerPitchSB_editingFinished();
void on_timezoneSB_editingFinished();
void on_adjustRTC_stateChanged(int);
Expand Down Expand Up @@ -100,6 +100,7 @@ class GeneralSetupPanel : public GeneralPanel
void populateBacklightCB();
void populateVoiceLangCB();
void populateRotEncCB(int reCount);
void populateRotEncModeCB();
void updateVarioPitchRange();
};

Expand Down
13 changes: 3 additions & 10 deletions companion/src/generaledit/generalsetup.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1146,21 +1146,14 @@ p, li { white-space: pre-wrap; }
<widget class="QComboBox" name="re_CB"/>
</item>
<item row="21" column="0">
<widget class="QLabel" name="invertRotary_label">
<widget class="QLabel" name="rotEncMode_label">
<property name="text">
<string>Invert Rotary</string>
<string>Rotary Encoder Mode</string>
</property>
</widget>
</item>
<item row="21" column="1">
<widget class="QCheckBox" name="invertRotary_CB">
<property name="toolTip">
<string>Invert the direction of the rotary encoder</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QComboBox" name="rotEncMode_CB"/>
</item>
</layout>
</item>
Expand Down
12 changes: 8 additions & 4 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ PACK(struct TrainerData {
#if defined(BUZZER)
#define BUZZER_FIELD int8_t buzzerMode:2 // -2=quiet, -1=only alarms, 0=no keys, 1=all (only used on AVR radios without audio hardware)
#else
#define BUZZER_FIELD int8_t spare1:2 SKIP
#define BUZZER_FIELD int8_t spare2:2 SKIP
#endif

PACK(struct RadioData {
Expand All @@ -830,7 +830,7 @@ PACK(struct RadioData {
int8_t antennaMode:2 ENUM(AntennaModes);
uint8_t disableRtcWarning:1;
uint8_t keysBacklight:1;
int8_t rotEncDirection:1;
NOBACKUP(uint8_t spare1:1 SKIP);
NOBACKUP(uint8_t internalModule ENUM(ModuleType));
NOBACKUP(TrainerData trainer);
NOBACKUP(uint8_t view); // index of view in main screen
Expand Down Expand Up @@ -899,13 +899,17 @@ PACK(struct RadioData {

char ownerRegistrationID[PXX2_LEN_REGISTRATION_ID];

CUST_ATTR(rotEncDirection, r_rotEncDirection, nullptr);
NOBACKUP(uint8_t rotEncMode:2);

NOBACKUP(int8_t uartSampleMode:2); // See UartSampleModes

#if defined(STICK_DEAD_ZONE)
NOBACKUP(uint8_t stickDeadZone:3);
NOBACKUP(uint8_t spare2:3 SKIP);
#else
NOBACKUP(uint8_t spare2:6 SKIP);
NOBACKUP(uint8_t stickDeadZoneSpare:3 SKIP);
#endif
NOBACKUP(uint8_t spare4:1 SKIP);

#if defined(IMU)
NOBACKUP(int8_t imuMax);
Expand Down
24 changes: 20 additions & 4 deletions radio/src/gui/128x64/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum {
ITEM_RADIO_SETUP_USB_MODE,
CASE_JACK_DETECT(ITEM_RADIO_SETUP_JACK_MODE)
ITEM_RADIO_SETUP_RX_CHANNEL_ORD,
CASE_ROTARY_ENCODER(ITEM_RADIO_SETUP_ROTARY_INVERSE)
CASE_ROTARY_ENCODER(ITEM_RADIO_SETUP_ROTARY_ENC_MODE)
ITEM_RADIO_SETUP_STICK_MODE_LABELS,
ITEM_RADIO_SETUP_STICK_MODE,
ITEM_RADIO_SETUP_MAX
Expand Down Expand Up @@ -137,7 +137,7 @@ void menuRadioSetup(event_t event)
#endif

uint8_t old_editMode = s_editMode;

MENU(STR_RADIO_SETUP, menuTabGeneral, MENU_RADIO_SETUP, HEADER_LINE+ITEM_RADIO_SETUP_MAX, {
HEADER_LINE_COLUMNS CASE_RTCLOCK(2) CASE_RTCLOCK(2) CASE_BATTGRAPH(1)
LABEL(SOUND), CASE_AUDIO(0)
Expand Down Expand Up @@ -181,6 +181,9 @@ void menuRadioSetup(event_t event)

if (event == EVT_ENTRY) {
reusableBuffer.generalSettings.stickMode = g_eeGeneral.stickMode;
#if defined(ROTARY_ENCODER_NAVIGATION)
reusableBuffer.generalSettings.rotaryEncoderMode = g_eeGeneral.rotEncMode;
#endif
}

uint8_t sub = menuVerticalPosition - HEADER_LINE;
Expand Down Expand Up @@ -661,8 +664,21 @@ void menuRadioSetup(event_t event)
break;

#if defined(ROTARY_ENCODER_NAVIGATION)
case ITEM_RADIO_SETUP_ROTARY_INVERSE:
g_eeGeneral.rotEncDirection = editCheckBox(g_eeGeneral.rotEncDirection, RADIO_SETUP_2ND_COLUMN, y, STR_INVERT_ROTARY, attr, event);
case ITEM_RADIO_SETUP_ROTARY_ENC_MODE:
lcdDrawTextAlignedLeft(y, STR_ROTARY_ENC_MODE);
lcdDrawTextAtIndex(RADIO_SETUP_2ND_COLUMN, y, STR_ROTARY_ENC_OPT,
reusableBuffer.generalSettings.rotaryEncoderMode,
attr);
if (attr && s_editMode > 0) {
CHECK_INCDEC_GENVAR(event,
reusableBuffer.generalSettings.rotaryEncoderMode,
ROTARY_ENCODER_MODE_NORMAL,
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT);
} else if (reusableBuffer.generalSettings.rotaryEncoderMode !=
g_eeGeneral.rotEncMode) {
g_eeGeneral.rotEncMode =
reusableBuffer.generalSettings.rotaryEncoderMode;
}
break;
#endif

Expand Down
24 changes: 20 additions & 4 deletions radio/src/gui/212x64/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ enum MenuRadioSetupItems {
ITEM_RADIO_SETUP_SWITCHES_DELAY,
ITEM_RADIO_SETUP_USB_MODE,
ITEM_RADIO_SETUP_RX_CHANNEL_ORD,
CASE_ROTARY_ENCODER(ITEM_RADIO_SETUP_ROTARY_INVERSE)
CASE_ROTARY_ENCODER(ITEM_RADIO_SETUP_ROTARY_ENC_MODE)
ITEM_RADIO_SETUP_STICK_MODE_LABELS,
ITEM_RADIO_SETUP_STICK_MODE,
ITEM_RADIO_SETUP_MAX
Expand Down Expand Up @@ -124,7 +124,7 @@ void menuRadioSetup(event_t event)
#endif

uint8_t old_editMode = s_editMode;

MENU(STR_RADIO_SETUP, menuTabGeneral, MENU_RADIO_SETUP, ITEM_RADIO_SETUP_MAX, {
2, // date
2, // time
Expand Down Expand Up @@ -183,6 +183,9 @@ void menuRadioSetup(event_t event)

if (event == EVT_ENTRY) {
reusableBuffer.generalSettings.stickMode = g_eeGeneral.stickMode;
#if defined(ROTARY_ENCODER_NAVIGATION)
reusableBuffer.generalSettings.rotaryEncoderMode = g_eeGeneral.rotEncMode;
#endif
}

int sub = menuVerticalPosition;
Expand Down Expand Up @@ -591,8 +594,21 @@ void menuRadioSetup(event_t event)
break;

#if defined(ROTARY_ENCODER_NAVIGATION)
case ITEM_RADIO_SETUP_ROTARY_INVERSE:
g_eeGeneral.rotEncDirection = editCheckBox(g_eeGeneral.rotEncDirection, RADIO_SETUP_2ND_COLUMN, y, STR_INVERT_ROTARY, attr, event);
case ITEM_RADIO_SETUP_ROTARY_ENC_MODE:
lcdDrawTextAlignedLeft(y, STR_ROTARY_ENC_MODE);
lcdDrawTextAtIndex(RADIO_SETUP_2ND_COLUMN, y, STR_ROTARY_ENC_OPT,
reusableBuffer.generalSettings.rotaryEncoderMode,
attr);
if (attr && s_editMode > 0) {
CHECK_INCDEC_GENVAR(event,
reusableBuffer.generalSettings.rotaryEncoderMode,
ROTARY_ENCODER_MODE_NORMAL,
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT);
} else if (reusableBuffer.generalSettings.rotaryEncoderMode !=
g_eeGeneral.rotEncMode) {
g_eeGeneral.rotEncMode =
reusableBuffer.generalSettings.rotaryEncoderMode;
}
break;
#endif

Expand Down
6 changes: 4 additions & 2 deletions radio/src/gui/colorlcd/radio_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,10 @@ void RadioSetupPage::build(FormWindow * window)

#if defined(ROTARY_ENCODER_NAVIGATION)
line = window->newLine(&grid);
new StaticText(line, rect_t{}, STR_INVERT_ROTARY, 0, COLOR_THEME_PRIMARY1);
new CheckBox(line, rect_t{}, GET_SET_DEFAULT(g_eeGeneral.rotEncDirection));
new StaticText(line, rect_t{}, STR_ROTARY_ENC_MODE, 0, COLOR_THEME_PRIMARY1);
new Choice(line, rect_t{}, STR_ROTARY_ENC_OPT, ROTARY_ENCODER_MODE_NORMAL,
ROTARY_ENCODER_MODE_INVERT_BOTH,
GET_SET_DEFAULT(g_eeGeneral.rotEncMode));
#endif

// RX channel order
Expand Down
14 changes: 13 additions & 1 deletion radio/src/gui/common/stdlcd/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,19 @@ const char * runPopupMenu(event_t event)
drawVerticalScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_DISPLAY_LINES * (FH+1), popupMenuOffset, popupMenuItemsCount, display_count);
}

switch (event) {
event_t eventTemp = event;

#if defined(ROTARY_ENCODER_NAVIGATION) && !defined(COLORLCD)
if (g_eeGeneral.rotEncMode >= ROTARY_ENCODER_MODE_INVERT_BOTH) {
if (eventTemp == EVT_ROTARY_LEFT) {
eventTemp = EVT_ROTARY_RIGHT;
} else if (eventTemp == EVT_ROTARY_RIGHT) {
eventTemp = EVT_ROTARY_LEFT;
}
}
#endif

switch (eventTemp) {
#if defined(ROTARY_ENCODER_NAVIGATION)
CASE_EVT_ROTARY_LEFT
#endif
Expand Down
29 changes: 24 additions & 5 deletions radio/src/gui/navigation/navigation_9x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,16 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
case EVT_KEY_FIRST(KEY_DOWN):
if (s_editMode>0) break;
do {
#if defined(ROTARY_ENCODER_NAVIGATION)
if (g_eeGeneral.rotEncMode >=
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM) {
DEC(l_posVert, 0, maxrow);
} else {
INC(l_posVert, 0, maxrow);
}
#else
INC(l_posVert, 0, maxrow);
#endif
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));

#if defined(ROTARY_ENCODER_NAVIGATION)
Expand All @@ -368,12 +377,13 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
if (l_posHorz > 0) {
l_posHorz--;
break;
}
else if (IS_ROTARY_LEFT(event) && s_editMode == 0) {
} else if (IS_ROTARY_LEFT(event) && s_editMode == 0) {
l_posHorz = 0xff;
}
else {
l_posHorz = maxcol;
} else {
l_posHorz =
g_eeGeneral.rotEncMode == ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_ALT
? 0
: maxcol;
break;
}
#else
Expand All @@ -388,7 +398,16 @@ void check(event_t event, uint8_t curr, const MenuHandlerFunc *menuTab, uint8_t
if (s_editMode>0) break;

do {
#if defined(ROTARY_ENCODER_NAVIGATION)
if (g_eeGeneral.rotEncMode >=
ROTARY_ENCODER_MODE_INVERT_VERT_HORZ_NORM) {
INC(l_posVert, 0, maxrow);
} else {
DEC(l_posVert, 0, maxrow);
}
#else
DEC(l_posVert, 0, maxrow);
#endif
} while (CURSOR_NOT_ALLOWED_IN_ROW(l_posVert));

#if defined(ROTARY_ENCODER_NAVIGATION)
Expand Down
Loading