From 046a4d253dc3e79f5d05d7e1e4e7254854cb978b Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 24 Jan 2014 16:49:33 +0100 Subject: [PATCH] [Taranis] Issue #554 Radio part done. We have now modes on trims. Let's say we are configuring the Rudder Trim on phase 1: - R:0 => Rudder trim = Rudder trim(phase 0) - R+0 => Rudder trim = Rudder trim(phase 0) + Rudder trim(phase 1) - R-- => Rudder trim is OFF Still needs to be done: - The result on screen is awful. I need ideas. Martin? - Companion conversions / UI for this feature - R+1 when configuring Rudder Trim on phase 1 should be impossible --- radio/src/gui/menu_model.cpp | 45 +++++++------------- radio/src/lcd.cpp | 25 ++++++++++- radio/src/myeeprom.h | 11 ++++- radio/src/opentx.cpp | 81 +++++++++++++++++++++++++++++++----- radio/src/opentx.h | 13 ++++-- 5 files changed, 128 insertions(+), 47 deletions(-) diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 6f2309e1b..130f0cb72 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -1722,7 +1722,7 @@ FlightModesType editFlightModes(uint8_t x, uint8_t y, uint8_t event, FlightModes return value; } -#if LCD_W >= 212 +#if defined(PCBTARANIS) enum FlightModesItems { ITEM_PHASES_NAME, @@ -1739,7 +1739,7 @@ void editPhaseTrims(uint8_t x, uint8_t y, uint8_t phase, uint8_t event, uint8_t static uint8_t cursorPos = 0; for (uint8_t t=0; t 0) { if (p1valdiff || IS_ROTARY_RIGHT(event) || IS_ROTARY_LEFT(event) || event==EVT_KEY_FIRST(KEY_DOWN) || event==EVT_KEY_FIRST(KEY_UP) || event==EVT_KEY_REPT(KEY_DOWN) || event==EVT_KEY_REPT(KEY_UP)) { - int16_t v = getRawTrimValue(phase, cur); - if (v < TRIM_EXTENDED_MAX) v = TRIM_EXTENDED_MAX; - v = checkIncDec(event, v, TRIM_EXTENDED_MAX, TRIM_EXTENDED_MAX+MAX_PHASES-1, EE_MODEL); - if (checkIncDec_Ret) { - if (v == TRIM_EXTENDED_MAX) v = 0; - setTrimValue(phase, cur, v); - } + PhaseData *p = phaseAddress(phase); + trim_t & v = p->trim[cur]; + v.mode = checkIncDec(event, v.mode, -1, 2*MAX_PHASES-1, EE_MODEL); } switch (event) { -#if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBTARANIS) - case EVT_ROTARY_BREAK: + case EVT_KEY_BREAK(KEY_ENTER): if (s_editMode == EDIT_MODIFY_FIELD) { s_editMode = EDIT_MODIFY_STRING; cur = 0; @@ -1768,23 +1763,11 @@ void editPhaseTrims(uint8_t x, uint8_t y, uint8_t phase, uint8_t event, uint8_t else s_editMode = 0; break; -#endif -#if !defined(PCBTARANIS) - case EVT_KEY_BREAK(KEY_LEFT): - if (cur>0) cur--; - break; - case EVT_KEY_BREAK(KEY_RIGHT): - if (curname, sizeof(p->name), event, attr); + editName(4*FW-1, y, p->name, sizeof(p->name), event, attr); break; case ITEM_PHASES_SWITCH: if (k == 0) { - lcd_puts((5+LEN_FP_NAME)*FW+FW/2, y, STR_DEFAULT); + lcd_puts((5+LEN_FP_NAME)*FW-FW/2, y, STR_DEFAULT); } else { - putsSwitches((5+LEN_FP_NAME)*FW+FW/2, y, p->swtch, attr); + putsSwitches((5+LEN_FP_NAME)*FW-FW/2, y, p->swtch, attr); if (active) CHECK_INCDEC_MODELSWITCH(event, p->swtch, -MAX_SWITCH, MAX_SWITCH); } break; case ITEM_PHASES_TRIMS: if (k != 0) { - editPhaseTrims((10+LEN_FP_NAME)*FW+FW/2, y, k, event, attr); + editPhaseTrims((10+LEN_FP_NAME)*FW-2*FW, y, k, event, attr); } break; case ITEM_PHASES_FADE_IN: - lcd_outdezAtt(29*FW, y, (10/DELAY_STEP)*p->fadeIn, attr|PREC1); + lcd_outdezAtt(32*FW-2, y, (10/DELAY_STEP)*p->fadeIn, attr|PREC1); if (active) p->fadeIn = checkIncDec(event, p->fadeIn, 0, DELAY_MAX, EE_MODEL|NO_INCDEC_MARKS); break; case ITEM_PHASES_FADE_OUT: - lcd_outdezAtt(34*FW, y, (10/DELAY_STEP)*p->fadeOut, attr|PREC1); + lcd_outdezAtt(35*FW, y, (10/DELAY_STEP)*p->fadeOut, attr|PREC1); if (active) p->fadeOut = checkIncDec(event, p->fadeOut, 0, DELAY_MAX, EE_MODEL|NO_INCDEC_MARKS); break; @@ -1865,7 +1848,7 @@ void menuModelFlightModesAll(uint8_t event) } } -#else // LCD_W >= 212 +#else // PCBTARANIS enum menuModelPhaseItems { ITEM_MODEL_PHASE_NAME, diff --git a/radio/src/lcd.cpp b/radio/src/lcd.cpp index 7b2cbe7f0..cdcf18323 100644 --- a/radio/src/lcd.cpp +++ b/radio/src/lcd.cpp @@ -1162,9 +1162,31 @@ void putsTmrMode(xcoord_t x, uint8_t y, int8_t mode, LcdFlags att) putsSwitches(x, y, mode-(TMR_VAROFS-1), att); } +#if defined(PCBTARANIS) void putsTrimMode(xcoord_t x, uint8_t y, uint8_t phase, uint8_t idx, LcdFlags att) { - int16_t v = getRawTrimValue(phase, idx); + trim_t v = getRawTrimValue(phase, idx); + + putsChnLetter(x, y, idx+1, att); + + if (v.mode < 0) { + lcd_putsAtt(x+FWNUM, y, "--", att); + } + else { + uint8_t p = v.mode >> 1; + if (v.mode % 2 == 0) { + lcd_putcAtt(x+FWNUM, y, '+', att); + } + else { + lcd_putcAtt(x+FWNUM, y, ':', att); + } + lcd_putcAtt(x+2*FWNUM, y, '0'+p, att); + } +} +#else +void putsTrimMode(xcoord_t x, uint8_t y, uint8_t phase, uint8_t idx, LcdFlags att) +{ + trim_t v = getRawTrimValue(phase, idx); if (v > TRIM_EXTENDED_MAX) { uint8_t p = v - TRIM_EXTENDED_MAX - 1; @@ -1175,6 +1197,7 @@ void putsTrimMode(xcoord_t x, uint8_t y, uint8_t phase, uint8_t idx, LcdFlags at putsChnLetter(x, y, idx+1, att); } } +#endif #if ROTARY_ENCODERS > 0 void putsRotaryEncoderMode(xcoord_t x, uint8_t y, uint8_t phase, uint8_t idx, LcdFlags att) diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index d91b0d507..d0973c639 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -1070,8 +1070,17 @@ PACK(typedef struct t_SwashRingData { // Swash Ring data #if defined(PCBSTD) #define TRIMS_ARRAY int8_t trim[4]; int8_t trim_ext:8 #define TRIMS_ARRAY_SIZE 5 + #define trim_t int16_t #else - #define TRIMS_ARRAY int16_t trim[4] + #if defined(PCBTARANIS) + PACK(typedef struct { + int16_t value:11; + int16_t mode:5; + }) trim_t; + #else + #define trim_t int16_t + #endif + #define TRIMS_ARRAY trim_t trim[4] #define TRIMS_ARRAY_SIZE 8 #endif diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index cdefd2577..50609e63d 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1640,38 +1640,83 @@ uint8_t getFlightPhase() } #endif -int16_t getRawTrimValue(uint8_t phase, uint8_t idx) +trim_t getRawTrimValue(uint8_t phase, uint8_t idx) { PhaseData *p = phaseAddress(phase); #if defined(PCBSTD) - return (((int16_t)p->trim[idx]) << 2) + ((p->trim_ext >> (2*idx)) & 0x03); + return (((trim_t)p->trim[idx]) << 2) + ((p->trim_ext >> (2*idx)) & 0x03); #else return p->trim[idx]; #endif } -int16_t getTrimValue(uint8_t phase, uint8_t idx) +int getTrimValue(uint8_t phase, uint8_t idx) { +#if defined(PCBTARANIS) + int result = 0; + for (uint8_t i=0; i> 1; + if (p == phase || phase == 0) { + return result + v.value; + } + else { + phase = p; + if (v.mode % 2 == 0) + result += v.value; + else + result = 0; + } + } + } + return 0; +#else return getRawTrimValue(getTrimFlightPhase(phase, idx), idx); +#endif } -void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim) +void setTrimValue(uint8_t phase, uint8_t idx, int trim) { +#if defined(PCBTARANIS) + for (uint8_t i=0; itrim[idx]; + if (v.mode < 0) + return; + unsigned int p = v.mode >> 1; + if (p == phase || phase == 0) { + v.value = trim; + break;; + } + else if (v.mode % 2 == 0) { + v.value = limit(-500, trim - getTrimValue(p, idx), 500); + break; + } + else { + phase = p; + } + } +#elif defined(PCBSTD) PhaseData *p = phaseAddress(phase); -#if defined(PCBSTD) p->trim[idx] = (int8_t)(trim >> 2); - p->trim_ext = (p->trim_ext & ~(0x03 << (2*idx))) + (((trim & 0x03) << (2*idx))); + idx <<= 1; + p->trim_ext = (p->trim_ext & ~(0x03 << idx)) + (((trim & 0x03) << idx)); #else + PhaseData *p = phaseAddress(phase); p->trim[idx] = trim; #endif eeDirty(EE_MODEL); } +#if !defined(PCBTARANIS) uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx) { for (uint8_t i=0; i= phase) result++; @@ -1679,6 +1724,7 @@ uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx) } return 0; } +#endif #if defined(ROTARY_ENCODERS) uint8_t getRotaryEncoderFlightPhase(uint8_t idx) @@ -2309,7 +2355,7 @@ uint8_t checkTrim(uint8_t event) // LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP uint8_t idx = CONVERT_MODE((uint8_t)k/2); uint8_t phase; - int16_t before; + int before; bool thro; #if defined(GVARS) @@ -2325,13 +2371,21 @@ uint8_t checkTrim(uint8_t event) } else { phase = getTrimFlightPhase(s_perout_flight_phase, idx); +#if defined(PCBTARANIS) + before = getTrimValue(phase, idx); +#else before = getRawTrimValue(phase, idx); +#endif thro = (idx==THR_STICK && g_model.thrTrim); } #else #define TRIM_REUSED() 0 phase = getTrimFlightPhase(s_perout_flight_phase, idx); +#if defined(PCBTARANIS) + before = getTrimValue(phase, idx); +#else before = getRawTrimValue(phase, idx); +#endif thro = (idx==THR_STICK && g_model.thrTrim); #endif int8_t trimInc = g_model.trimInc + 1; @@ -4671,7 +4725,7 @@ void instantTrim() if (i!=THR_STICK) { // don't instant trim the throttle stick uint8_t trim_phase = getTrimFlightPhase(s_perout_flight_phase, i); - int16_t trim = limit((int16_t)TRIM_EXTENDED_MIN, (int16_t)((anas[i] + trims[i]) / 2), (int16_t)TRIM_EXTENDED_MAX); + int16_t trim = limit(TRIM_EXTENDED_MIN, (anas[i] + trims[i]) / 2, TRIM_EXTENDED_MAX); setTrimValue(trim_phase, i, trim); } } @@ -4729,9 +4783,16 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim if (i!=THR_STICK || !g_model.thrTrim) { int16_t original_trim = getTrimValue(s_perout_flight_phase, i); for (uint8_t phase=0; phase