Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix carryTrim in LUA #2995

Merged
merged 2 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ PACK(struct ExpoData {
uint16_t mode:2;
uint16_t scale:14;
uint16_t srcRaw:10 ENUM(MixSources) CUST(r_mixSrcRaw,w_mixSrcRaw);
int16_t carryTrim:6;
int16_t trimSource:6;
uint32_t chn:5;
int32_t swtch:9 CUST(r_swtchSrc,w_swtchSrc);
uint32_t flightModes:9 CUST(r_flightModes, w_flightModes);
Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/128x64/model_input_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ void menuModelExpoOne(event_t event)

case EXPO_FIELD_TRIM:
uint8_t notStick = (ed->srcRaw > MIXSRC_Ail);
int8_t carryTrim = -ed->carryTrim;
int8_t trimSource = -ed->trimSource;
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)
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;
}
y += FH;
Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/212x64/model_input_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ void menuModelExpoOne(event_t event)

case EXPO_FIELD_TRIM:
uint8_t not_stick = (ed->srcRaw > MIXSRC_Ail);
int8_t carryTrim = -ed->carryTrim;
int8_t trimSource = -ed->trimSource;
lcdDrawTextAlignedLeft(y, STR_TRIM);
lcdDrawTextAtIndex(EXPO_ONE_2ND_COLUMN, y, STR_VMIXTRIMS, (not_stick && carryTrim == 0) ? 0 : carryTrim+1, menuHorizontalPosition==0 ? attr : 0);
if (attr) ed->carryTrim = -checkIncDecModel(event, carryTrim, not_stick ? TRIM_ON : -TRIM_OFF, -TRIM_LAST);
lcdDrawTextAtIndex(EXPO_ONE_2ND_COLUMN, y, STR_VMIXTRIMS, (not_stick && trimSource == 0) ? 0 : trimSource + 1, menuHorizontalPosition==0 ? attr : 0);
if (attr) ed->trimSource = -checkIncDecModel(event, trimSource, not_stick ? TRIM_ON : -TRIM_OFF, -TRIM_LAST);
break;
}
y += FH;
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/colorlcd/input_edit_adv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ InputEditAdvanced::InputEditAdvanced(uint8_t input_n, uint8_t index) :
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_TRIM, 0, COLOR_THEME_PRIMARY1);
auto c = new Choice(line, rect_t{}, STR_VMIXTRIMS, -TRIM_OFF,
-TRIM_LAST, GET_VALUE(-input->carryTrim),
SET_VALUE(input->carryTrim, -newValue));
-TRIM_LAST, GET_VALUE(-input->trimSource),
SET_VALUE(input->trimSource, -newValue));
c->setAvailableHandler([=](int value) {
return value != TRIM_ON || input->srcRaw <= MIXSRC_Ail;
});
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/colorlcd/input_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ InputSource::InputSource(Window* parent, ExpoData* input) :

