From bca4660742b63c7d736f5ef1494a9fcdf236e668 Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 15 Oct 2012 20:13:06 +0000 Subject: [PATCH] [all] Now 5 Global Variables available on all boards --- src/menus.cpp | 12 ++++++------ src/model_menus.cpp | 8 ++++---- src/myeeprom.h | 6 +++--- src/open9x.cpp | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/menus.cpp b/src/menus.cpp index 5a75e460b..fb176d1a0 100644 --- a/src/menus.cpp +++ b/src/menus.cpp @@ -631,12 +631,12 @@ int8_t gvarMenuItem(uint8_t x, uint8_t y, int8_t value, int8_t min, int8_t max, { bool invers = attr&INVERS; if (invers && event == EVT_KEY_LONG(KEY_MENU)) { - value = (value >= 126 ? REG_VALUE(value-126) : 126); + value = ((value >= 126 || value <= -126) ? REG_VALUE((uint8_t)value-126) : 126); eeDirty(EE_MODEL); } - if (value >= 126) { - putsStrIdx(attr&LEFT?x:x-FW-FWNUM, y, STR_GV, value - 126 + 1, attr); - if (invers) CHECK_INCDEC_MODELVAR(event, value, 126, 127); + if (value >= 126 || value <= -126) { + putsStrIdx(attr&LEFT?x:x-FW-FWNUM, y, STR_GV, (uint8_t)value - 125, attr); + if (invers) value = checkIncDec(event, (uint8_t)value, 126, 130, EE_MODEL); } else { lcd_outdezAtt(x, y, value, attr); @@ -647,8 +647,8 @@ int8_t gvarMenuItem(uint8_t x, uint8_t y, int8_t value, int8_t min, int8_t max, void displayGVar(uint8_t x, uint8_t y, int8_t value) { - if (value > 125) { - putsStrIdx(x-FW-FWNUM, y, STR_GV, value - 125, 0); + if (value >= 126 || value <= -126) { + putsStrIdx(x-FW-FWNUM, y, STR_GV, (uint8_t)value - 125, 0); } else { lcd_outdezAtt(x, y, value, 0); diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 3f98c0e99..66fb630a3 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -2651,9 +2651,9 @@ void menuModelFunctionSwitches(uint8_t event) } #endif #if defined(GVARS) - else if (sd->func >= FUNC_GVAR_X1) { - func_displayed = FUNC_GVAR_X1 - 16 - NUM_STICKS + 1; - putsStrIdx(12*FW-2, y, STR_GV, sd->func-FUNC_GVAR_X1+1, attr); + else if (sd->func >= FUNC_ADJUST_GV1) { + func_displayed = FUNC_ADJUST_GV1 - 16 - NUM_STICKS + 1; + putsStrIdx(12*FW-2, y, STR_GV, sd->func-FUNC_ADJUST_GV1+1, attr); } #endif else { @@ -2743,7 +2743,7 @@ void menuModelFunctionSwitches(uint8_t event) lcd_outdezAtt(18*FW, y, val_displayed, attr); } #if defined(GVARS) - else if (sd->func >= FUNC_GVAR_X1 + else if (sd->func >= FUNC_ADJUST_GV1 #if defined(DEBUG) && sd->func != FUNC_TEST #endif diff --git a/src/myeeprom.h b/src/myeeprom.h index 74eac7b4e..8bff32107 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -375,8 +375,8 @@ enum Functions { FUNC_BACKGND_MUSIC_PAUSE, #endif #if defined(GVARS) - FUNC_GVAR_X1, - FUNC_GVAR_X2, + FUNC_ADJUST_GV1, + FUNC_ADJUST_GV5 = FUNC_ADJUST_GV1 + 4, #endif #if defined(DEBUG) FUNC_TEST, // should remain the last before MAX as not added in companion9x @@ -736,7 +736,7 @@ typedef int8_t model_gvar_t; #endif #if defined(GVARS) -#define MAX_GVARS 2 +#define MAX_GVARS 5 #define EXTRA_GVARS model_gvar_t gvars[MAX_GVARS] #else #define MAX_GVARS 0 diff --git a/src/open9x.cpp b/src/open9x.cpp index 245f0256d..6658e9fa4 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -934,8 +934,8 @@ void incRotaryEncoder(uint8_t idx, int8_t inc) int8_t REG(int8_t x, int8_t min, int8_t max) { int8_t result = x; - if (x >= 126) { - x -= 126; + if (x >= 126 || x <= -126) { + x = (uint8_t)x - 126; result = REG_VALUE(x); if (result < min) { REG_VALUE(x) = result = min; @@ -2112,12 +2112,12 @@ void evalFunctions() #endif #if defined(GVARS) - else if (sd->func >= FUNC_GVAR_X1) { + else if (sd->func >= FUNC_ADJUST_GV1) { if (FSW_PARAM(sd) >= MIXSRC_TrimRud-1 && FSW_PARAM(sd) <= MIXSRC_TrimAil-1) { - trimPtr[FSW_PARAM(sd)-MIXSRC_TrimRud+1] = ®_VALUE(sd->func-FUNC_GVAR_X1); + trimPtr[FSW_PARAM(sd)-MIXSRC_TrimRud+1] = ®_VALUE(sd->func-FUNC_ADJUST_GV1); } else { - REG_VALUE(sd->func-FUNC_GVAR_X1) = limit((int16_t)-1250, getValue(FSW_PARAM(sd)), (int16_t)1250) / 10; + REG_VALUE(sd->func-FUNC_ADJUST_GV1) = limit((int16_t)-1250, getValue(FSW_PARAM(sd)), (int16_t)1250) / 10; } } #endif