fix(lua): Remove faulty carryTrim, replace with trimSource (#2995)

* Fix carryTrim in LUA

* Remove carryTrim
This commit is contained in:
3djc
2023-01-15 11:54:57 +10:00
committed by GitHub
parent ea162d2158
commit 8ee73a5800
10 changed files with 32 additions and 31 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ PACK(struct ExpoData {
uint16_t mode:2; uint16_t mode:2;
uint16_t scale:14; uint16_t scale:14;
uint16_t srcRaw:10 ENUM(MixSources) CUST(r_mixSrcRaw,w_mixSrcRaw); uint16_t srcRaw:10 ENUM(MixSources) CUST(r_mixSrcRaw,w_mixSrcRaw);
int16_t carryTrim:6; int16_t trimSource:6;
uint32_t chn:5; uint32_t chn:5;
int32_t swtch:9 CUST(r_swtchSrc,w_swtchSrc); int32_t swtch:9 CUST(r_swtchSrc,w_swtchSrc);
uint32_t flightModes:9 CUST(r_flightModes, w_flightModes); uint32_t flightModes:9 CUST(r_flightModes, w_flightModes);
+3 -3
View File
@@ -151,11 +151,11 @@ void menuModelExpoOne(event_t event)
case EXPO_FIELD_TRIM: case EXPO_FIELD_TRIM:
uint8_t notStick = (ed->srcRaw > MIXSRC_Ail); uint8_t notStick = (ed->srcRaw > MIXSRC_Ail);
int8_t carryTrim = -ed->carryTrim; int8_t trimSource = -ed->trimSource;
lcdDrawTextAlignedLeft(y, STR_TRIM); lcdDrawTextAlignedLeft(y, STR_TRIM);
lcdDrawTextAtIndex(EXPO_ONE_2ND_COLUMN, y, STR_VMIXTRIMS, (notStick && carryTrim == 0) ? 0 : carryTrim+1, RIGHT | (menuHorizontalPosition==0 ? attr : 0)); lcdDrawTextAtIndex(EXPO_ONE_2ND_COLUMN, y, STR_VMIXTRIMS, (notStick && trimSource == 0) ? 0 : trimSource + 1, RIGHT | (menuHorizontalPosition==0 ? attr : 0));
if (attr) if (attr)
ed->carryTrim = -checkIncDecModel(event, carryTrim, notStick ? TRIM_ON : -TRIM_OFF, -TRIM_LAST); ed->trimSource = -checkIncDecModel(event, trimSource, notStick ? TRIM_ON : -TRIM_OFF, -TRIM_LAST);
break; break;
} }
y += FH; y += FH;
+3 -3
View File
@@ -142,10 +142,10 @@ void menuModelExpoOne(event_t event)
case EXPO_FIELD_TRIM: case EXPO_FIELD_TRIM:
uint8_t not_stick = (ed->srcRaw > MIXSRC_Ail); uint8_t not_stick = (ed->srcRaw > MIXSRC_Ail);
int8_t carryTrim = -ed->carryTrim; int8_t trimSource = -ed->trimSource;
lcdDrawTextAlignedLeft(y, STR_TRIM); lcdDrawTextAlignedLeft(y, STR_TRIM);
lcdDrawTextAtIndex(EXPO_ONE_2ND_COLUMN, y, STR_VMIXTRIMS, (not_stick && carryTrim == 0) ? 0 : carryTrim+1, menuHorizontalPosition==0 ? attr : 0); lcdDrawTextAtIndex(EXPO_ONE_2ND_COLUMN, y, STR_VMIXTRIMS, (not_stick && trimSource == 0) ? 0 : trimSource + 1, menuHorizontalPosition==0 ? attr : 0);
if (attr) ed->carryTrim = -checkIncDecModel(event, carryTrim, not_stick ? TRIM_ON : -TRIM_OFF, -TRIM_LAST); if (attr) ed->trimSource = -checkIncDecModel(event, trimSource, not_stick ? TRIM_ON : -TRIM_OFF, -TRIM_LAST);
break; break;
} }
y += FH; y += FH;
+2 -2
View File
@@ -61,8 +61,8 @@ InputEditAdvanced::InputEditAdvanced(uint8_t input_n, uint8_t index) :
line = form->newLine(&grid); line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_TRIM, 0, COLOR_THEME_PRIMARY1); new StaticText(line, rect_t{}, STR_TRIM, 0, COLOR_THEME_PRIMARY1);
auto c = new Choice(line, rect_t{}, STR_VMIXTRIMS, -TRIM_OFF, auto c = new Choice(line, rect_t{}, STR_VMIXTRIMS, -TRIM_OFF,
-TRIM_LAST, GET_VALUE(-input->carryTrim), -TRIM_LAST, GET_VALUE(-input->trimSource),
SET_VALUE(input->carryTrim, -newValue)); SET_VALUE(input->trimSource, -newValue));
c->setAvailableHandler([=](int value) { c->setAvailableHandler([=](int value) {
return value != TRIM_ON || input->srcRaw <= MIXSRC_Ail; return value != TRIM_ON || input->srcRaw <= MIXSRC_Ail;
}); });
+2 -2
View File
@@ -143,8 +143,8 @@ InputSource::InputSource(Window* parent, ExpoData* input) :
void InputSource::update() void InputSource::update()
{ {
if (input->srcRaw > MIXSRC_Ail && input->carryTrim == TRIM_ON) { if (input->srcRaw > MIXSRC_Ail && input->trimSource == TRIM_ON) {
input->carryTrim = TRIM_OFF; input->trimSource = TRIM_OFF;
} }
if (!sensor_form) return; if (!sensor_form) return;
+2 -2
View File
@@ -181,8 +181,8 @@ void displayExpoLine(coord_t y, ExpoData * ed)
{ {
drawSource(EXPO_LINE_SRC_POS, y, ed->srcRaw, 0); drawSource(EXPO_LINE_SRC_POS, y, ed->srcRaw, 0);
if (ed->carryTrim != TRIM_ON) { if (ed->trimSource != TRIM_ON) {
lcdDrawChar(EXPO_LINE_TRIM_POS, y, ed->carryTrim > 0 ? '-' : STR_RETA123[-ed->carryTrim][0]); lcdDrawChar(EXPO_LINE_TRIM_POS, y, ed->trimSource > 0 ? '-' : STR_RETA123[-ed->trimSource][0]);
} }
if (!ed->flightModes || ((ed->curve.value || ed->swtch) && ((get_tmr10ms() / 200) & 1))) if (!ed->flightModes || ((ed->curve.value || ed->swtch) && ((get_tmr10ms() / 200) & 1)))
+7 -6
View File
@@ -582,10 +582,11 @@ Return input data for given input and line number
* `switch` (number) input switch index * `switch` (number) input switch index
* `curveType` (number) curve type (function, expo, custom curve) * `curveType` (number) curve type (function, expo, custom curve)
* `curveValue` (number) curve index * `curveValue` (number) curve index
* `carryTrim` (boolean) input trims applied * `carryTrim` deprecated, please use trimSource instead. WARNING: carryTrim was getting negative values (carryTrim = - trimSource)
* 'trimSource' (number) a positive number representing trim source
* 'flightModes' (number) bit-mask of active flight modes * 'flightModes' (number) bit-mask of active flight modes
@status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10, flighmode reworked in 2.3.11 @status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10, flighmode reworked in 2.3.11, broken carryTrim replaced by trimSource in 2.8.1
*/ */
static int luaModelGetInput(lua_State *L) static int luaModelGetInput(lua_State *L)
{ {
@@ -604,7 +605,7 @@ static int luaModelGetInput(lua_State *L)
lua_pushtableinteger(L, "switch", expo->swtch); lua_pushtableinteger(L, "switch", expo->swtch);
lua_pushtableinteger(L, "curveType", expo->curve.type); lua_pushtableinteger(L, "curveType", expo->curve.type);
lua_pushtableinteger(L, "curveValue", expo->curve.value); lua_pushtableinteger(L, "curveValue", expo->curve.value);
lua_pushtableinteger(L, "carryTrim", expo->carryTrim); lua_pushtableinteger(L, "trimSource", - expo->trimSource);
lua_pushtableinteger(L, "flightModes", expo->flightModes); lua_pushtableinteger(L, "flightModes", expo->flightModes);
} }
else { else {
@@ -624,7 +625,7 @@ Insert an Input at specified line
@param value (table) input data, see model.getInput() @param value (table) input data, see model.getInput()
@status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10 @status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10, broken carryTrim replaced by trimSource in EdgeTX 2.8.1
*/ */
static int luaModelInsertInput(lua_State *L) static int luaModelInsertInput(lua_State *L)
{ {
@@ -673,8 +674,8 @@ static int luaModelInsertInput(lua_State *L)
else if (!strcmp(key, "curveValue")) { else if (!strcmp(key, "curveValue")) {
expo->curve.value = luaL_checkinteger(L, -1); expo->curve.value = luaL_checkinteger(L, -1);
} }
else if (!strcmp(key, "carryTrim")) { else if (!strcmp(key, "trimSource")) {
expo->carryTrim = lua_toboolean(L, -1); expo->trimSource = - luaL_checkinteger(L, -1);
} }
else if (!strcmp(key, "flightModes")) { else if (!strcmp(key, "flightModes")) {
expo->flightModes = luaL_checkinteger(L, -1); expo->flightModes = luaL_checkinteger(L, -1);
+3 -3
View File
@@ -189,9 +189,9 @@ void applyExpos(int16_t * anas, uint8_t mode, uint8_t ovwrIdx, int16_t ovwrValue
if (offset) v += divRoundClosest(calc100toRESX(offset), 10); if (offset) v += divRoundClosest(calc100toRESX(offset), 10);
//========== TRIMS ================ //========== TRIMS ================
if (ed->carryTrim < TRIM_ON) if (ed->trimSource < TRIM_ON)
virtualInputsTrims[cur_chn] = -ed->carryTrim - 1; virtualInputsTrims[cur_chn] = -ed->trimSource - 1;
else if (ed->carryTrim == TRIM_ON && ed->srcRaw >= MIXSRC_Rud && ed->srcRaw <= MIXSRC_Ail) else if (ed->trimSource == TRIM_ON && ed->srcRaw >= MIXSRC_Rud && ed->srcRaw <= MIXSRC_Ail)
virtualInputsTrims[cur_chn] = ed->srcRaw - MIXSRC_Rud; virtualInputsTrims[cur_chn] = ed->srcRaw - MIXSRC_Rud;
else else
virtualInputsTrims[cur_chn] = -1; virtualInputsTrims[cur_chn] = -1;
+1 -1
View File
@@ -1480,7 +1480,7 @@ void instantTrim()
if (!EXPO_VALID(expo)) if (!EXPO_VALID(expo))
break; // end of list break; // end of list
if (stick == expo->srcRaw - MIXSRC_FIRST_STICK) { if (stick == expo->srcRaw - MIXSRC_FIRST_STICK) {
if (expo->carryTrim < 0) { if (expo->trimSource < 0) {
// only default trims will be taken into account // only default trims will be taken into account
addTrim = false; addTrim = false;
break; break;
+8 -8
View File
@@ -395,9 +395,9 @@ TEST_F(TrimsTest, MoveTrimsToOffsetsWithCrossTrims)
g_model.limitData[1].offset = 0; g_model.limitData[1].offset = 0;
g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM; g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM;
ExpoData *expo = expoAddress(THR_STICK); ExpoData *expo = expoAddress(THR_STICK);
expo->carryTrim = TRIM_ELE; expo->trimSource = TRIM_ELE;
expo = expoAddress(ELE_STICK); expo = expoAddress(ELE_STICK);
expo->carryTrim = TRIM_THR; expo->trimSource = TRIM_THR;
anaInValues[THR_STICK] = 0; anaInValues[THR_STICK] = 0;
setTrimValue(0, MIXSRC_TrimEle - MIXSRC_FIRST_TRIM, 100); setTrimValue(0, MIXSRC_TrimEle - MIXSRC_FIRST_TRIM, 100);
@@ -422,9 +422,9 @@ TEST_F(TrimsTest, MoveTrimsToOffsetsWithCrosstrimsAndTrimIdle)
g_model.thrTrim = 1; g_model.thrTrim = 1;
g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM; g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM;
ExpoData *expo = expoAddress(THR_STICK); ExpoData *expo = expoAddress(THR_STICK);
expo->carryTrim = TRIM_ELE; expo->trimSource = TRIM_ELE;
expo = expoAddress(ELE_STICK); expo = expoAddress(ELE_STICK);
expo->carryTrim = TRIM_THR; expo->trimSource = TRIM_THR;
anaInValues[THR_STICK] = -1024; // Min stick anaInValues[THR_STICK] = -1024; // Min stick
setTrimValue(0, MIXSRC_TrimEle - MIXSRC_FIRST_TRIM, 100); setTrimValue(0, MIXSRC_TrimEle - MIXSRC_FIRST_TRIM, 100);
@@ -834,9 +834,9 @@ TEST_F(TrimsTest, throttleTrimWithCrossTrims)
g_model.thrTrim = 1; g_model.thrTrim = 1;
g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM; g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM;
ExpoData *expo = expoAddress(THR_STICK); ExpoData *expo = expoAddress(THR_STICK);
expo->carryTrim = TRIM_ELE; expo->trimSource = TRIM_ELE;
expo = expoAddress(ELE_STICK); expo = expoAddress(ELE_STICK);
expo->carryTrim = TRIM_THR; expo->trimSource = TRIM_THR;
// stick max + trim max // stick max + trim max
anaInValues[THR_STICK] = +1024; anaInValues[THR_STICK] = +1024;
@@ -909,9 +909,9 @@ TEST_F(TrimsTest, invertedThrottlePlusThrottleTrimWithCrossTrims)
g_model.thrTrim = 1; g_model.thrTrim = 1;
g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM; g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM;
ExpoData *expo = expoAddress(THR_STICK); ExpoData *expo = expoAddress(THR_STICK);
expo->carryTrim = TRIM_ELE; expo->trimSource = TRIM_ELE;
expo = expoAddress(ELE_STICK); expo = expoAddress(ELE_STICK);
expo->carryTrim = TRIM_THR; expo->trimSource = TRIM_THR;
// stick max + trim max // stick max + trim max
anaInValues[THR_STICK] = +1024; anaInValues[THR_STICK] = +1024;