fix: Use keysGetMaxTrims() instead of MAX_TRIMS (#3860)

* fix: use keysGetMaxTrims() instead of MAX_TRIMS

* feat: add support for virtual trims

This is necessary for radios like X-lite where half of the trims are simulated
This commit is contained in:
Raphael Coeffic
2023-07-30 14:18:58 +10:00
committed by GitHub
parent 76423370cd
commit 574369aca4
13 changed files with 55 additions and 36 deletions
+1 -1
View File
@@ -808,7 +808,7 @@ void menuModelSetup(event_t event)
case ITEM_MODEL_SETUP_THROTTLE_TRIM_SWITCH:
lcdDrawTextAlignedLeft(y, STR_TTRIM_SW);
if (attr)
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.thrTrimSw, MAX_TRIMS - 1);
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.thrTrimSw, keysGetMaxTrims() - 1);
drawSource(MODEL_SETUP_2ND_COLUMN, y, g_model.getThrottleStickTrimSource(), attr);
break;
+1 -1
View File
@@ -108,7 +108,7 @@ class FlightModeEdit : public Page
FlexGridLayout trim_grid(trims_col_dsc, line_row_dsc);
for (int t = 0; t < MAX_TRIMS; t++) {
for (int t = 0; t < keysGetMaxTrims(); t++) {
lastTrim[t] = p_fm->trim[t].value;
if ((t % TRIMS_PER_LINE) == 0) {
+5 -8
View File
@@ -25,6 +25,8 @@
#include "hal/rotary_encoder.h"
static const uint8_t _trimMap[MAX_TRIMS * 2] = {6, 7, 4, 5, 2, 3, 0, 1, 8, 9, 10, 11};
static EnumKeys get_ith_key(uint8_t i)
{
auto supported_keys = keysGetSupported();
@@ -118,7 +120,7 @@ class RadioKeyDiagsWindow : public Window
}
#endif
// SWITCHES
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
if (SWITCH_EXISTS(i)) {
coord_t y = 1 + FH * i;
getvalue_t val = getValue(MIXSRC_FIRST_SWITCH + i);
@@ -128,18 +130,13 @@ class RadioKeyDiagsWindow : public Window
}
// TRIMS
for (uint8_t i = 0; i < MAX_TRIMS * 2; i++) {
#if MAX_TRIMS * 2 == 12
const uint8_t trimMap[MAX_TRIMS * 2] = {6, 7, 4, 5, 2, 3, 0, 1, 8, 9, 10, 11};
#else
const uint8_t trimMap[MAX_TRIMS * 2] = {6, 7, 4, 5, 2, 3, 0, 1};
#endif
for (uint8_t i = 0; i < keysGetMaxTrims() * 2; i++) {
coord_t y = 1 + FH + FH * (i / 2);
if (i & 1) {
dc->drawText(TRIM_COLUMN, y, "T", COLOR_THEME_PRIMARY1);
dc->drawNumber(TRIM_COLUMN + 10, y, i / 2 + 1, COLOR_THEME_PRIMARY1);
}
displayTrimState(dc, i & 1 ? TRIM_PLUS_COLUMN : TRIM_MINUS_COLUMN, y, trimMap[i]);
displayTrimState(dc, i & 1 ? TRIM_PLUS_COLUMN : TRIM_MINUS_COLUMN, y, _trimMap[i]);
}
};