Skip to content

Commit

Permalink
Backport: Fix opentx#7601 - Wrong Flight Mode Index when exiting from…
Browse files Browse the repository at this point in the history
… Gvar Menu (128x64 display) (opentx#7601) (#411)

GVars menu issue, (Backport: Fix opentx#7601)
  • Loading branch information
ajjjjjjjj authored Sep 16, 2024
1 parent 8b31041 commit a4a2ee5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
8 changes: 3 additions & 5 deletions radio/src/curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include "opentx.h"

uint8_t s_curveChan;

int8_t * curveEnd[MAX_CURVES];
void loadCurves()
{
Expand Down Expand Up @@ -317,8 +315,8 @@ int applyCustomCurve(int x, uint8_t idx)
point_t getPoint(uint8_t i)
{
point_t result = {0, 0};
CurveInfo & crv = g_model.curves[s_curveChan];
int8_t * points = curveAddress(s_curveChan);
CurveInfo & crv = g_model.curves[s_currIdxSubMenu];
int8_t * points = curveAddress(s_currIdxSubMenu);
bool custom = (crv.type == CURVE_TYPE_CUSTOM);
uint8_t count = 5+crv.points;
if (i < count) {
Expand All @@ -333,5 +331,5 @@ point_t getPoint(uint8_t i)

int applyCurrentCurve(int x)
{
return applyCustomCurve(x, s_curveChan);
return applyCustomCurve(x, s_currIdxSubMenu);
}
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ extern uint8_t s_copyMode;
extern int8_t s_copySrcRow;
extern int8_t s_copyTgtOfs;
extern uint8_t s_currIdx;
extern uint8_t s_curveChan;
extern uint8_t s_currIdxSubMenu;
extern uint8_t s_copySrcIdx;
extern uint8_t s_copySrcCh;
extern int8_t s_currCh;
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/128x64/menu_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ void editSingleName(coord_t x, coord_t y, const char * label, char * name, uint8
}

uint8_t s_currIdx;
uint8_t s_currIdxSubMenu;
26 changes: 13 additions & 13 deletions radio/src/gui/128x64/model_curve_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void runPopupCurvePreset(event_t event)

if (warningResult) {
warningResult = 0;
CurveInfo & crv = g_model.curves[s_curveChan];
int8_t * points = curveAddress(s_curveChan);
CurveInfo & crv = g_model.curves[s_currIdxSubMenu];
int8_t * points = curveAddress(s_currIdxSubMenu);
int k = 25 * reusableBuffer.curveEdit.preset;
int dx = 2000 / (5+crv.points-1);
for (uint8_t i=0; i<5+crv.points; i++) {
Expand All @@ -71,14 +71,14 @@ void onCurveOneMenu(const char * result)
POPUP_INPUT(STR_PRESET, runPopupCurvePreset);
}
else if (result == STR_MIRROR) {
CurveInfo & crv = g_model.curves[s_curveChan];
int8_t * points = curveAddress(s_curveChan);
CurveInfo & crv = g_model.curves[s_currIdxSubMenu];
int8_t * points = curveAddress(s_currIdxSubMenu);
for (int i=0; i<5+crv.points; i++)
points[i] = -points[i];
}
else if (result == STR_CLEAR) {
CurveInfo & crv = g_model.curves[s_curveChan];
int8_t * points = curveAddress(s_curveChan);
CurveInfo & crv = g_model.curves[s_currIdxSubMenu];
int8_t * points = curveAddress(s_currIdxSubMenu);
for (int i=0; i<5+crv.points; i++)
points[i] = 0;
if (crv.type == CURVE_TYPE_CUSTOM) {
Expand All @@ -89,10 +89,10 @@ void onCurveOneMenu(const char * result)

void menuModelCurveOne(event_t event)
{
CurveData & crv = g_model.curves[s_curveChan];
int8_t * points = curveAddress(s_curveChan);
CurveData & crv = g_model.curves[s_currIdxSubMenu];
int8_t * points = curveAddress(s_currIdxSubMenu);

drawStringWithIndex(PSIZE(TR_MENUCURVES)*FW+FW, 0, STR_CV, s_curveChan+1);
drawStringWithIndex(PSIZE(TR_MENUCURVES)*FW+FW, 0, STR_CV, s_currIdxSubMenu+1);

SIMPLE_SUBMENU(STR_MENUCURVES, 4 + 5+crv.points + (crv.type==CURVE_TYPE_CUSTOM ? 5+crv.points-2 : 0));

Expand All @@ -108,9 +108,9 @@ void menuModelCurveOne(event_t event)
uint8_t newType = checkIncDecModelZero(event, crv.type, CURVE_TYPE_LAST);
if (newType != crv.type) {
for (int i = 1; i < 4 + crv.points; i++) {
points[i] = calcRESXto100(applyCustomCurve(calc100toRESX(getCurveX(5 + crv.points, i)), s_curveChan));
points[i] = calcRESXto100(applyCustomCurve(calc100toRESX(getCurveX(5 + crv.points, i)), s_currIdxSubMenu));
}
if (moveCurve(s_curveChan, checkIncDec_Ret > 0 ? 3 + crv.points : -3 - crv.points)) {
if (moveCurve(s_currIdxSubMenu, checkIncDec_Ret > 0 ? 3 + crv.points : -3 - crv.points)) {
if (newType == CURVE_TYPE_CUSTOM) {
resetCustomCurveX(points, 5 + crv.points);
}
Expand All @@ -131,8 +131,8 @@ void menuModelCurveOne(event_t event)
newPoints[0] = points[0];
newPoints[4 + count] = points[4 + crv.points];
for (int i = 1; i < 4 + count; i++)
newPoints[i] = calcRESXto100(applyCustomCurve(calc100toRESX(getCurveX(5 + count, i)), s_curveChan));
if (moveCurve(s_curveChan, checkIncDec_Ret * (crv.type == CURVE_TYPE_CUSTOM ? 2 : 1))) {
newPoints[i] = calcRESXto100(applyCustomCurve(calc100toRESX(getCurveX(5 + count, i)), s_currIdxSubMenu));
if (moveCurve(s_currIdxSubMenu, checkIncDec_Ret * (crv.type == CURVE_TYPE_CUSTOM ? 2 : 1))) {
for (int i = 0; i < 5 + count; i++) {
points[i] = newPoints[i];
if (crv.type == CURVE_TYPE_CUSTOM && i != 0 && i != 4 + count)
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/model_flightmodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void menuModelFlightModeOne(event_t event)
drawStringWithIndex(INDENT_WIDTH, y, STR_GV, idx+1, posHorz==0 ? attr : 0);
lcdDrawSizedText(4*FW, y,g_model.gvars[idx].name, LEN_GVAR_NAME, ZCHAR);
if (attr && editMode>0 && posHorz==0) {
s_currIdx = sub - ITEM_MODEL_FLIGHT_MODE_GV1;
s_currIdxSubMenu = sub - ITEM_MODEL_FLIGHT_MODE_GV1;
editMode = 0;
pushMenu(menuModelGVarOne);
}
Expand Down
12 changes: 6 additions & 6 deletions radio/src/gui/128x64/model_gvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ enum GVarFields {

void menuModelGVarOne(event_t event)
{
GVarData * gvar = &g_model.gvars[s_currIdx];
GVarData * gvar = &g_model.gvars[s_currIdxSubMenu];

drawStringWithIndex(PSIZE(TR_GVARS)*FW+FW, 0, STR_GV, s_currIdx+1, 0);
drawGVarValue(32*FW, 0, s_currIdx, getGVarValue(s_currIdx, getFlightMode()));
drawStringWithIndex(PSIZE(TR_GVARS)*FW+FW, 0, STR_GV, s_currIdxSubMenu+1, 0);
drawGVarValue(32*FW, 0, s_currIdxSubMenu, getGVarValue(s_currIdxSubMenu, getFlightMode()));
lcdDrawFilledRect(0, 0, LCD_W, FH, SOLID);

SIMPLE_SUBMENU(STR_GVARS, GVAR_FIELD_LAST);
Expand All @@ -92,13 +92,13 @@ void menuModelGVarOne(event_t event)

case GVAR_FIELD_MIN:
lcdDrawText(0, y, STR_MIN);
drawGVarValue(GVAR_2ND_COLUMN, y, s_currIdx, GVAR_MIN+gvar->min, LEFT|attr);
drawGVarValue(GVAR_2ND_COLUMN, y, s_currIdxSubMenu, GVAR_MIN+gvar->min, LEFT|attr);
if (attr) gvar->min = checkIncDec(event, GVAR_MIN+gvar->min, GVAR_MIN, GVAR_MAX-gvar->max, EE_MODEL) - GVAR_MIN;
break;

case GVAR_FIELD_MAX:
lcdDrawText(0, y, STR_MAX);
drawGVarValue(GVAR_2ND_COLUMN, y, s_currIdx, GVAR_MAX-gvar->max, LEFT|attr);
drawGVarValue(GVAR_2ND_COLUMN, y, s_currIdxSubMenu, GVAR_MAX-gvar->max, LEFT|attr);
if (attr) gvar->max = GVAR_MAX - checkIncDec(event, GVAR_MAX-gvar->max, GVAR_MIN+gvar->min, GVAR_MAX, EE_MODEL);
break;

Expand All @@ -108,7 +108,7 @@ void menuModelGVarOne(event_t event)

default:
drawStringWithIndex(0, y, STR_FM, k-GVAR_FIELD_FM0);
editGVarValue(GVAR_2ND_COLUMN, y, event, s_currIdx, k-GVAR_FIELD_FM0, LEFT|attr);
editGVarValue(GVAR_2ND_COLUMN, y, event, s_currIdxSubMenu, k-GVAR_FIELD_FM0, LEFT|attr);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/128x64/model_inputs_mixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void menuModelExpoOne(event_t event)
CHECK_INCDEC_MODELVAR_ZERO(event, ed->curveParam, CURVE_BASE+MAX_CURVES-1);
if (ed->curveParam) ed->curveMode = MODE_CURVE;
if (ed->curveParam>=CURVE_BASE && event==EVT_KEY_LONG(KEY_ENTER)) {
s_curveChan = ed->curveParam - CURVE_BASE;
s_currIdxSubMenu = ed->curveParam - CURVE_BASE;
pushMenu(menuModelCurveOne);
}
}
Expand Down Expand Up @@ -449,7 +449,7 @@ void menuModelMixOne(event_t event)
drawCurveName(COLUMN_X+MIXES_2ND_COLUMN, y, curveParam, attr);
if (attr) {
if (event==EVT_KEY_LONG(KEY_ENTER) && (curveParam<0 || curveParam>=CURVE_BASE)){
s_curveChan = (curveParam<0 ? -curveParam-1 : curveParam-CURVE_BASE);
s_currIdxSubMenu = (curveParam<0 ? -curveParam-1 : curveParam-CURVE_BASE);
pushMenu(menuModelCurveOne);
}
else {
Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/common/stdlcd/model_curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void menuModelCurvesAll(event_t event)
#endif
case EVT_KEY_FIRST(KEY_ENTER):
if (CURVE_SELECTED() && !READ_ONLY()) {
s_curveChan = sub;
s_currIdxSubMenu = sub;
pushMenu(menuModelCurveOne);
}
break;
Expand Down Expand Up @@ -93,7 +93,7 @@ void menuModelCurvesAll(event_t event)
}

if (CURVE_SELECTED()) {
s_curveChan = sub;
s_currIdxSubMenu = sub;
#if LCD_W >= 212
drawCurve(23);
#else
Expand Down Expand Up @@ -142,7 +142,7 @@ void editCurveRef(coord_t x, coord_t y, CurveRef & curve, event_t event, LcdFlag
drawCurveName(x, y, curve.value, flags);
if (active && menuHorizontalPosition==1) {
if (event==EVT_KEY_LONG(KEY_ENTER) && curve.value!=0) {
s_curveChan = (curve.value<0 ? -curve.value-1 : curve.value-1);
s_currIdxSubMenu = (curve.value<0 ? -curve.value-1 : curve.value-1);
pushMenu(menuModelCurveOne);
}
else {
Expand Down

0 comments on commit a4a2ee5

Please sign in to comment.