diff --git a/radio/src/curves.cpp b/radio/src/curves.cpp index a79407e97..342598895 100644 --- a/radio/src/curves.cpp +++ b/radio/src/curves.cpp @@ -26,6 +26,7 @@ uint8_t s_curveChan; int8_t * curveEnd[MAX_CURVES]; void loadCurves() { + bool showWarning= false; int8_t * tmp = g_model.points; for (int i=0; i maxend) { + tmp = maxend; + g_model.curves[i].type=CURVE_TYPE_STANDARD; + g_model.curves[i].points=-3; + showWarning=true; + } curveEnd[i] = tmp; + + } + if (showWarning) { + POPUP_WARNING("Invalid curve data repaired"); + const char * w = "check your curves, logic switches"; + SET_WARNING_INFO(w, strlen(w), 0); } } @@ -50,7 +65,7 @@ int8_t * curveAddress(uint8_t idx) return idx==0 ? g_model.points : curveEnd[idx-1]; } -bool moveCurve(uint8_t index, int8_t shift) // TODO bool? +bool moveCurve(uint8_t index, int8_t shift) { if (curveEnd[MAX_CURVES-1] + shift > g_model.points + sizeof(g_model.points)) { AUDIO_WARNING2(); diff --git a/radio/src/gui/128x64/model_curve_edit.cpp b/radio/src/gui/128x64/model_curve_edit.cpp index e26cb323c..42abb30ea 100644 --- a/radio/src/gui/128x64/model_curve_edit.cpp +++ b/radio/src/gui/128x64/model_curve_edit.cpp @@ -87,11 +87,12 @@ void menuModelCurveOne(event_t event) for (int i = 1; i < 4 + crv.points; i++) { points[i] = calcRESXto100(applyCustomCurve(calc100toRESX(getCurveX(5 + crv.points, i)), s_curveChan)); } - moveCurve(s_curveChan, checkIncDec_Ret > 0 ? 3 + crv.points : -3 - crv.points); - if (newType == CURVE_TYPE_CUSTOM) { - resetCustomCurveX(points, 5 + crv.points); + if (moveCurve(s_curveChan, checkIncDec_Ret > 0 ? 3 + crv.points : -3 - crv.points)) { + if (newType == CURVE_TYPE_CUSTOM) { + resetCustomCurveX(points, 5 + crv.points); + } + crv.type = newType; } - crv.type = newType; } } @@ -105,16 +106,17 @@ void menuModelCurveOne(event_t event) if (checkIncDec_Ret) { int8_t newPoints[MAX_POINTS_PER_CURVE]; 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)); - moveCurve(s_curveChan, 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) - points[5+count+i-1] = getCurveX(5+count, i); + 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))) { + for (int i = 0; i < 5 + count; i++) { + points[i] = newPoints[i]; + if (crv.type == CURVE_TYPE_CUSTOM && i != 0 && i != 4 + count) + points[5 + count + i - 1] = getCurveX(5 + count, i); + } + crv.points = count; } - crv.points = count; } } diff --git a/radio/src/gui/212x64/model_curve_edit.cpp b/radio/src/gui/212x64/model_curve_edit.cpp index 66c8d8874..30bc33b78 100644 --- a/radio/src/gui/212x64/model_curve_edit.cpp +++ b/radio/src/gui/212x64/model_curve_edit.cpp @@ -91,11 +91,12 @@ void menuModelCurveOne(event_t event) for (int i = 1; i < 4 + crv.points; i++) { points[i] = calcRESXto100(applyCustomCurve(calc100toRESX(getCurveX(5 + crv.points, i)), s_curveChan)); } - moveCurve(s_curveChan, checkIncDec_Ret > 0 ? 3 + crv.points : -3 - crv.points); - if (newType == CURVE_TYPE_CUSTOM) { - resetCustomCurveX(points, 5 + crv.points); + if (moveCurve(s_curveChan, checkIncDec_Ret > 0 ? 3 + crv.points : -3 - crv.points)) { + if (newType == CURVE_TYPE_CUSTOM) { + resetCustomCurveX(points, 5 + crv.points); + } + crv.type = newType; } - crv.type = newType; } } @@ -109,16 +110,17 @@ void menuModelCurveOne(event_t event) if (checkIncDec_Ret) { int8_t newPoints[MAX_POINTS_PER_CURVE]; 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)); - moveCurve(s_curveChan, 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) - points[5+count+i-1] = getCurveX(5+count, i); + 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))) { + for (int i = 0; i < 5 + count; i++) { + points[i] = newPoints[i]; + if (crv.type == CURVE_TYPE_CUSTOM && i != 0 && i != 4 + count) + points[5 + count + i - 1] = getCurveX(5 + count, i); + } + crv.points = count; } - crv.points = count; } } diff --git a/radio/src/gui/480x272/model_curves.cpp b/radio/src/gui/480x272/model_curves.cpp index 5cdc2f3bd..29ba0b76d 100644 --- a/radio/src/gui/480x272/model_curves.cpp +++ b/radio/src/gui/480x272/model_curves.cpp @@ -117,14 +117,15 @@ bool menuModelCurveOne(event_t event) if (attr) { uint8_t newType = checkIncDecModelZero(event, crv.type, CURVE_TYPE_LAST); if (newType != crv.type) { - for (int i=1; i<4+crv.points; i++) { + for (int i = 1; i < 4 + crv.points; i++) { points[i] = calcRESXto100(applyCustomCurve(calc100toRESX(-100 + i * 200 / (4 + crv.points)), s_curveChan)); } - moveCurve(s_curveChan, checkIncDec_Ret > 0 ? 3+crv.points : -3-crv.points); - if (newType == CURVE_TYPE_CUSTOM) { - resetCustomCurveX(points, 5+crv.points); + if (moveCurve(s_curveChan, checkIncDec_Ret > 0 ? 3 + crv.points : -3 - crv.points)) { + if (newType == CURVE_TYPE_CUSTOM) { + resetCustomCurveX(points, 5 + crv.points); + } + crv.type = newType; } - crv.type = newType; } } @@ -140,13 +141,14 @@ bool menuModelCurveOne(event_t event) newPoints[4+count] = points[4+crv.points]; for (int i=1; i<4+count; i++) newPoints[i] = calcRESXto100(applyCustomCurve(calc100toRESX(-100 + (i*200) / (4+count)), s_curveChan)); - moveCurve(s_curveChan, 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) - points[5+count+i-1] = -100 + (i*200) / (4+count); + if (moveCurve(s_curveChan, 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) + points[5 + count + i - 1] = -100 + (i * 200) / (4 + count); + } + crv.points = count; } - crv.points = count; } }