feat: Use trim as a 3POS toggle switch source (#4465)

This commit is contained in:
philmoz
2024-01-05 19:16:26 +10:00
committed by GitHub
parent fa12b27438
commit 2635a4972b
12 changed files with 52 additions and 17 deletions
+3 -2
View File
@@ -283,8 +283,9 @@ void drawTrimMode(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t phase, uint8_
if (mode == TRIM_MODE_NONE) {
dc->drawText(x, y, "--", att);
}
else {
} else if (mode == TRIM_MODE_3POS) {
dc->drawText(x, y, "3P", att);
} else {
char s[2];
s[0] = (mode % 2 == 0) ? ':' : '+';
s[1] = '0'+p;
+10 -5
View File
@@ -30,6 +30,8 @@ static std::string getFMTrimStr(uint8_t mode, bool spacer)
mode &= 0x1F;
if (mode == TRIM_MODE_NONE)
return "-";
if (mode == TRIM_MODE_3POS)
return "3P";
std::string str((mode & 1) ? "+" : "=");
if (spacer) str += " ";
mode >>= 1;
@@ -135,18 +137,21 @@ class FlightModeEdit : public Page
tr_btn->setWidth(LV_DPI_DEF / 2);
tr_btn->setHeight(33);
tr_mode[t] = new Choice(trim, rect_t{}, 0, 2 * MAX_FLIGHT_MODES - 1,
tr_mode[t] = new Choice(trim, rect_t{}, 0, 2 * MAX_FLIGHT_MODES,
GET_DEFAULT(tr->mode),
[=](int val) {
tr->mode = val;
showControls(t, tr->mode);
SET_DIRTY();
});
tr_mode[t]->setTextHandler([=](uint8_t mode) { return getFMTrimStr(mode, true); });
tr_mode[t]->setAvailableHandler([=](int mode) {
return ((mode & 1) == 0) || ((mode >> 1) != index);
if (index > 0)
return ((mode & 1) == 0) || ((mode >> 1) != index) || (mode == TRIM_MODE_3POS);
return (mode == 0) || (mode == TRIM_MODE_3POS);
});
tr_value[t] = new NumberEdit(trim, rect_t{},
tr_value[t] = new NumberEdit(trim, rect_t{0, 0, 70, 0},
g_model.extendedTrims ? -512 : -128, g_model.extendedTrims ? 512 : 128,
GET_SET_DEFAULT(tr->value));
@@ -176,9 +181,9 @@ class FlightModeEdit : public Page
void showControls(int trim, uint8_t mode)
{
bool checked = (mode != TRIM_MODE_NONE);
bool showValue = (index == 0) || ((mode & 1) || (mode >> 1 == index));
bool showValue = (index == 0 && mode != TRIM_MODE_3POS) || ((mode & 1) || (mode >> 1 == index));
if (checked && (index > 0)) {
if (checked) {
lv_obj_clear_flag(tr_mode[trim]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_add_flag(tr_mode[trim]->getLvObj(), LV_OBJ_FLAG_HIDDEN);