feat: stick inversion (#6394)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user