feat: stick inversion (#6394)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
This commit is contained in:
@@ -25,6 +25,11 @@
|
||||
|
||||
void menuRadioCalibration(event_t event)
|
||||
{
|
||||
if (reusableBuffer.calib.state == CALIB_FINISHED) {
|
||||
menuCalibrationState = CALIB_START;
|
||||
popMenu();
|
||||
}
|
||||
|
||||
check_submenu_simple(event, 0);
|
||||
title(STR_MENUCALIBRATION);
|
||||
menuCommonCalib(event);
|
||||
|
||||
@@ -49,6 +49,11 @@ void drawPotsBars()
|
||||
|
||||
void menuRadioCalibration(event_t event)
|
||||
{
|
||||
if (reusableBuffer.calib.state == CALIB_FINISHED) {
|
||||
menuCalibrationState = CALIB_START;
|
||||
popMenu();
|
||||
}
|
||||
|
||||
check_submenu_simple(event, 0);
|
||||
title(STR_MENUCALIBRATION);
|
||||
menuCommonCalib(event);
|
||||
|
||||
@@ -56,25 +56,34 @@ static const lv_coord_t pots_col_dsc[] = {LV_GRID_FR(13), LV_GRID_FR(7),
|
||||
|
||||
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
|
||||
|
||||
HWSticks::HWSticks(Window* parent) : Window(parent, rect_t{})
|
||||
HWSticks::HWSticks(Window* parent) : Window(parent, {0, 0, LV_PCT(100), LV_SIZE_CONTENT})
|
||||
{
|
||||
padAll(PAD_TINY);
|
||||
|
||||
FlexGridLayout grid(col_two_dsc, row_dsc, PAD_TINY);
|
||||
setFlexLayout();
|
||||
new StaticText(this, {S_NM_X, -PAD_TINY, 0, 0}, STR_NAME, COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
new StaticText(this, {S_INV_X, -PAD_TINY, 0, 0}, STR_MENU_INVERT, COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
|
||||
coord_t yo = EdgeTxStyles::STD_FONT_HEIGHT - PAD_TINY;
|
||||
|
||||
auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
|
||||
for (int i = 0; i < max_sticks; i++) {
|
||||
auto line = newLine(grid);
|
||||
new StaticText(line, rect_t{}, analogGetCanonicalName(ADC_INPUT_MAIN, i));
|
||||
new HWInputEdit(line, (char*)analogGetCustomLabel(ADC_INPUT_MAIN, i),
|
||||
LEN_ANA_NAME);
|
||||
new StaticText(this, {0, S_Y(i) + yo + PAD_MEDIUM, S_LBL_W, 0},
|
||||
analogGetCanonicalName(ADC_INPUT_MAIN, i));
|
||||
new HWInputEdit(this, (char*)analogGetCustomLabel(ADC_INPUT_MAIN, i),
|
||||
LEN_ANA_NAME, S_NM_X, S_Y(i) + yo);
|
||||
|
||||
new ToggleSwitch(
|
||||
this, {S_INV_X, S_Y(i) + yo, S_INV_W, 0},
|
||||
[=]() -> uint8_t { return (uint8_t)getStickInversion(i); },
|
||||
[=](int8_t newValue) {
|
||||
setStickInversion(i, newValue);
|
||||
SET_DIRTY();
|
||||
});
|
||||
}
|
||||
|
||||
#if defined(STICK_DEAD_ZONE)
|
||||
auto line = newLine(grid);
|
||||
new StaticText(line, rect_t{}, STR_DEAD_ZONE);
|
||||
auto dz = new Choice(line, rect_t{}, 0, 7,
|
||||
new StaticText(this, {0, S_Y(max_sticks) + yo + PAD_MEDIUM}, STR_DEAD_ZONE);
|
||||
auto dz = new Choice(this, {S_INV_X, S_Y(max_sticks) + yo}, 0, 7,
|
||||
GET_SET_DEFAULT(g_eeGeneral.stickDeadZone));
|
||||
dz->setTextHandler([](uint8_t value) {
|
||||
return std::to_string(value ? 2 << (value - 1) : 0);
|
||||
@@ -83,7 +92,7 @@ HWSticks::HWSticks(Window* parent) : Window(parent, rect_t{})
|
||||
}
|
||||
|
||||
HWPots::HWPots(Window* parent) :
|
||||
Window(parent, rect_t{0, 0, LV_PCT(100), LV_SIZE_CONTENT})
|
||||
Window(parent, {0, 0, LV_PCT(100), LV_SIZE_CONTENT})
|
||||
{
|
||||
padAll(PAD_TINY);
|
||||
|
||||
@@ -111,15 +120,14 @@ HWPots::HWPots(Window* parent) :
|
||||
// #if !defined(SIMU) && defined(RADIO_FAMILY_T16)
|
||||
// if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue;
|
||||
// #endif
|
||||
new StaticText(this,
|
||||
rect_t{0, P_Y(i) + yo + PAD_MEDIUM, P_LBL_W, 0},
|
||||
new StaticText(this, {0, P_Y(i) + yo + PAD_MEDIUM, P_LBL_W, 0},
|
||||
adcGetInputLabel(ADC_INPUT_FLEX, i));
|
||||
|
||||
new HWInputEdit(this, (char*)analogGetCustomLabel(ADC_INPUT_FLEX, i),
|
||||
LEN_ANA_NAME, P_NM_X, P_Y(i) + yo);
|
||||
|
||||
auto pot = new Choice(
|
||||
this, rect_t{P_TYP_X, P_Y(i) + P_OFST_Y + yo, P_TYP_W, 0},
|
||||
this, {P_TYP_X, P_Y(i) + P_OFST_Y + yo, P_TYP_W, 0},
|
||||
STR_POTTYPES, FLEX_NONE, FLEX_SWITCH,
|
||||
[=]() -> int { return getPotType(i); },
|
||||
[=](int newValue) {
|
||||
@@ -136,7 +144,7 @@ HWPots::HWPots(Window* parent) :
|
||||
pot->setAvailableHandler([=](int val) { return isPotTypeAvailable(val); });
|
||||
|
||||
auto tgl = new ToggleSwitch(
|
||||
this, rect_t{P_INV_X, P_Y(i) + yo, P_INV_W, 0},
|
||||
this, {P_INV_X, P_Y(i) + yo, P_INV_W, 0},
|
||||
[=]() -> uint8_t { return (uint8_t)getPotInversion(i); },
|
||||
[=](int8_t newValue) {
|
||||
setPotInversion(i, newValue);
|
||||
@@ -155,7 +163,7 @@ class SwitchDynamicLabel : public StaticText
|
||||
{
|
||||
public:
|
||||
SwitchDynamicLabel(Window* parent, uint8_t index, coord_t x, coord_t y, coord_t w) :
|
||||
StaticText(parent, rect_t{x, y, w, 0}, ""),
|
||||
StaticText(parent, {x, y, w, 0}, ""),
|
||||
index(index)
|
||||
{
|
||||
checkEvents();
|
||||
|
||||
@@ -33,6 +33,16 @@ class HWSticks : public Window
|
||||
{
|
||||
public:
|
||||
HWSticks(Window* parent);
|
||||
|
||||
// Absolute layout for Pots popup - due to performance issues with lv_textarea
|
||||
// in a flex layout
|
||||
static LAYOUT_VAL_SCALED(S_LBL_W, 60)
|
||||
static constexpr coord_t S_NM_X = S_LBL_W + PAD_SMALL;
|
||||
static LAYOUT_VAL_SCALED(S_NM_W, 64)
|
||||
static constexpr coord_t S_INV_X = S_NM_X + S_NM_W + PAD_LARGE * 3;
|
||||
static constexpr coord_t S_INV_W = ToggleSwitch::TOGGLE_W;
|
||||
static constexpr coord_t S_ROW_H = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE;
|
||||
#define S_Y(i) (i * S_ROW_H + PAD_TINY)
|
||||
};
|
||||
|
||||
class HWPots : public Window
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "edgetx.h"
|
||||
#include "sliders.h"
|
||||
#include "view_main_decoration.h"
|
||||
#include "hw_inputs.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -66,8 +67,8 @@ class StickCalibrationWindow : public Window
|
||||
StaticLZ4Image *calibStick = nullptr;
|
||||
};
|
||||
|
||||
RadioCalibrationPage::RadioCalibrationPage(bool initial) :
|
||||
Page(ICON_RADIO_CALIBRATION), initial(initial)
|
||||
RadioCalibrationPage::RadioCalibrationPage() :
|
||||
Page(ICON_RADIO_CALIBRATION)
|
||||
{
|
||||
buildHeader(header);
|
||||
buildBody(body);
|
||||
@@ -76,7 +77,8 @@ RadioCalibrationPage::RadioCalibrationPage(bool initial) :
|
||||
void RadioCalibrationPage::buildHeader(Window *window)
|
||||
{
|
||||
header->setTitle(STR_MENUCALIBRATION);
|
||||
text = header->setTitle2(STR_MENUTOSTART);
|
||||
title2 = header->setTitle2("");
|
||||
etx_font(title2->getLvObj(), FONT_BOLD_INDEX);
|
||||
}
|
||||
|
||||
void RadioCalibrationPage::buildBody(Window *window)
|
||||
@@ -106,13 +108,54 @@ void RadioCalibrationPage::buildBody(Window *window)
|
||||
|
||||
std::unique_ptr<ViewMainDecoration> deco(new ViewMainDecoration(window, false, true, false));
|
||||
|
||||
#if defined(PCBNV14) || defined(PCBPL18)
|
||||
new TextButton(window, {LCD_W - 120, LCD_H - 140, 90, 40}, "Next",
|
||||
axisBtn = new TextButton(window, {AXIS_X, PAD_LARGE, AXIS_W, 0}, STR_STICKS,
|
||||
[=]() -> uint8_t {
|
||||
new HWInputDialog<HWSticks>(STR_STICKS);
|
||||
return 0;
|
||||
});
|
||||
|
||||
potsBtn = new TextButton(window, {POTS_X, PAD_LARGE, POTS_W, 0}, STR_POTS,
|
||||
[=]() -> uint8_t {
|
||||
new HWInputDialog<HWPots>(STR_POTS, HWPots::POTS_WINDOW_WIDTH);
|
||||
return 0;
|
||||
});
|
||||
|
||||
nxtBtn = new TextButton(window, {NXT_X, PAD_LARGE, NXT_W, 0}, "",
|
||||
[=]() -> uint8_t {
|
||||
nextStep();
|
||||
return 0;
|
||||
});
|
||||
#endif
|
||||
|
||||
setState();
|
||||
}
|
||||
|
||||
void RadioCalibrationPage::setState()
|
||||
{
|
||||
axisBtn->hide();
|
||||
potsBtn->hide();
|
||||
|
||||
switch (menuCalibrationState) {
|
||||
case CALIB_START:
|
||||
title2->setText("");
|
||||
nxtBtn->setText(STR_START);
|
||||
break;
|
||||
case CALIB_SET_MIDPOINT:
|
||||
title2->setText(STR_SETMIDPOINT);
|
||||
nxtBtn->setText(STR_NEXT);
|
||||
break;
|
||||
case CALIB_MOVE_STICKS:
|
||||
title2->setText(STR_MOVESTICKSPOTS);
|
||||
nxtBtn->setText(STR_NEXT);
|
||||
axisBtn->show();
|
||||
potsBtn->show();
|
||||
break;
|
||||
case CALIB_STORE:
|
||||
title2->setText(STR_CALIB_DONE);
|
||||
nxtBtn->setText(STR_EXIT);
|
||||
break;
|
||||
case CALIB_FINISHED:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RadioCalibrationPage::checkEvents()
|
||||
@@ -126,14 +169,12 @@ void RadioCalibrationPage::checkEvents()
|
||||
}
|
||||
}
|
||||
|
||||
void RadioCalibrationPage::onClicked() { nextStep(); }
|
||||
|
||||
void RadioCalibrationPage::onCancel()
|
||||
{
|
||||
if (menuCalibrationState != CALIB_START &&
|
||||
menuCalibrationState != CALIB_FINISHED) {
|
||||
menuCalibrationState != CALIB_STORE) {
|
||||
menuCalibrationState = CALIB_START;
|
||||
text->setText(STR_MENUTOSTART);
|
||||
setState();
|
||||
} else {
|
||||
Page::onCancel();
|
||||
}
|
||||
@@ -141,34 +182,15 @@ void RadioCalibrationPage::onCancel()
|
||||
|
||||
void RadioCalibrationPage::nextStep()
|
||||
{
|
||||
if (menuCalibrationState == CALIB_FINISHED) deleteLater();
|
||||
|
||||
menuCalibrationState++;
|
||||
|
||||
switch (menuCalibrationState) {
|
||||
case CALIB_SET_MIDPOINT:
|
||||
text->setText(STR_SETMIDPOINT);
|
||||
break;
|
||||
if (menuCalibrationState == CALIB_FINISHED)
|
||||
deleteLater();
|
||||
|
||||
case CALIB_MOVE_STICKS:
|
||||
text->setText(STR_MOVESTICKSPOTS);
|
||||
break;
|
||||
if (menuCalibrationState == CALIB_STORE)
|
||||
adcCalibStore();
|
||||
|
||||
case CALIB_STORE:
|
||||
text->setText(STR_CALIB_DONE);
|
||||
adcCalibStore();
|
||||
menuCalibrationState = CALIB_FINISHED;
|
||||
|
||||
// initial calibration completed
|
||||
// -> exit
|
||||
if (initial) deleteLater();
|
||||
break;
|
||||
|
||||
default:
|
||||
text->setText(STR_MENUTOSTART);
|
||||
menuCalibrationState = CALIB_START;
|
||||
break;
|
||||
}
|
||||
setState();
|
||||
}
|
||||
|
||||
void startCalibration() { new RadioCalibrationPage(true); }
|
||||
void startCalibration() { new RadioCalibrationPage(); }
|
||||
|
||||
@@ -27,19 +27,27 @@ class StaticText;
|
||||
|
||||
class RadioCalibrationPage: public Page {
|
||||
public:
|
||||
explicit RadioCalibrationPage(bool initial = false);
|
||||
explicit RadioCalibrationPage();
|
||||
|
||||
void checkEvents() override;
|
||||
void onClicked() override;
|
||||
void onCancel() override;
|
||||
|
||||
protected:
|
||||
StaticText * text = nullptr;
|
||||
TextButton * button = nullptr;
|
||||
bool initial;
|
||||
StaticText* title2 = nullptr;
|
||||
TextButton* nxtBtn = nullptr;
|
||||
TextButton* axisBtn = nullptr;
|
||||
TextButton* potsBtn = nullptr;
|
||||
void nextStep();
|
||||
void buildHeader(Window * window);
|
||||
void buildBody(Window * window);
|
||||
void setState();
|
||||
|
||||
static LAYOUT_VAL_SCALED(NXT_W, 80);
|
||||
static constexpr coord_t NXT_X = LCD_W - NXT_W - PAD_LARGE * 4;
|
||||
static LAYOUT_VAL_SCALED(AXIS_W, 80);
|
||||
static constexpr coord_t AXIS_X = PAD_LARGE * 4;
|
||||
static LAYOUT_VAL_SCALED(POTS_W, 80);
|
||||
static constexpr coord_t POTS_X = AXIS_X + AXIS_W + PAD_LARGE;
|
||||
};
|
||||
|
||||
void startCalibration();
|
||||
|
||||
@@ -21,9 +21,33 @@
|
||||
|
||||
#include "edgetx.h"
|
||||
#include "calibration.h"
|
||||
#include "analogs.h"
|
||||
|
||||
#include "hal/adc_driver.h"
|
||||
|
||||
void menuCommonCalibOptions(event_t event)
|
||||
{
|
||||
SIMPLE_SUBMENU(STR_AXISDIR, HEADER_LINE+4);
|
||||
uint8_t sub = menuVerticalPosition;
|
||||
|
||||
coord_t y = MENU_HEADER_HEIGHT + 1;
|
||||
lcdDrawTextAlignedLeft(y, STR_STICKS);
|
||||
lcdDrawText(LCD_W / 3 * 2, y, STR_MENU_INVERT, CENTERED);
|
||||
y+=FH;
|
||||
for(uint8_t i = 0; i < 4; i++) {
|
||||
uint8_t k = i + menuVerticalOffset;
|
||||
LcdFlags attr = (sub == k) ? INVERS : 0;
|
||||
|
||||
lcdDrawTextIndented(y, STR_CHAR_STICK);
|
||||
lcdDrawText(lcdNextPos, y, analogGetCanonicalName(ADC_INPUT_MAIN, i), 0);
|
||||
bool stickInversion = getStickInversion(i);
|
||||
lcdDrawChar(LCD_W / 3 * 2, y, stickInversion ? 127 : 126, attr);
|
||||
if (attr) stickInversion = checkIncDec(event, stickInversion, 0, 1, EE_GENERAL);
|
||||
setStickInversion(i, stickInversion);
|
||||
y+=FH;
|
||||
}
|
||||
}
|
||||
|
||||
void menuCommonCalib(event_t event)
|
||||
{
|
||||
// make sure we don't scroll while calibrating
|
||||
@@ -35,6 +59,11 @@ void menuCommonCalib(event_t event)
|
||||
reusableBuffer.calib.state = CALIB_START;
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
killEvents(event);
|
||||
pushMenu(menuCommonCalibOptions);
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
reusableBuffer.calib.state++;
|
||||
break;
|
||||
@@ -55,7 +84,8 @@ void menuCommonCalib(event_t event)
|
||||
|
||||
case CALIB_MOVE_STICKS:
|
||||
// MOVE STICKS/POTS
|
||||
lcdDrawText(LCD_W/2, MENU_HEADER_HEIGHT+FH, STR_MOVESTICKSPOTS, INVERS|CENTERED);
|
||||
lcdDrawText(LCD_W/2, MENU_HEADER_HEIGHT, STR_MOVESTICKSPOTS, INVERS|CENTERED);
|
||||
lcdDrawText(LCD_W/2, MENU_HEADER_HEIGHT+FH, STR_MENUAXISDIR, CENTERED);
|
||||
lcdDrawText(LCD_W/2, MENU_HEADER_HEIGHT+2*FH, STR_MENUWHENDONE, CENTERED);
|
||||
adcCalibSetMinMax();
|
||||
break;
|
||||
|
||||
@@ -138,7 +138,7 @@ static void _init_menu_tab_array(uint8_t* tab, size_t len)
|
||||
auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
|
||||
for (int i = ITEM_RADIO_HARDWARE_STICK; i <= ITEM_RADIO_HARDWARE_STICK_END; i++) {
|
||||
uint8_t idx = i - ITEM_RADIO_HARDWARE_STICK;
|
||||
tab[i] = idx < max_sticks ? 0 : HIDDEN_ROW;
|
||||
tab[i] = idx < max_sticks ? 1 : HIDDEN_ROW;
|
||||
}
|
||||
|
||||
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
|
||||
@@ -480,9 +480,17 @@ void menuRadioHardware(event_t event)
|
||||
default:
|
||||
if (k <= ITEM_RADIO_HARDWARE_STICK_END) {
|
||||
// Sticks
|
||||
int idx = k - ITEM_RADIO_HARDWARE_STICK;
|
||||
|
||||
LcdFlags flags = menuHorizontalPosition == 0 ? attr : 0;
|
||||
editStickHardwareSettings(HW_SETTINGS_COLUMN1, y,
|
||||
k - ITEM_RADIO_HARDWARE_STICK, event,
|
||||
attr, old_editMode);
|
||||
idx, event, flags, old_editMode);
|
||||
// ADC inversion
|
||||
flags = menuHorizontalPosition == 1 ? attr : 0;
|
||||
bool stickinversion = getStickInversion(idx);
|
||||
lcdDrawChar(LCD_W - 8, y, stickinversion ? 127 : 126, flags);
|
||||
if (flags & (~RIGHT)) stickinversion = checkIncDec(event, stickinversion, 0, 1, EE_GENERAL);
|
||||
setStickInversion(idx, stickinversion);
|
||||
|
||||
} else if (k <= ITEM_RADIO_HARDWARE_POT_END) {
|
||||
// Pots & sliders
|
||||
|
||||
@@ -1352,6 +1352,16 @@ bool isFlexSwitchSourceValid(int source)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getStickInversion(int index)
|
||||
{
|
||||
return bfGet<uint8_t>(g_eeGeneral.stickInvert, index, STICK_CFG_INV_BITS);
|
||||
}
|
||||
|
||||
void setStickInversion(int index, bool value)
|
||||
{
|
||||
g_eeGeneral.stickInvert = bfSet<uint8_t>(g_eeGeneral.stickInvert, value, index, STICK_CFG_INV_BITS);
|
||||
}
|
||||
|
||||
bool getPotInversion(int index)
|
||||
{
|
||||
return bfGet<potconfig_t>(g_eeGeneral.potsConfig, (POT_CFG_BITS * index) + POT_CFG_TYPE_BITS, POT_CFG_INV_BITS);
|
||||
|
||||
@@ -85,6 +85,8 @@ bool isAssignableFunctionAvailable(int function, bool modelFunctions);
|
||||
bool isPotTypeAvailable(uint8_t type);
|
||||
bool isFlexSwitchSourceValid(int source);
|
||||
bool getPotInversion(int index);
|
||||
bool getStickInversion(int index);
|
||||
void setStickInversion(int index, bool value);
|
||||
void setPotInversion(int index, bool value);
|
||||
uint8_t getPotType(int index);
|
||||
void setPotType(int index, int value);
|
||||
|
||||
Reference in New Issue
Block a user