diff --git a/src/Makefile b/src/Makefile index 70ae97021..60ef76f2e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -193,9 +193,9 @@ CURVES = YES # Values = YES, NO XCURVES = YES -# Registers +# Global Vars # Values = YES, NO -REGISTERS = NO +GVARS = NO #------- END BUILD OPTIONS --------------------------- @@ -364,8 +364,8 @@ ifeq ($(XCURVES), YES) CPPDEFS += -DXCURVES endif -ifeq ($(REGISTERS), YES) - CPPDEFS += -DREGISTERS +ifeq ($(GVARS), YES) + CPPDEFS += -DGVARS endif # If STD-Support is enabled diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 23b11f284..4d0a20bf5 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -70,23 +70,23 @@ const MenuFuncP_PROGMEM menuTabDiag[] PROGMEM = { menuGeneralCalib }; -#define GENERAL_PARAM_OFS (2+16*FW) +#define RADIO_SETUP_2ND_COLUMN (DISPLAY_W-5*FW-MENUS_SCROLLBAR_WIDTH) #if defined(GRAPHICS) void displaySlider(uint8_t x, uint8_t y, uint8_t value, uint8_t attr) { - lcd_putc(GENERAL_PARAM_OFS+2*FW+(value*FW), y, '$'); - lcd_hline(GENERAL_PARAM_OFS, y+3, 5*FW-1, SOLID); - if (attr && (!(attr & BLINK) || !BLINK_ON_PHASE)) lcd_filled_rect(GENERAL_PARAM_OFS, y, 5*FW-1, FH-1); + lcd_putc(RADIO_SETUP_2ND_COLUMN+2*FW+(value*FW), y, '$'); + lcd_hline(RADIO_SETUP_2ND_COLUMN, y+3, 5*FW-1, SOLID); + if (attr && (!(attr & BLINK) || !BLINK_ON_PHASE)) lcd_filled_rect(RADIO_SETUP_2ND_COLUMN, y, 5*FW-1, FH-1); } #define SLIDER(y, value, min, max, label, values, event, attr) { \ int8_t tmp = value; \ - displaySlider(GENERAL_PARAM_OFS, y, tmp, attr); \ - value = selectMenuItem(GENERAL_PARAM_OFS, y, label, NULL, tmp, min, max, attr, event); \ + displaySlider(RADIO_SETUP_2ND_COLUMN, y, tmp, attr); \ + value = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, label, NULL, tmp, min, max, attr, event); \ } #else #define SLIDER(y, value, min, max, label, values, event, attr) \ - value = selectMenuItem(GENERAL_PARAM_OFS, y, label, values, value, min, max, attr, event) + value = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, label, values, value, min, max, attr, event) #endif enum menuGeneralSetupItems { @@ -207,7 +207,7 @@ void menuGeneralSetup(uint8_t event) #endif case ITEM_SETUP_BEEPER_MODE: - g_eeGeneral.beeperMode = selectMenuItem(GENERAL_PARAM_OFS, y, STR_BEEPERMODE, STR_VBEEPMODE, g_eeGeneral.beeperMode, -2, 1, attr, event); + g_eeGeneral.beeperMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_BEEPERMODE, STR_VBEEPMODE, g_eeGeneral.beeperMode, -2, 1, attr, event); #if defined(FRSKY) if (attr && checkIncDec_Ret) FRSKY_setModelAlarms(); #endif @@ -220,7 +220,7 @@ void menuGeneralSetup(uint8_t event) #if defined(AUDIO) case ITEM_SETUP_SPEAKER_PITCH: lcd_putsLeft( y, STR_SPKRPITCH); - lcd_outdezAtt(GENERAL_PARAM_OFS, y, g_eeGeneral.speakerPitch, attr|LEFT); + lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.speakerPitch, attr|LEFT); if (attr) { CHECK_INCDEC_GENVAR(event, g_eeGeneral.speakerPitch, 0, 20); } @@ -232,14 +232,14 @@ void menuGeneralSetup(uint8_t event) { lcd_putsLeft(y, STR_SPEAKER_VOLUME); #if defined(PCBSKY9X) - lcd_outdezAtt(GENERAL_PARAM_OFS, y, g_eeGeneral.speakerVolume, attr|LEFT); + lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.speakerVolume, attr|LEFT); if (attr) { CHECK_INCDEC_GENVAR(event, g_eeGeneral.speakerVolume, 0, NUM_VOL_LEVELS-1); } #else uint8_t b ; b = g_eeGeneral.speakerVolume+7; - lcd_outdezAtt(GENERAL_PARAM_OFS, y, b, attr|LEFT); + lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, b, attr|LEFT); if (attr) { CHECK_INCDEC_GENVAR(event, b, 0, 7); if (checkIncDec_Ret) { @@ -254,7 +254,7 @@ void menuGeneralSetup(uint8_t event) #if defined(HAPTIC) case ITEM_SETUP_HAPTIC_MODE: - g_eeGeneral.hapticMode = selectMenuItem(GENERAL_PARAM_OFS, y, STR_HAPTICMODE, STR_VBEEPMODE, g_eeGeneral.hapticMode, -2, 1, attr, event); + g_eeGeneral.hapticMode = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_HAPTICMODE, STR_VBEEPMODE, g_eeGeneral.hapticMode, -2, 1, attr, event); break; case ITEM_SETUP_HAPTIC_LENGTH: @@ -263,7 +263,7 @@ void menuGeneralSetup(uint8_t event) case ITEM_SETUP_HAPTIC_STRENGTH: lcd_putsLeft( y, STR_HAPTICSTRENGTH); - lcd_outdezAtt(GENERAL_PARAM_OFS, y, g_eeGeneral.hapticStrength, attr|LEFT); + lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.hapticStrength, attr|LEFT); if (attr) { CHECK_INCDEC_GENVAR(event, g_eeGeneral.hapticStrength, 0, 5); } @@ -273,7 +273,7 @@ void menuGeneralSetup(uint8_t event) #if defined(PCBSKY9X) case ITEM_SETUP_BRIGHTNESS: lcd_putsLeft(y, STR_BRIGHTNESS); - lcd_outdezAtt(GENERAL_PARAM_OFS, y, 100-g_eeGeneral.backlightBright, attr|LEFT) ; + lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, 100-g_eeGeneral.backlightBright, attr|LEFT) ; if(attr) { uint8_t b ; b = 100 - g_eeGeneral.backlightBright; @@ -285,7 +285,7 @@ void menuGeneralSetup(uint8_t event) case ITEM_SETUP_CONTRAST: lcd_putsLeft( y, STR_CONTRAST); - lcd_outdezAtt(GENERAL_PARAM_OFS,y,g_eeGeneral.contrast, attr|LEFT); + lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN,y,g_eeGeneral.contrast, attr|LEFT); if(attr) { CHECK_INCDEC_GENVAR(event, g_eeGeneral.contrast, 10, 45); lcdSetContrast(); @@ -294,34 +294,34 @@ void menuGeneralSetup(uint8_t event) case ITEM_SETUP_BATTERY_WARNING: lcd_putsLeft( y,STR_BATTERYWARNING); - putsVolts(GENERAL_PARAM_OFS, y, g_eeGeneral.vBatWarn, attr|LEFT); + putsVolts(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.vBatWarn, attr|LEFT); if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatWarn, 40, 120); //4-12V break; #if defined(PCBSKY9X) case ITEM_SETUP_CAPACITY_WARNING: lcd_putsLeft(y, STR_CAPAWARNING); - putsTelemetryValue(GENERAL_PARAM_OFS, y, g_eeGeneral.mAhWarn*50, UNIT_MAH, attr|LEFT) ; + putsTelemetryValue(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.mAhWarn*50, UNIT_MAH, attr|LEFT) ; if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.mAhWarn, 0, 100); break; case ITEM_SETUP_TEMPERATURE_WARNING: lcd_putsLeft(y, STR_TEMPWARNING); - putsTelemetryValue(GENERAL_PARAM_OFS, y, g_eeGeneral.temperatureWarn, UNIT_DEGREES, attr|LEFT) ; + putsTelemetryValue(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.temperatureWarn, UNIT_DEGREES, attr|LEFT) ; if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.temperatureWarn, 0, 120); // 0 means no alarm break; #endif case ITEM_SETUP_INACTIVITY_ALARM: lcd_putsLeft( y,STR_INACTIVITYALARM); - lcd_outdezAtt(GENERAL_PARAM_OFS, y, g_eeGeneral.inactivityTimer, attr|LEFT); + lcd_outdezAtt(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.inactivityTimer, attr|LEFT); lcd_putc(lcdLastPos, y, 'm'); if(attr) g_eeGeneral.inactivityTimer = checkIncDec(event, g_eeGeneral.inactivityTimer, 0, 250, EE_GENERAL); //0..250minutes break; #if defined(ROTARY_ENCODERS) case ITEM_SETUP_RE_NAVIGATION: - g_eeGeneral.reNavigation = selectMenuItem(GENERAL_PARAM_OFS, y, STR_RENAVIG, STR_VRENAVIG, g_eeGeneral.reNavigation, 0, ROTARY_ENCODERS, attr, event); + g_eeGeneral.reNavigation = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_RENAVIG, STR_VRENAVIG, g_eeGeneral.reNavigation, 0, ROTARY_ENCODERS, attr, event); if (attr && checkIncDec_Ret) { for (uint8_t i=0; iAETR for (uint8_t i=1; i<=4; i++) - putsChnLetter(GENERAL_PARAM_OFS - FW + i*FW, y, channel_order(i), attr); + putsChnLetter(RADIO_SETUP_2ND_COLUMN - FW + i*FW, y, channel_order(i), attr); if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.templateSetup, 0, 23); break; @@ -899,7 +899,7 @@ void menuGeneralHardware(uint8_t event) #if defined(BLUETOOTH) case ITEM_SETUP_HW_BT_BAUDRATE: - g_eeGeneral.btBaudrate = selectMenuItem(GENERAL_PARAM_OFS, y, STR_BAUDRATE, PSTR("\005115k 9600 19200"), g_eeGeneral.btBaudrate, 0, 2, attr, event); + g_eeGeneral.btBaudrate = selectMenuItem(RADIO_SETUP_2ND_COLUMN, y, STR_BAUDRATE, PSTR("\005115k 9600 19200"), g_eeGeneral.btBaudrate, 0, 2, attr, event); if (attr && checkIncDec_Ret) { btInit(); } diff --git a/src/mavlink.cpp b/src/mavlink.cpp index dfcf3d6eb..d1a983a8a 100644 --- a/src/mavlink.cpp +++ b/src/mavlink.cpp @@ -624,7 +624,7 @@ void check_mavlink() { } // Start of Mavlink menus <<<<<<<<<<<<<<<<<<<<<<<<<<< -void DisplayScreenIndex(uint8_t index, uint8_t count, uint8_t attr); +void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr); enum mavlink_menu_ { MENU_INFO = 0, // @@ -656,7 +656,7 @@ inline mavlink_menu_ operator--(mavlink_menu_ &eDOW, int) { void mav_title(const pm_char * s, uint8_t index) { lcd_putsAtt(0, 0, PSTR("MAVLINK"), INVERS); lcd_putsAtt(10 * FW, 0, s, 0); - DisplayScreenIndex(index, MAX_MAVLINK_MENU, INVERS); + displayScreenIndex(index, MAX_MAVLINK_MENU, INVERS); lcd_putcAtt(8 * FW, 0, (mav_heartbeat > 0) ? '*' : ' ', 0); } diff --git a/src/menus.cpp b/src/menus.cpp index 7e33c7c2f..5a75e460b 100644 --- a/src/menus.cpp +++ b/src/menus.cpp @@ -58,13 +58,26 @@ void menu_lcd_onoff(uint8_t x,uint8_t y, uint8_t value, uint8_t attr) #endif } -void DisplayScreenIndex(uint8_t index, uint8_t count, uint8_t attr) +void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr) { lcd_outdezAtt(DISPLAY_W,0,count,attr); lcd_putcAtt(1+DISPLAY_W-FW*(count>9 ? 3 : 2),0,'/',attr); lcd_outdezAtt(1+DISPLAY_W-FW*(count>9 ? 3 : 2),0,index+1,attr); } +#if !defined(PCBSTD) +void displayScrollbar(uint8_t x, uint8_t y, uint8_t h, uint16_t offset, uint16_t count, uint8_t visible) +{ + lcd_vlineStip(x, y, h, SOLID, WHITE); + lcd_vlineStip(x, y, h, DOTTED); + uint8_t yofs = (h * offset) / count; + uint8_t yhgt = (h * visible) / count; + if (yhgt + yofs > h) + yhgt = h - yofs; + lcd_vlineStip(x, y + yofs, yhgt, SOLID, BLACK); +} +#endif + #if defined(ROTARY_ENCODERS) int8_t scrollRE; int16_t p1valdiff; @@ -326,7 +339,12 @@ bool check(uint8_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTa } } s_noScroll = 0; - DisplayScreenIndex(curr, menuTabSize, attr); + displayScreenIndex(curr, menuTabSize, attr); + +#if defined(PCBX9D) + if (maxrow > 7) + displayScrollbar(DISPLAY_W-1, FH, DISPLAY_H-FH, s_pgOfs, maxrow, 7); +#endif } #if defined(ROTARY_ENCODERS) else if (m_posVert < 0) { @@ -608,6 +626,43 @@ int8_t switchMenuItem(uint8_t x, uint8_t y, int8_t value, uint8_t attr, uint8_t return value; } +#if defined(GVARS) +int8_t gvarMenuItem(uint8_t x, uint8_t y, int8_t value, int8_t min, int8_t max, uint8_t attr, uint8_t event) +{ + bool invers = attr&INVERS; + if (invers && event == EVT_KEY_LONG(KEY_MENU)) { + value = (value >= 126 ? REG_VALUE(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); + } + else { + lcd_outdezAtt(x, y, value, attr); + if (invers) CHECK_INCDEC_MODELVAR(event, value, min, max); + } + return value; +} + +void displayGVar(uint8_t x, uint8_t y, int8_t value) +{ + if (value > 125) { + putsStrIdx(x-FW-FWNUM, y, STR_GV, value - 125, 0); + } + else { + lcd_outdezAtt(x, y, value, 0); + } +} +#else +int8_t gvarMenuItem(uint8_t x, uint8_t y, int8_t value, int8_t min, int8_t max, uint8_t attr, uint8_t event) +{ + lcd_outdezAtt(x, y, value, attr); + if (attr&INVERS) CHECK_INCDEC_MODELVAR(event, value, min, max); + return value; +} +#endif + #if defined(SDCARD) const char *s_menu[MENU_MAX_LINES]; uint8_t s_menu_item = 0; @@ -629,14 +684,7 @@ const char * displayMenu(uint8_t event) } if (s_menu_count > display_count) { - // scroll bar - lcd_vlineStip(DISPLAY_W-11, 16, MENU_MAX_LINES * (FH+1) + 2, SOLID, WHITE); - lcd_vlineStip(DISPLAY_W-11, 16, MENU_MAX_LINES * (FH+1) + 2, DOTTED); - uint8_t ofs = (MENU_MAX_LINES * (FH+1) * s_menu_offset) / s_menu_count; - uint8_t hgt = (MENU_MAX_LINES * (FH+1) * MENU_MAX_LINES) / s_menu_count; - if (hgt + ofs > MENU_MAX_LINES * (FH+1)) - hgt = MENU_MAX_LINES * (FH+1) - ofs; - lcd_vlineStip(DISPLAY_W-11, 16 + ofs, 2 + hgt, SOLID, BLACK); + displayScrollbar(DISPLAY_W-11, 17, MENU_MAX_LINES * (FH+1), s_menu_offset, s_menu_count, MENU_MAX_LINES); } switch(event) { diff --git a/src/menus.h b/src/menus.h index 26a0caad5..9a30349c9 100644 --- a/src/menus.h +++ b/src/menus.h @@ -45,7 +45,13 @@ typedef void (*MenuFuncP)(uint8_t event); -void DisplayScreenIndex(uint8_t index, uint8_t count, uint8_t attr); +void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr); + +#if defined(PCBX9D) +#define MENUS_SCROLLBAR_WIDTH 2 +#else +#define MENUS_SCROLLBAR_WIDTH 0 +#endif #if defined(SDCARD) extern uint16_t s_pgOfs; @@ -210,6 +216,12 @@ TITLE(title) int8_t selectMenuItem(uint8_t x, uint8_t y, const pm_char *label, const pm_char *values, int8_t value, int8_t min, int8_t max, uint8_t attr, uint8_t event); uint8_t onoffMenuItem(uint8_t value, uint8_t x, uint8_t y, const pm_char *label, uint8_t attr, uint8_t event ); int8_t switchMenuItem(uint8_t x, uint8_t y, int8_t value, uint8_t attr, uint8_t event); +int8_t gvarMenuItem(uint8_t x, uint8_t y, int8_t value, int8_t min, int8_t max, uint8_t attr, uint8_t event); +#if defined(GVARS) +void displayGVar(uint8_t x, uint8_t y, int8_t value); +#else +#define displayGVar(x, y, v) lcd_outdez8(x, y, v) +#endif #define WARNING_TYPE_ASTERISK 0 #define WARNING_TYPE_CONFIRM 1 diff --git a/src/model_menus.cpp b/src/model_menus.cpp index a74330c02..3f98c0e99 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -418,7 +418,7 @@ void menuModelSelect(uint8_t event) lcd_outdezAtt(17*FW, 0, reusableBuffer.models.eepromfree, 0); #endif - DisplayScreenIndex(e_ModelSelect, DIM(menuTabModel), (sub == g_eeGeneral.currModel) ? INVERS : 0); + displayScreenIndex(e_ModelSelect, DIM(menuTabModel), (sub == g_eeGeneral.currModel) ? INVERS : 0); if (sub-s_pgOfs < 1) s_pgOfs = max(0, sub-1); else if (sub-s_pgOfs > 5) s_pgOfs = min(MAX_MODELS-7, sub-4); @@ -600,7 +600,8 @@ enum menuModelSetupItems { #define FIELD_TIMER_MAX 2 #endif -#define MODEL_PARAM_OFS (10*FW+2) +#define MODEL_SETUP_2ND_COLUMN (DISPLAY_W-11*FW-MENUS_SCROLLBAR_WIDTH) + void menuModelSetup(uint8_t event) { lcd_outdezNAtt(7*FW,0,g_eeGeneral.currModel+1,INVERS+LEADING0,2); @@ -624,7 +625,7 @@ void menuModelSetup(uint8_t event) switch(k) { case ITEM_MODEL_NAME: - editName(MODEL_PARAM_OFS, y, g_model.name, sizeof(g_model.name), event, attr, m_posHorz); + editName(MODEL_SETUP_2ND_COLUMN, y, g_model.name, sizeof(g_model.name), event, attr, m_posHorz); #if defined(PCBSKY9X) memcpy(ModelNames[g_eeGeneral.currModel], g_model.name, sizeof(g_model.name)); #endif @@ -635,12 +636,12 @@ void menuModelSetup(uint8_t event) { TimerData *timer = &g_model.timers[k-ITEM_MODEL_TIMER1]; putsStrIdx(0*FW, y, STR_TIMER, k-ITEM_MODEL_TIMER1+1); - putsTmrMode(MODEL_PARAM_OFS, y, timer->mode, (attr && m_posHorz==0) ? blink : 0); - putsTime(15*FW, y, timer->val, + putsTmrMode(MODEL_SETUP_2ND_COLUMN, y, timer->mode, (attr && m_posHorz==0) ? blink : 0); + putsTime(MODEL_SETUP_2ND_COLUMN+5*FW-2, y, timer->val, (attr && m_posHorz==1 ? blink:0), (attr && m_posHorz==2 ? blink:0) ); #if defined(PCBSKY9X) || defined(PCBGRUVIN9X) - lcd_putcAtt(20*FW+1, y, g_model.timersXtra[k-ITEM_MODEL_TIMER1].remanent ? 'R' : '-', (attr && m_posHorz==3) ? blink : 0); + lcd_putcAtt(MODEL_SETUP_2ND_COLUMN+10*FW-1, y, g_model.timersXtra[k-ITEM_MODEL_TIMER1].remanent ? 'R' : '-', (attr && m_posHorz==3) ? blink : 0); #endif if (attr && (s_editMode>0 || p1valdiff)) { div_t qr = div(timer->val, 60); @@ -668,15 +669,15 @@ void menuModelSetup(uint8_t event) } case ITEM_MODEL_EXTENDED_LIMITS: - g_model.extendedLimits = onoffMenuItem(g_model.extendedLimits, MODEL_PARAM_OFS, y, STR_ELIMITS, attr, event); + g_model.extendedLimits = onoffMenuItem(g_model.extendedLimits, MODEL_SETUP_2ND_COLUMN, y, STR_ELIMITS, attr, event); break; case ITEM_MODEL_EXTENDED_TRIMS: - g_model.extendedTrims = onoffMenuItem(g_model.extendedTrims, MODEL_PARAM_OFS, y, STR_ETRIMS, attr, event); + g_model.extendedTrims = onoffMenuItem(g_model.extendedTrims, MODEL_SETUP_2ND_COLUMN, y, STR_ETRIMS, attr, event); break; case ITEM_MODEL_TRIM_INC: - g_model.trimInc = selectMenuItem(MODEL_PARAM_OFS, y, STR_TRIMINC, STR_VTRIMINC, g_model.trimInc, 0, 4, attr, event); + g_model.trimInc = selectMenuItem(MODEL_SETUP_2ND_COLUMN, y, STR_TRIMINC, STR_VTRIMINC, g_model.trimInc, 0, 4, attr, event); break; case ITEM_MODEL_THROTTLE_TRACE: @@ -685,17 +686,17 @@ void menuModelSetup(uint8_t event) int8_t idx = 3; if (g_model.thrTraceSrc > NUM_POTS) idx = NUM_STICKS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+3+NUM_PPM+g_model.thrTraceSrc; else if (g_model.thrTraceSrc > 0) idx = NUM_STICKS+g_model.thrTraceSrc; - putsChnRaw(MODEL_PARAM_OFS, y, idx, attr); + putsChnRaw(MODEL_SETUP_2ND_COLUMN, y, idx, attr); if (attr) CHECK_INCDEC_MODELVAR(event, g_model.thrTraceSrc, 0, NUM_POTS+NUM_CHNOUT); break; } case ITEM_MODEL_THROTTLE_TRIM: - g_model.thrTrim = onoffMenuItem(g_model.thrTrim, MODEL_PARAM_OFS, y, STR_TTRIM, attr, event); + g_model.thrTrim = onoffMenuItem(g_model.thrTrim, MODEL_SETUP_2ND_COLUMN, y, STR_TTRIM, attr, event); break; case ITEM_MODEL_THROTTLE_WARNING: - g_model.disableThrottleWarning = !onoffMenuItem(!g_model.disableThrottleWarning, MODEL_PARAM_OFS, y, STR_THROTTLEWARNING, attr, event); + g_model.disableThrottleWarning = !onoffMenuItem(!g_model.disableThrottleWarning, MODEL_SETUP_2ND_COLUMN, y, STR_THROTTLEWARNING, attr, event); break; case ITEM_MODEL_SWITCHES_WARNING: @@ -703,7 +704,7 @@ void menuModelSetup(uint8_t event) lcd_putsLeft(y, STR_SWITCHWARNING); uint8_t states = g_model.switchWarningStates; char c = !(states & 1); - menu_lcd_onoff(MODEL_PARAM_OFS, y, c, attr); + menu_lcd_onoff(MODEL_SETUP_2ND_COLUMN, y, c, attr); if (attr) { s_editMode = 0; switch(event) { @@ -734,7 +735,7 @@ void menuModelSetup(uint8_t event) c = pgm_read_byte(STR_VSWITCHES - 2 + (3*i) + (i>=5 ? 6 : 0)); states >>= 1; } - lcd_putcAtt(MODEL_PARAM_OFS+2*FW+i*FW, y, c, attr); + lcd_putcAtt(MODEL_SETUP_2ND_COLUMN+2*FW+i*FW, y, c, attr); } } break; @@ -743,7 +744,7 @@ void menuModelSetup(uint8_t event) case ITEM_MODEL_BEEP_CENTER: lcd_putsLeft(y, STR_BEEPCTR); for (uint8_t i=0;i0 ? BLINK|INVERS : INVERS):0)); if (protocol <= PROTO_PPMSIM) { - lcd_putsiAtt(MODEL_PARAM_OFS+7*FW, y, STR_NCHANNELS, g_model.ppmNCH+2, (attr && m_posHorz==1) ? blink : 0); + lcd_putsiAtt(MODEL_SETUP_2ND_COLUMN+7*FW, y, STR_NCHANNELS, g_model.ppmNCH+2, (attr && m_posHorz==1) ? blink : 0); } #ifdef DSM2 else if (protocol == PROTO_DSM2) { if (attr && m_posHorz > 1) m_posHorz = 1; int8_t x = limit((int8_t)0, (int8_t)g_model.ppmNCH, (int8_t)2); g_model.ppmNCH = x; - lcd_putsiAtt(MODEL_PARAM_OFS+5*FW, y, STR_DSM2MODE, x, (attr && m_posHorz==1) ? blink : 0); + lcd_putsiAtt(MODEL_SETUP_2ND_COLUMN+5*FW, y, STR_DSM2MODE, x, (attr && m_posHorz==1) ? blink : 0); } #endif else if (attr) { @@ -792,11 +793,11 @@ void menuModelSetup(uint8_t event) case ITEM_MODEL_PROTOCOL_PARAMS: if (protocol <= PROTO_PPMSIM) { lcd_putsLeft( y, STR_PPMFRAME); - lcd_puts(MODEL_PARAM_OFS+3*FW, y, STR_MS); - lcd_outdezAtt(MODEL_PARAM_OFS, y, (int16_t)g_model.ppmFrameLength*5 + 225, ((attr && m_posHorz==0) ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0) | PREC1|LEFT); - lcd_putc(MODEL_PARAM_OFS+8*FW+2, y, 'u'); - lcd_outdezAtt(MODEL_PARAM_OFS+8*FW+2, y, (g_model.ppmDelay*50)+300, ((attr && m_posHorz==1) ? blink : 0)); - lcd_putcAtt(MODEL_PARAM_OFS+10*FW, y, g_model.pulsePol ? '+' : '-', (attr && m_posHorz==2) ? INVERS : 0); + lcd_puts(MODEL_SETUP_2ND_COLUMN+3*FW, y, STR_MS); + lcd_outdezAtt(MODEL_SETUP_2ND_COLUMN, y, (int16_t)g_model.ppmFrameLength*5 + 225, ((attr && m_posHorz==0) ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0) | PREC1|LEFT); + lcd_putc(MODEL_SETUP_2ND_COLUMN+8*FW+2, y, 'u'); + lcd_outdezAtt(MODEL_SETUP_2ND_COLUMN+8*FW+2, y, (g_model.ppmDelay*50)+300, ((attr && m_posHorz==1) ? blink : 0)); + lcd_putcAtt(MODEL_SETUP_2ND_COLUMN+10*FW, y, g_model.pulsePol ? '+' : '-', (attr && m_posHorz==2) ? INVERS : 0); if(attr && (s_editMode>0 || p1valdiff)) { switch (m_posHorz) { @@ -818,11 +819,11 @@ void menuModelSetup(uint8_t event) m_posHorz = 0; // limit 3 column row to 2 colums for DSM2 protocol (Rx_Num and RANGE fields) lcd_putsLeft(y, STR_RXNUM); - lcd_outdezNAtt(MODEL_PARAM_OFS-(IS_DSM2_PROTOCOL(protocol) ? 0 : 3*FW), y, g_model.modelId, ((attr && m_posHorz==0) ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0) | LEADING0|LEFT, 2); + lcd_outdezNAtt(MODEL_SETUP_2ND_COLUMN-(IS_DSM2_PROTOCOL(protocol) ? 0 : 3*FW), y, g_model.modelId, ((attr && m_posHorz==0) ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0) | LEADING0|LEFT, 2); #if defined(DSM2) if (IS_DSM2_PROTOCOL(protocol)) { // RANGE CHECK - lcd_putsnAtt(MODEL_PARAM_OFS+5*FW, y, PSTR("RANGErange")+5*(s_rangecheck_mode), 5, (m_posHorz==1 ? attr : 0)); + lcd_putsnAtt(MODEL_SETUP_2ND_COLUMN+5*FW, y, PSTR("RANGErange")+5*(s_rangecheck_mode), 5, (m_posHorz==1 ? attr : 0)); s_rangecheck_mode = (attr && m_posHorz==1 && s_editMode>0); // [MENU] key toggles range check mode } #endif @@ -832,7 +833,7 @@ void menuModelSetup(uint8_t event) #if defined(PXX) if (protocol == PROTO_PXX) { - lcd_putsAtt(MODEL_PARAM_OFS, y, STR_SYNCMENU, (m_posHorz==1 ? attr : 0)); + lcd_putsAtt(MODEL_SETUP_2ND_COLUMN, y, STR_SYNCMENU, (m_posHorz==1 ? attr : 0)); if (attr && m_posHorz==1) { s_editMode = false; if (event==EVT_KEY_LONG(KEY_MENU)) { @@ -1068,9 +1069,11 @@ void menuModelPhasesAll(uint8_t event) if (s_pgOfs != MAX_PHASES-6) return; #endif - att = (sub==MAX_PHASES && !trimsCheckTimer) ? INVERS : 0; - lcd_putsAtt(0, 7*FH, STR_CHECKTRIMS, att); - putsFlightPhase(6*FW, 7*FH, s_perout_flight_phase+1, att); + lcd_putsLeft(7*FH+1, STR_CHECKTRIMS); + putsFlightPhase(OFS_CHECKTRIMS, 7*FH+1, s_perout_flight_phase+1); + if (sub==MAX_PHASES && !trimsCheckTimer) { + lcd_status_line(); + } } #endif @@ -1526,15 +1529,13 @@ void menuModelExpoOne(uint8_t event) #endif case EXPO_FIELD_WIDTH: lcd_putsLeft(y, STR_WEIGHT); - lcd_outdezAtt(EXPO_ONE_2ND_COLUMN+3*FW, y, ed->weight, attr|INFLIGHT((int8_t&)ed->weight)); - if (attr) CHECK_INFLIGHT_INCDEC_MODELVAR(event, (int8_t&)ed->weight, 0, 100, 0, STR_DRWEIGHT); + ed->weight = gvarMenuItem(EXPO_ONE_2ND_COLUMN+3*FW, y, ed->weight, 0, 100, attr, event); break; case EXPO_FIELD_EXPO: lcd_putsLeft(y, STR_EXPO); if (ed->curveMode==MODE_EXPO || ed->curveParam==0) { ed->curveMode = MODE_EXPO; - lcd_outdezAtt(EXPO_ONE_2ND_COLUMN+3*FW, y, ed->curveParam, attr|INFLIGHT(ed->curveParam)); - if (attr) CHECK_INFLIGHT_INCDEC_MODELVAR(event, ed->curveParam, -100, 100, 0, STR_DREXPO); + ed->curveParam = gvarMenuItem(EXPO_ONE_2ND_COLUMN+3*FW, y, ed->curveParam, -100, 100, attr, event); } else { lcd_putsAtt(EXPO_ONE_2ND_COLUMN, y, STR_NA, attr); @@ -1634,13 +1635,11 @@ void menuModelMixOne(uint8_t event) break; case MIX_FIELD_WEIGHT: lcd_putsLeft(y, STR_WEIGHT); - lcd_outdezAtt(MIXES_2ND_COLUMN, y, md2->weight, attr|LEFT|INFLIGHT(md2->weight)); - if (attr) CHECK_INFLIGHT_INCDEC_MODELVAR(event, md2->weight, -125, 125, 0, STR_MIXERWEIGHT); + md2->weight = gvarMenuItem(MIXES_2ND_COLUMN, y, md2->weight, -125, 125, attr|LEFT, event); break; case MIX_FIELD_OFFSET: lcd_putsLeft(y, STR_OFFSET); - lcd_outdezAtt(MIXES_2ND_COLUMN, y, md2->sOffset, attr|LEFT|INFLIGHT(md2->sOffset)); - if (attr) CHECK_INFLIGHT_INCDEC_MODELVAR(event, md2->sOffset, -125, 125, 0, STR_MIXEROFFSET); + md2->sOffset = gvarMenuItem(MIXES_2ND_COLUMN, y, md2->sOffset, -125, 125, attr|LEFT, event); break; case MIX_FIELD_TRIM: { @@ -1661,10 +1660,12 @@ void menuModelMixOne(uint8_t event) } #if defined(CURVES) case MIX_FIELD_CURVE: + { + int8_t curveParam = md2->curveParam; lcd_putsLeft(y, STR_CURVE); - if (attr) { - int8_t curveParam = md2->curveParam; - if (md2->curveMode==MODE_CURVE) { + if (md2->curveMode == MODE_CURVE) { + putsCurve(MIXES_2ND_COLUMN, y, curveParam, attr); + if (attr) { if (event==EVT_KEY_FIRST(KEY_MENU) && (curveParam<0 || curveParam>=CURVE_BASE)){ s_curveChan = (curveParam<0 ? -curveParam-1 : curveParam-CURVE_BASE); pushMenu(menuModelCurveOne); @@ -1676,29 +1677,21 @@ void menuModelMixOne(uint8_t event) m_posHorz = 0; } } - else if (s_editMode>0) { - if (m_posHorz==0) { - int8_t tmp = 0; - CHECK_INCDEC_MODELVAR(event, tmp, -1, 1); - if (tmp != 0) { - md2->curveMode = MODE_CURVE; - md2->curveParam = tmp; - } - } - else { - CHECK_INCDEC_MODELVAR(event, md2->curveParam, -100, 100); - } - } - } - - if (md2->curveMode == MODE_CURVE) { - putsCurve(MIXES_2ND_COLUMN, y, md2->curveParam, attr); } else { lcd_putsAtt(MIXES_2ND_COLUMN, y, PSTR("Diff"), m_posHorz==0 ? attr : 0); - lcd_outdezAtt(MIXES_2ND_COLUMN+5*FW, y, md2->curveParam, LEFT|(m_posHorz==1 ? attr : 0)); + md2->curveParam = gvarMenuItem(MIXES_2ND_COLUMN+5*FW, y, curveParam, -100, 100, LEFT|(m_posHorz==1 ? attr : 0), s_editMode>0 ? event : 0); + if (attr && s_editMode>0 && m_posHorz==0) { + int8_t tmp = 0; + CHECK_INCDEC_MODELVAR(event, tmp, -1, 1); + if (tmp != 0) { + md2->curveMode = MODE_CURVE; + md2->curveParam = tmp; + } + } } break; + } #endif case MIX_FIELD_SWITCH: md2->swtch = switchMenuItem(MIXES_2ND_COLUMN, y, md2->swtch, attr, event); @@ -1924,15 +1917,12 @@ void menuModelExpoMix(uint8_t expo, uint8_t _event) uint8_t y = (cur-s_pgOfs)*FH; uint8_t attr = ((s_copyMode || sub != cur) ? 0 : INVERS); if (expo) { - lcd_outdezAtt(EXPO_LINE_WEIGHT_POS, y, ed->weight, attr | (isExpoActive(i) ? BOLD : 0)); - if (attr != 0) { - CHECK_INCDEC_MODELVAR(_event, ed->weight, 0, 100); - } + ed->weight = gvarMenuItem(EXPO_LINE_WEIGHT_POS, y, ed->weight, 0, 100, attr | (isExpoActive(i) ? BOLD : 0), _event); if (ed->curveMode == MODE_CURVE) putsCurve(EXPO_LINE_EXPO_POS-3*FW, y, ed->curveParam); else - lcd_outdezAtt(EXPO_LINE_EXPO_POS, y, ed->curveParam, 0); + displayGVar(EXPO_LINE_EXPO_POS, y, ed->curveParam); #if defined(PCBSKY9X) if (ed->name[0]) { @@ -1952,9 +1942,7 @@ void menuModelExpoMix(uint8_t expo, uint8_t _event) putsMixerSource(4*FW+0, y, md->srcRaw, isMixActive(i) ? BOLD : 0); - lcd_outdezAtt(11*FW+3, y, md->weight, attr); - if (attr != 0) - CHECK_INCDEC_MODELVAR(_event, md->weight, -125, 125); + md->weight = gvarMenuItem(11*FW+3, y, md->weight, -125, 125, attr, _event); #if defined(PCBSKY9X) if (md->name[0]) { @@ -1967,7 +1955,7 @@ void menuModelExpoMix(uint8_t expo, uint8_t _event) if (md->curveMode == MODE_CURVE) putsCurve(12*FW+2, y, md->curveParam); else - lcd_outdez8(15*FW+2, y, md->curveParam); + displayGVar(15*FW+2, y, md->curveParam); } if (md->swtch) putsSwitches(16*FW, y, md->swtch); @@ -2241,10 +2229,45 @@ void menuModelLimits(uint8_t event) } } +#if defined(GVARS) && defined(PCBSKY9X) +void menuModelRegisterOne(uint8_t event) +{ + model_gvar_t *reg = &g_model.gvars[s_curveChan]; + + putsStrIdx(11*FW, 0, STR_GV, s_curveChan+1); + + // TODO Translation + SUBMENU(PSTR("GLOBAL VAR"), 2, {ZCHAR|(sizeof(reg->name)-1), 0}); + + int8_t sub = m_posVert; + + for (uint8_t i=0, k=0, y=2*FH; i<2; i++, k++, y+=FH) { + uint8_t attr = (sub==k ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0); + switch(i) { + case 0: + editName(MIXES_2ND_COLUMN, y, reg->name, sizeof(reg->name), event, attr, m_posHorz); + break; + case 1: + lcd_putsLeft(y, PSTR("Value")); + lcd_outdezAtt(MIXES_2ND_COLUMN, y, reg->value, attr|LEFT); + if (attr) CHECK_INCDEC_MODELVAR(event, reg->value, -125, 125); + break; + } + } +} +#endif + #if defined(CURVES) + +#if defined(GVARS) +#define CURVE_SELECTED() (sub >= 0 && sub < MAX_CURVES) +#else +#define CURVE_SELECTED() (sub >= 0) +#endif + void menuModelCurvesAll(uint8_t event) { - SIMPLE_MENU(STR_MENUCURVES, menuTabModel, e_CurvesAll, 1+MAX_CURVES+MAX_REGISTERS); + SIMPLE_MENU(STR_MENUCURVES, menuTabModel, e_CurvesAll, 1+MAX_CURVES+MAX_GVARS); int8_t sub = m_posVert - 1; @@ -2258,14 +2281,16 @@ void menuModelCurvesAll(uint8_t event) #endif case EVT_KEY_FIRST(KEY_RIGHT): case EVT_KEY_FIRST(KEY_MENU): - if (sub >= 0 -#if defined(REGISTERS) - && sub < MAX_CURVES -#endif - ) { + if (CURVE_SELECTED()) { s_curveChan = sub; pushMenu(menuModelCurveOne); } +#if defined(GVARS) && defined(PCBSKY9X) + else if (sub >= MAX_CURVES) { + s_curveChan = sub-MAX_CURVES; + pushMenu(menuModelRegisterOne); + } +#endif break; } @@ -2273,26 +2298,32 @@ void menuModelCurvesAll(uint8_t event) uint8_t y = FH + i*FH; uint8_t k = i + s_pgOfs; uint8_t attr = (sub == k ? INVERS : 0); -#if defined(REGISTERS) +#if defined(GVARS) if (k < MAX_CURVES) { putsStrIdx(0, y, STR_CV, k+1, attr); } else { - if (attr && s_editMode>0) attr |= BLINK; - putsStrIdx(0, y, PSTR("Reg.X"), k-MAX_CURVES+1, 0); - lcd_outdezAtt(10*FW, y, g_model.registers[k-MAX_CURVES], attr); - if (attr) CHECK_INCDEC_MODELVAR(event, g_model.registers[k-MAX_CURVES], -125, 125); +#if defined(PCBSKY9X) + putsStrIdx(0, y, STR_GV, k-MAX_CURVES+1, attr); + if (sub >= MAX_CURVES) { + lcd_outdezAtt(10*FW, y, REG_VALUE(k-MAX_CURVES)); + lcd_putsnAtt(12*FW, y, g_model.gvars[k-MAX_CURVES].name, sizeof(g_model.gvars[k-MAX_CURVES].name), ZCHAR); + } +#else + putsStrIdx(0, y, STR_GV, k-MAX_CURVES+1); + if (sub >= MAX_CURVES) { + if (attr && s_editMode>0) attr |= BLINK; + lcd_outdezAtt(10*FW, y, REG_VALUE(k-MAX_CURVES), attr); + if (attr) CHECK_INCDEC_MODELVAR(event, g_model.gvars[k-MAX_CURVES], -125, 125); + } +#endif } #else putsStrIdx(0, y, STR_CV, k+1, attr); #endif } - if (sub >= 0 -#if defined(REGISTERS) - && sub < MAX_CURVES -#endif - ) { + if (CURVE_SELECTED()) { s_curveChan = sub; DrawCurve(curveFn, 25); } @@ -2605,7 +2636,7 @@ void menuModelFunctionSwitches(uint8_t event) case 1: if (sd->swtch) { uint8_t func_displayed; - if (sd->func < 16) { + if (sd->func < FUNC_TRAINER) { func_displayed = 0; putsChnRaw(11*FW-2, y, NUM_STICKS+NUM_POTS+NUM_ROTARY_ENCODERS+NUM_STICKS+2+3+NUM_PPM+sd->func+1, attr); } @@ -2614,8 +2645,20 @@ void menuModelFunctionSwitches(uint8_t event) if (sd->func != FUNC_TRAINER) putsChnRaw(13*FW-2, y, sd->func-FUNC_TRAINER, attr); } - else +#if defined(DEBUG) + else if (sd->func == FUNC_TEST) { + func_displayed = FUNC_TEST - 16 - NUM_STICKS - MAX_GVARS + 2; + } +#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); + } +#endif + else { func_displayed = 2 + sd->func - 16 - NUM_STICKS - 1; + } lcd_putsiAtt(5*FW-2, y, STR_VFSWFUNC, func_displayed, attr); if (active) { CHECK_INCDEC_MODELVAR( event, sd->func, 0, FUNC_MAX-1); @@ -2699,6 +2742,16 @@ void menuModelFunctionSwitches(uint8_t event) val_min = -125; val_max = 125; lcd_outdezAtt(18*FW, y, val_displayed, attr); } +#if defined(GVARS) + else if (sd->func >= FUNC_GVAR_X1 +#if defined(DEBUG) + && sd->func != FUNC_TEST +#endif + ) { + val_max = NUM_XCHNRAW-1; + putsChnRaw(17*FW, y, val_displayed+1, attr); + } +#endif else { if (attr) m_posHorz = ((event & EVT_KEY_MASK) == KEY_LEFT ? 1 : 3); break; diff --git a/src/myeeprom.h b/src/myeeprom.h index 49f944a72..74eac7b4e 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -374,6 +374,10 @@ enum Functions { FUNC_BACKGND_MUSIC, FUNC_BACKGND_MUSIC_PAUSE, #endif +#if defined(GVARS) + FUNC_GVAR_X1, + FUNC_GVAR_X2, +#endif #if defined(DEBUG) FUNC_TEST, // should remain the last before MAX as not added in companion9x #endif @@ -720,12 +724,23 @@ PACK(typedef struct t_TimerDataExtra { #define EXTRA_MODEL_FIELDS #endif -#if defined(REGISTERS) -#define MAX_REGISTERS 2 -#define EXTRA_REGISTERS uint8_t registers[MAX_REGISTERS] +#if defined(PCBSKY9X) +PACK(typedef struct { + int8_t value; + char name[6]; +}) model_gvar_t; +#define REG_VALUE(x) g_model.gvars[x].value #else -#define MAX_REGISTERS 0 -#define EXTRA_REGISTERS +typedef int8_t model_gvar_t; +#define REG_VALUE(x) g_model.gvars[x] +#endif + +#if defined(GVARS) +#define MAX_GVARS 2 +#define EXTRA_GVARS model_gvar_t gvars[MAX_GVARS] +#else +#define MAX_GVARS 0 +#define EXTRA_GVARS #endif PACK(typedef struct t_ModelData { @@ -766,7 +781,7 @@ PACK(typedef struct t_ModelData { EXTRA_MODEL_FIELDS; - EXTRA_REGISTERS; + EXTRA_GVARS; }) ModelData; extern EEGeneral g_eeGeneral; diff --git a/src/open9x.cpp b/src/open9x.cpp index 8b813b89a..245f0256d 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -442,13 +442,14 @@ void applyExpos(int16_t *anas) int16_t v = anas2[ed.chn]; if((v<0 && ed.mode&1) || (v>=0 && ed.mode&2)) { cur_chn = ed.chn; - if (ed.curveParam) { + int8_t curveParam = ed.curveParam; + if (curveParam) { if (ed.curveMode == MODE_CURVE) - v = applyCurve(v, ed.curveParam); + v = applyCurve(v, curveParam); else - v = expo(v, ed.curveParam); + v = expo(v, REG(curveParam, -100, 100)); } - v = ((int32_t)v * ed.weight) / 100; + v = ((int32_t)v * REG(ed.weight, 0, 100)) / 100; anas[cur_chn] = v; } } @@ -929,6 +930,26 @@ void incRotaryEncoder(uint8_t idx, int8_t inc) } #endif +#if defined(GVARS) +int8_t REG(int8_t x, int8_t min, int8_t max) +{ + int8_t result = x; + if (x >= 126) { + x -= 126; + result = REG_VALUE(x); + if (result < min) { + REG_VALUE(x) = result = min; + eeDirty(EE_MODEL); + } + if (result > max) { + REG_VALUE(x) = result = max; + eeDirty(EE_MODEL); + } + } + return result; +} +#endif + #if defined(FRSKY) || defined(PCBSKY9X) void putsTelemetryValue(uint8_t x, uint8_t y, int16_t val, uint8_t unit, uint8_t att) { @@ -1249,6 +1270,10 @@ void message(const pm_char *title, const pm_char *t, const char *last MESSAGE_SO clearKeyEvents(); } +#if defined(GVARS) +int8_t *trimPtr[NUM_STICKS] = { NULL, NULL, NULL, NULL }; +#endif + #if defined(PCBSTD) uint8_t checkTrim(uint8_t event) { @@ -1266,9 +1291,24 @@ void checkTrims() // LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP uint8_t idx = CONVERT_MODE(1+k/2) - 1; uint8_t phase = getTrimFlightPhase(s_perout_flight_phase, idx); +#if defined(GVARS) +#define TRIM_REUSED() trimPtr[idx] + int16_t before; + bool thro; + if (TRIM_REUSED()) { + before = *trimPtr[idx]; + thro = false; + } + else { + before = getRawTrimValue(phase, idx); + thro = (idx==THR_STICK && g_model.thrTrim); + } +#else +#define TRIM_REUSED() 0 int16_t before = getRawTrimValue(phase, idx); - int8_t v = (s==0) ? min(32, abs(before)/4+1) : 1 << (s-1); // 1=>1 2=>2 3=>4 4=>8 bool thro = (idx==THR_STICK && g_model.thrTrim); +#endif + int8_t v = (s==0) ? min(32, abs(before)/4+1) : 1 << (s-1); // 1=>1 2=>2 3=>4 4=>8 if (thro) v = 4; // if throttle trim and trim trottle then step=4 int16_t after = (k&1) ? before + v : before - v; // positive = k&1 #if defined(PCBSKY9X) @@ -1284,7 +1324,7 @@ void checkTrims() } if ((beforeTRIM_MAX) || (before>after && afterswtch; @@ -1990,7 +2042,7 @@ void evalFunctions() } } -#if defined(PCBSKY9X) +#if defined(PCBSKY9X) && defined(SDCARD) if ((shrt || lng) && (activeFunctions & function_mask)) { if (sd->func == FUNC_BACKGND_MUSIC) { STOP_PLAY(i+1); @@ -2058,6 +2110,17 @@ void evalFunctions() testFunc(); } #endif + +#if defined(GVARS) + else if (sd->func >= FUNC_GVAR_X1) { + 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); + } + else { + REG_VALUE(sd->func-FUNC_GVAR_X1) = limit((int16_t)-1250, getValue(FSW_PARAM(sd)), (int16_t)1250) / 10; + } + } +#endif } if (COMPLEX_SWITCH) { @@ -2279,7 +2342,10 @@ void perOut(uint8_t tick10ms) #endif //========== OFFSET =============== - if (apply_offset && md->sOffset) v += calc100toRESX(md->sOffset); + if (apply_offset) { + int8_t offset = REG(md->sOffset, -125, 125); + if (offset) v += calc100toRESX(offset); + } //========== TRIMS =============== if (!(s_perout_mode & e_perout_mode_notrims)) { @@ -2294,6 +2360,8 @@ void perOut(uint8_t tick10ms) v += trims[mix_trim]; } + int8_t weight = REG(md->weight, -125, 125); + //========== SPEED =============== if (s_perout_mode == e_perout_mode_normal && (md->speedUp || md->speedDown)) // there are delay values { @@ -2307,7 +2375,7 @@ void perOut(uint8_t tick10ms) //-100..100 => 32768 -> 100*83886/256 = 32768, For MAX we divide by 2 since it's asymmetrical if (tick10ms) { int32_t rate = (int32_t)DEL_MULT*2048*100*tick10ms; - if(md->weight) rate /= abs(md->weight); + if (weight) rate /= abs(weight); act[i] = (diff>0) ? ((md->speedUp>0) ? act[i]+(rate)/((int16_t)50*md->speedUp) : (int32_t)v*DEL_MULT) : ((md->speedDown>0) ? act[i]-(rate)/((int16_t)50*md->speedDown) : (int32_t)v*DEL_MULT) ; @@ -2328,14 +2396,15 @@ void perOut(uint8_t tick10ms) } //========== WEIGHT =============== - int32_t dv = (int32_t)v*md->weight; + int32_t dv = (int32_t)v*weight; //========== DIFFERENTIAL ========= if (md->curveMode == MODE_DIFFERENTIAL) { - if (md->curveParam>0 && dv<0) - dv = (dv * (100-md->curveParam)) / 100; - else if (md->curveParam<0 && dv>0) - dv = (dv * (100+md->curveParam)) / 100; + int8_t curveParam = REG(md->curveParam, -100, 100); + if (curveParam>0 && dv<0) + dv = (dv * (100-curveParam)) / 100; + else if (curveParam<0 && dv>0) + dv = (dv * (100+curveParam)) / 100; } int32_t *ptr = &chans[md->destCh]; // Save calculating address several times diff --git a/src/open9x.h b/src/open9x.h index 11fca9f01..910d6675c 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -661,7 +661,7 @@ extern uint8_t s_perout_mode; void perOut(uint8_t tick10ms); void perMain(); -NOINLINE void per10ms(); +NOINLINE void per10ms(); int16_t getValue(uint8_t i); bool getSwitch(int8_t swtch, bool nc); @@ -691,6 +691,12 @@ inline bool navigationRotaryEncoder(uint8_t event) } #endif +#if defined(GVARS) +int8_t REG(int8_t x, int8_t min, int8_t max); +#else +#define REG(x, min, max) (x) +#endif + extern uint16_t s_timeCumTot; extern uint16_t s_timeCumThr; //gewichtete laufzeit in 1/16 sec extern uint16_t s_timeCum16ThrP; //gewichtete laufzeit in 1/16 sec diff --git a/src/sky9x/debug.cpp b/src/sky9x/debug.cpp index 029f9ee36..bb9e16010 100644 --- a/src/sky9x/debug.cpp +++ b/src/sky9x/debug.cpp @@ -34,6 +34,8 @@ #include "../open9x.h" #include +#if !defined(SIMU) + /* * Outputs a character on the UART line. * @@ -142,3 +144,5 @@ void debugTask(void* pdata) } } + +#endif diff --git a/src/sky9x/debug.h b/src/sky9x/debug.h index 404fee4fb..dcaf82ded 100644 --- a/src/sky9x/debug.h +++ b/src/sky9x/debug.h @@ -36,7 +36,7 @@ #include -#if defined(DEBUG) +#if defined(DEBUG) && !defined(SIMU) #ifdef __cplusplus extern "C" { diff --git a/src/translations.cpp b/src/translations.cpp index 94df4f55f..80987555d 100644 --- a/src/translations.cpp +++ b/src/translations.cpp @@ -152,6 +152,7 @@ const pm_char STR_SLOWDOWN[] PROGMEM = TR_SLOWDOWN; const pm_char STR_SLOWUP[] PROGMEM = TR_SLOWUP; const pm_char STR_MIXER[] PROGMEM = TR_MIXER; const pm_char STR_CV[] PROGMEM = TR_CV; +const pm_char STR_GV[] PROGMEM = TR_GV; const pm_char STR_ACHANNEL[] PROGMEM = TR_ACHANNEL; const pm_char STR_RANGE[] PROGMEM = TR_RANGE; const pm_char STR_BAR[] PROGMEM = TR_BAR; @@ -286,7 +287,7 @@ const pm_char STR_INVERT_THR[] PROGMEM = TR_INVERT_THR; #if defined(ROTARY_ENCODERS) const pm_char STR_BACK[] PROGMEM = TR_BACK; -const pm_char STR_MIXERWEIGHT[] PROGMEM = TR_MIXERWEIGHT; +const pm_char STR_MIXERWEIGHT[] PROGMEM = TR_MIXERWEIGHT; // TODO remove them const pm_char STR_MIXEROFFSET[] PROGMEM = TR_MIXEROFFSET; const pm_char STR_DRWEIGHT[] PROGMEM = TR_DRWEIGHT; const pm_char STR_DREXPO[] PROGMEM = TR_DREXPO; diff --git a/src/translations.h b/src/translations.h index 5aaf5265f..eea4cd8af 100644 --- a/src/translations.h +++ b/src/translations.h @@ -259,6 +259,7 @@ extern const pm_char STR_SLOWDOWN[]; extern const pm_char STR_SLOWUP[]; extern const pm_char STR_MIXER[]; extern const pm_char STR_CV[]; +extern const pm_char STR_GV[]; extern const pm_char STR_ACHANNEL[]; extern const pm_char STR_RANGE[]; extern const pm_char STR_BAR[]; diff --git a/src/translations/cz.h b/src/translations/cz.h index 2b5aa9bcb..45f96cd76 100644 --- a/src/translations/cz.h +++ b/src/translations/cz.h @@ -129,12 +129,17 @@ #define TR_FSW_VOLUME #define TR_FSW_BG_MUSIC #endif -#ifdef DEBUG -#define TR_TEST "Test\0 " +#ifdef GVARS +#define TR_FSW_ADJUST_GVAR "Adjust \0 " #else -#define TR_TEST +#define TR_FSW_ADJUST_GVAR #endif -#define TR_VFSWFUNC "Bezpe\201\0 ""Tren\202r\0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Podsv\203tlen\204\0 " TR_FSW_BG_MUSIC TR_TEST +#ifdef DEBUG +#define TR_FSW_TEST "Test\0 " +#else +#define TR_FSW_TEST +#endif +#define TR_VFSWFUNC "Bezpe\201\0 ""Tren\202r\0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Podsv\203tlen\204\0 " TR_FSW_BG_MUSIC TR_FSW_ADJUST_GVAR TR_FSW_TEST #define LEN_VFSWRESET "\006" #define TR_VFSWRESET "Timer1""Timer2""V\207e ""Telem." @@ -244,7 +249,8 @@ #define TR_FADEIN "P\206echod Zap" #define TR_FADEOUT "P\206echod Vyp" #define TR_DEFAULT "(v\212choz\204)" -#define TR_CHECKTRIMS "Kont. \002 Trimy" +#define TR_CHECKTRIMS "\003Kont.\005Trimy" +#define OFS_CHECKTRIMS (9*FW) #define TR_SWASHTYPE "Typ Cykliky" #define TR_COLLECTIVE "Kolektiv" #define TR_SWASHRING "Cyklika" @@ -279,6 +285,7 @@ #define TR_SLOWUP "Zpomalen\204(+)" #define TR_MIXER "MIXER" #define TR_CV "CV" +#define TR_GV "GV" #define TR_ACHANNEL "A\002Kan\200l" #define TR_RANGE "Rozsah" #define TR_BAR "Bar" diff --git a/src/translations/de.h b/src/translations/de.h index de5afa48e..cc9c2481e 100644 --- a/src/translations/de.h +++ b/src/translations/de.h @@ -129,12 +129,17 @@ #define TR_FSW_VOLUME #define TR_FSW_BG_MUSIC #endif +#ifdef GVARS +#define TR_FSW_ADJUST_GVAR "Adjust \0 " +#else +#define TR_FSW_ADJUST_GVAR +#endif #ifdef DEBUG -#define TR_TEST "Test\0 " +#define TR_FSW_TEST "Test\0 " #else -#define TR_TEST +#define TR_FSW_TEST #endif -#define TR_VFSWFUNC "Safety\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_TEST +#define TR_VFSWFUNC "Safety\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_FSW_ADJUST_GVAR TR_FSW_TEST #define LEN_VFSWRESET "\006" #define TR_VFSWRESET "Timer1""Timer2""Alle ""Telem." @@ -244,7 +249,8 @@ #define TR_FADEIN "Fade In" #define TR_FADEOUT "Fade Out" #define TR_DEFAULT "(Standard)" -#define TR_CHECKTRIMS "Check\005Trims" +#define TR_CHECKTRIMS "\003Check\005Trims" +#define OFS_CHECKTRIMS (9*FW) #define TR_SWASHTYPE "Swash Type" #define TR_COLLECTIVE "Collective" #define TR_SWASHRING "Swash Ring" @@ -278,7 +284,8 @@ #define TR_SLOWDOWN "Langs. Unten" #define TR_SLOWUP "Langs. Oben" #define TR_MIXER "MIXER" -#define TR_CV "CV" +#define TR_CV "CV" +#define TR_GV "GV" #define TR_ACHANNEL "A\002channel" #define TR_RANGE "Range" #define TR_BAR "Bar" diff --git a/src/translations/en.h b/src/translations/en.h index e2f0c13e0..c5a34deef 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -129,12 +129,18 @@ #define TR_FSW_VOLUME #define TR_FSW_BG_MUSIC #endif -#ifdef DEBUG -#define TR_TEST "Test\0" +#ifdef GVARS +#define TR_FSW_ADJUST_GVAR "Adjust \0 " #else -#define TR_TEST +#define TR_FSW_ADJUST_GVAR #endif -#define TR_VFSWFUNC "Safety\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_TEST +#ifdef DEBUG +#define TR_FSW_TEST "Test\0" +#else +#define TR_FSW_TEST +#endif + +#define TR_VFSWFUNC "Safety\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_FSW_ADJUST_GVAR TR_FSW_TEST #define LEN_VFSWRESET "\006" #define TR_VFSWRESET "Timer1""Timer2""All ""Telem." @@ -244,7 +250,8 @@ #define TR_FADEIN "Fade In" #define TR_FADEOUT "Fade Out" #define TR_DEFAULT "(default)" -#define TR_CHECKTRIMS "Check\005Trims" +#define TR_CHECKTRIMS "\003Check\005Trims" +#define OFS_CHECKTRIMS (9*FW) #define TR_SWASHTYPE "Swash Type" #define TR_COLLECTIVE "Collective" #define TR_SWASHRING "Swash Ring" @@ -279,6 +286,7 @@ #define TR_SLOWUP "Slow Up" #define TR_MIXER "MIXER" #define TR_CV "CV" +#define TR_GV "GV" #define TR_ACHANNEL "A\002channel" #define TR_RANGE "Range" #define TR_BAR "Bar" diff --git a/src/translations/fr.h b/src/translations/fr.h index 47a873e76..2e379d354 100644 --- a/src/translations/fr.h +++ b/src/translations/fr.h @@ -124,12 +124,17 @@ #define TR_FSW_VOLUME #define TR_FSW_BG_MUSIC #endif -#ifdef DEBUG -#define TR_TEST "Test\0 " +#ifdef GVARS +#define TR_FSW_ADJUST_GVAR "Adjust \0 " #else -#define TR_TEST +#define TR_FSW_ADJUST_GVAR #endif -#define TR_VFSWFUNC "S\200cur.\0 ""Ecolage \0 ""Trim instant." TR_SOUND TR_HAPTIC "Remise \202 0\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "R\200tro\200cl.\0 " TR_FSW_BG_MUSIC TR_TEST +#ifdef DEBUG +#define TR_FSW_TEST "Test\0 " +#else +#define TR_FSW_TEST +#endif +#define TR_VFSWFUNC "S\200cur.\0 ""Ecolage \0 ""Trim instant." TR_SOUND TR_HAPTIC "Remise \202 0\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "R\200tro\200cl.\0 " TR_FSW_BG_MUSIC TR_FSW_ADJUST_GVAR TR_FSW_TEST #define LEN_VFSWRESET "\006" #define TR_VFSWRESET "Timer1""Timer2""Timers""T\200l\200m." @@ -243,7 +248,8 @@ #define TR_FADEIN "Fondu ON" #define TR_FADEOUT "Fondu OFF" #define TR_DEFAULT "(d\200faut)" -#define TR_CHECKTRIMS "V\200rif\005Trims" +#define TR_CHECKTRIMS "\003V\200rif\005Trims" +#define OFS_CHECKTRIMS (9*FW) #define TR_SWASHTYPE "Type de Plat." #define TR_COLLECTIVE "Collectif" #define TR_SWASHRING "Limite Cycl." @@ -277,6 +283,7 @@ #define TR_SLOWUP "Ralenti Bas" #define TR_MIXER "MIXEUR" #define TR_CV "CB" +#define TR_GV "GV" #define TR_ACHANNEL "A" #define TR_RANGE "Plage" #define TR_BAR "Barre" diff --git a/src/translations/it.h b/src/translations/it.h index 52adbd831..bed91f487 100644 --- a/src/translations/it.h +++ b/src/translations/it.h @@ -129,12 +129,17 @@ #define TR_FSW_VOLUME #define TR_FSW_BG_MUSIC #endif -#ifdef DEBUG -#define TR_TEST "Test\0 " +#ifdef GVARS +#define TR_FSW_ADJUST_GVAR "Adjust \0 " #else -#define TR_TEST +#define TR_FSW_ADJUST_GVAR #endif -#define TR_VFSWFUNC "Blocco\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_TEST +#ifdef DEBUG +#define TR_FSW_TEST "Test\0 " +#else +#define TR_FSW_TEST +#endif +#define TR_VFSWFUNC "Blocco\0 ""Trainer \0 ""Instant Trim " TR_SOUND TR_HAPTIC "Reset\0 " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Backlight\0 " TR_FSW_BG_MUSIC TR_FSW_ADJUST_GVAR TR_FSW_TEST #define LEN_VFSWRESET "\006" #define TR_VFSWRESET "Timer1""Timer2""Tutto ""Telem." @@ -244,7 +249,8 @@ #define TR_FADEIN "Diss.In" #define TR_FADEOUT "Diss.Out" #define TR_DEFAULT "(default)" -#define TR_CHECKTRIMS "Contr.\003 Trim" +#define TR_CHECKTRIMS "\003Contr.\004Trim" +#define OFS_CHECKTRIMS (9*FW) #define TR_SWASHTYPE "Tipo Ciclico" #define TR_COLLECTIVE "Collettivo" #define TR_SWASHRING "AnelloCiclico" @@ -279,6 +285,7 @@ #define TR_SLOWUP "Rall. S\200" #define TR_MIXER "MIXER" #define TR_CV "CV" +#define TR_GV "GV" #define TR_ACHANNEL "A\002ingresso" #define TR_RANGE "Range" #define TR_BAR "Barra" diff --git a/src/translations/se.h b/src/translations/se.h index 4be28a66d..2b23682f9 100644 --- a/src/translations/se.h +++ b/src/translations/se.h @@ -124,12 +124,17 @@ #define TR_FSW_VOLUME #define TR_FSW_BG_MUSIC #endif -#ifdef DEBUG -#define TR_TEST "Test\0 " +#ifdef GVARS +#define TR_FSW_ADJUST_GVAR "Adjust \0 " #else -#define TR_TEST +#define TR_FSW_ADJUST_GVAR #endif -#define TR_VFSWFUNC "S\201kra\0 ""Trainer\0 ""S\201tt Trim " TR_SOUND TR_HAPTIC "Nollst\201ll " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Bakgrundsljus" TR_FSW_BG_MUSIC TR_TEST +#ifdef DEBUG +#define TR_FSW_TEST "Test\0 " +#else +#define TR_FSW_TEST +#endif +#define TR_VFSWFUNC "S\201kra\0 ""Trainer\0 ""S\201tt Trim " TR_SOUND TR_HAPTIC "Nollst\201ll " TR_VVARIO TR_PLAY_TRACK TR_PLAY_VALUE TR_SDCLOGS TR_FSW_VOLUME "Bakgrundsljus" TR_FSW_BG_MUSIC TR_FSW_ADJUST_GVAR TR_FSW_TEST #define LEN_VFSWRESET "\006" #define TR_VFSWRESET "Timer1""Timer2""Allt ""Telem." @@ -241,7 +246,8 @@ #define TR_FADEIN "Tona In" #define TR_FADEOUT "Tona Ut" #define TR_DEFAULT "Standard" -#define TR_CHECKTRIMS "Kolla\005Trimmar" +#define TR_CHECKTRIMS "\003Kolla\005Trimmar" +#define OFS_CHECKTRIMS (9*FW) #define TR_SWASHTYPE "Swashtyp" #define TR_COLLECTIVE "Kollektiv" #define TR_SWASHRING "Swashring" @@ -276,6 +282,7 @@ #define TR_SLOWUP "Tr\202ghet Upp" #define TR_MIXER "MIXAR" #define TR_CV "KU" +#define TR_GV "GV" #define TR_ACHANNEL "A\002kanal " #define TR_RANGE "Omr\200de" #define TR_BAR "Data"