void InputSource::update()
{
if (input->srcRaw > MIXSRC_Ail && input->carryTrim == TRIM_ON) {
input->carryTrim = TRIM_OFF;
if (input->srcRaw > MIXSRC_Ail && input->trimSource == TRIM_ON) {
input->trimSource = TRIM_OFF;
}

if (!sensor_form) return;
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/common/stdlcd/model_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ void displayExpoLine(coord_t y, ExpoData * ed)
{
drawSource(EXPO_LINE_SRC_POS, y, ed->srcRaw, 0);

if (ed->carryTrim != TRIM_ON) {
lcdDrawChar(EXPO_LINE_TRIM_POS, y, ed->carryTrim > 0 ? '-' : STR_RETA123[-ed->carryTrim][0]);
if (ed->trimSource != TRIM_ON) {
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)))
Expand Down
13 changes: 7 additions & 6 deletions radio/src/lua/api_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,11 @@ Return input data for given input and line number
* `switch` (number) input switch index
* `curveType` (number) curve type (function, expo, custom curve)
* `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

@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)
{
Expand All @@ -596,7 +597,7 @@ static int luaModelGetInput(lua_State *L)
lua_pushtableinteger(L, "switch", expo->swtch);
lua_pushtableinteger(L, "curveType", expo->curve.type);
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);
}
else {
Expand All @@ -616,7 +617,7 @@ Insert an Input at specified line

@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)
{
Expand Down Expand Up @@ -665,8 +666,8 @@ static int luaModelInsertInput(lua_State *L)
else if (!strcmp(key, "curveValue")) {
expo->curve.value = luaL_checkinteger(L, -1);
}
else if (!strcmp(key, "carryTrim")) {
expo->carryTrim = lua_toboolean(L, -1);
else if (!strcmp(key, "trimSource")) {
expo->trimSource = - luaL_checkinteger(L, -1);
}
else if (!strcmp(key, "flightModes")) {
expo->flightModes = luaL_checkinteger(L, -1);
Expand Down
6 changes: 3 additions & 3 deletions radio/src/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

//========== TRIMS ================
if (ed->carryTrim < TRIM_ON)
virtualInputsTrims[cur_chn] = -ed->carryTrim - 1;
else if (ed->carryTrim == TRIM_ON && ed->srcRaw >= MIXSRC_Rud && ed->srcRaw <= MIXSRC_Ail)
if (ed->trimSource < TRIM_ON)
virtualInputsTrims[cur_chn] = -ed->trimSource - 1;
else if (ed->trimSource == TRIM_ON && ed->srcRaw >= MIXSRC_Rud && ed->srcRaw <= MIXSRC_Ail)
virtualInputsTrims[cur_chn] = ed->srcRaw - MIXSRC_Rud;
else
virtualInputsTrims[cur_chn] = -1;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/opentx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ void instantTrim()
if (!EXPO_VALID(expo))
break; // end of list
if (stick == expo->srcRaw - MIXSRC_FIRST_STICK) {
if (expo->carryTrim < 0) {
if (expo->trimSource < 0) {
// only default trims will be taken into account
addTrim = false;
break;
Expand Down
16 changes: 8 additions & 8 deletions radio/src/tests/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ TEST_F(TrimsTest, MoveTrimsToOffsetsWithCrossTrims)
g_model.limitData[1].offset = 0;
g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM;
ExpoData *expo = expoAddress(THR_STICK);
expo->carryTrim = TRIM_ELE;
expo->trimSource = TRIM_ELE;
expo = expoAddress(ELE_STICK);
expo->carryTrim = TRIM_THR;
expo->trimSource = TRIM_THR;

anaInValues[THR_STICK] = 0;
setTrimValue(0, MIXSRC_TrimEle - MIXSRC_FIRST_TRIM, 100);
Expand All @@ -422,9 +422,9 @@ TEST_F(TrimsTest, MoveTrimsToOffsetsWithCrosstrimsAndTrimIdle)
g_model.thrTrim = 1;
g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM;
ExpoData *expo = expoAddress(THR_STICK);
expo->carryTrim = TRIM_ELE;
expo->trimSource = TRIM_ELE;
expo = expoAddress(ELE_STICK);
expo->carryTrim = TRIM_THR;
expo->trimSource = TRIM_THR;

anaInValues[THR_STICK] = -1024; // Min stick
setTrimValue(0, MIXSRC_TrimEle - MIXSRC_FIRST_TRIM, 100);
Expand Down Expand Up @@ -834,9 +834,9 @@ TEST_F(TrimsTest, throttleTrimWithCrossTrims)
g_model.thrTrim = 1;
g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM;
ExpoData *expo = expoAddress(THR_STICK);
expo->carryTrim = TRIM_ELE;
expo->trimSource = TRIM_ELE;
expo = expoAddress(ELE_STICK);
expo->carryTrim = TRIM_THR;
expo->trimSource = TRIM_THR;

// stick max + trim max
anaInValues[THR_STICK] = +1024;
Expand Down Expand Up @@ -909,9 +909,9 @@ TEST_F(TrimsTest, invertedThrottlePlusThrottleTrimWithCrossTrims)
g_model.thrTrim = 1;
g_model.thrTrimSw = MIXSRC_TrimEle - MIXSRC_FIRST_TRIM;
ExpoData *expo = expoAddress(THR_STICK);
expo->carryTrim = TRIM_ELE;
expo->trimSource = TRIM_ELE;
expo = expoAddress(ELE_STICK);
expo->carryTrim = TRIM_THR;
expo->trimSource = TRIM_THR;

// stick max + trim max
anaInValues[THR_STICK] = +1024;
Expand Down