Merge pull request #621 from opentx/bsongis/Issue554_trims_relative_default

All good!
This commit is contained in:
Andre Bernet
2014-02-07 11:35:58 +01:00
17 changed files with 310 additions and 194 deletions
+17 -1
View File
@@ -122,7 +122,7 @@ PACK(typedef struct {
}) TimerData_v215;
PACK(typedef struct {
TRIMS_ARRAY;
int16_t trim[4];
int8_t swtch; // swtch of phase[0] is not used
char name[LEN_FP_NAME];
uint8_t fadeIn;
@@ -453,6 +453,22 @@ void ConvertModel_215_to_216(ModelData &model)
for (uint8_t i=0; i<9; i++) {
memcpy(&g_model.phaseData[i], &oldModel.phaseData[i], sizeof(oldModel.phaseData[i])); // the last 4 gvars will remain blank
#if defined(PCBTARANIS)
for (uint8_t t=0; t<4; t++) {
int trim = oldModel.phaseData[i].trim[t];
if (trim > 500) {
trim -= 501;
if (trim >= i)
trim += 1;
g_model.phaseData[i].trim[t].mode = 2*trim;
g_model.phaseData[i].trim[t].value = 0;
}
else {
g_model.phaseData[i].trim[t].mode = 2*i;
g_model.phaseData[i].trim[t].value = trim;
}
}
#endif
}
g_model.thrTraceSrc = oldModel.thrTraceSrc;
g_model.switchWarningStates = oldModel.switchWarningStates;
+27 -73
View File
@@ -1722,86 +1722,34 @@ 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,
ITEM_PHASES_SWITCH,
ITEM_PHASES_TRIMS,
ITEM_PHASES_TRIM_RUD,
ITEM_PHASES_TRIM_ELE,
ITEM_PHASES_TRIM_THR,
ITEM_PHASES_TRIM_AIL,
ITEM_PHASES_FADE_IN,
ITEM_PHASES_FADE_OUT,
ITEM_PHASES_COUNT,
ITEM_PHASES_LAST = ITEM_PHASES_COUNT-1
};
void editPhaseTrims(uint8_t x, uint8_t y, uint8_t phase, uint8_t event, uint8_t active)
bool isTrimModeAvailable(int16_t mode)
{
static uint8_t cursorPos = 0;
for (uint8_t t=0; t<NUM_STICKS; t++) {
putsTrimMode(x+t*FW, y, phase, t, (active && (s_editMode <= 0 || cursorPos==t)) ? INVERS : 0);
}
if (active) {
uint8_t cur = cursorPos;
if (s_editMode > 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);
}
}
switch (event) {
#if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBTARANIS)
case EVT_ROTARY_BREAK:
if (s_editMode == EDIT_MODIFY_FIELD) {
s_editMode = EDIT_MODIFY_STRING;
cur = 0;
}
else if (cur<NUM_STICKS-1)
cur++;
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 (cur<NUM_STICKS-1) cur++;
break;
#endif
#if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBTARANIS)
case EVT_ROTARY_LONG:
s_editMode = 0;
killEvents(event);
break;
#endif
}
}
else {
cur = 0;
}
cursorPos = cur;
}
return (mode == TRIM_MODE_NONE || (mode%2) == 0 || (mode/2) != (m_posVert-1));
}
void menuModelFlightModesAll(uint8_t event)
{
MENU(STR_MENUFLIGHTPHASES, menuTabModel, e_FlightModesAll, 1+MAX_PHASES+1, {0, NAVIGATION_LINE_BY_LINE|(ITEM_PHASES_LAST-2), NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, 0});
MENU(STR_MENUFLIGHTPHASES, menuTabModel, e_FlightModesAll, 1+MAX_PHASES+1, {0, NAVIGATION_LINE_BY_LINE|(ITEM_PHASES_LAST-5), NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_PHASES_LAST, 0});
int8_t sub = m_posVert - 1;
horzpos_t posHorz = m_posHorz;
if (sub==0 && posHorz > 0) { posHorz += 2; }
if (sub==0 && posHorz > 0) { posHorz += 5; }
if (sub<MAX_PHASES && posHorz>=0) {
displayColumnHeader(STR_PHASES_HEADERS, posHorz);
@@ -1828,35 +1776,41 @@ void menuModelFlightModesAll(uint8_t event)
for (uint8_t j=0; j<ITEM_PHASES_COUNT; j++) {
uint8_t attr = ((sub==k && posHorz==j) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
uint8_t active = (attr && (s_editMode>0 || p1valdiff)) ;
switch(j)
{
switch (j) {
case ITEM_PHASES_NAME:
editName(4*FW, y, p->name, 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, y, STR_DEFAULT);
}
else {
putsSwitches((5+LEN_FP_NAME)*FW+FW/2, y, p->swtch, attr);
putsSwitches((5+LEN_FP_NAME)*FW, y, p->swtch, attr);
if (active) CHECK_INCDEC_MODELSWITCH(event, p->swtch, -NUM_SWITCH, NUM_SWITCH);
}
break;
case ITEM_PHASES_TRIMS:
case ITEM_PHASES_TRIM_RUD:
case ITEM_PHASES_TRIM_ELE:
case ITEM_PHASES_TRIM_THR:
case ITEM_PHASES_TRIM_AIL:
if (k != 0) {
editPhaseTrims((10+LEN_FP_NAME)*FW+FW/2, y, k, event, attr);
uint8_t t = j-ITEM_PHASES_TRIM_RUD;
putsTrimMode((4+LEN_FP_NAME)*FW+j*(5*FW/2), y, k, t, attr);
if (active) {
trim_t & v = p->trim[t];
v.mode = checkIncDec(event, v.mode==TRIM_MODE_NONE ? -1 : v.mode, -1, 2*MAX_PHASES-1, EE_MODEL, isTrimModeAvailable);
}
}
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 +1819,7 @@ void menuModelFlightModesAll(uint8_t event)
}
}
#else // LCD_W >= 212
#else // PCBTARANIS
enum menuModelPhaseItems {
ITEM_MODEL_PHASE_NAME,
@@ -2909,7 +2863,7 @@ void menuModelExpoOne(uint8_t event)
case EXPO_FIELD_SCALE:
lcd_putsLeft(y, STR_SCALE);
putsTelemetryChannel(EXPO_ONE_2ND_COLUMN, y, ed->srcRaw - MIXSRC_FIRST_TELEM, convertTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1, ed->scale), LEFT|attr);
if (attr) ed->scale = checkIncDec(event, ed->scale, 0, maxTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1), EE_MODEL, NULL);
if (attr) ed->scale = checkIncDec(event, ed->scale, 0, maxTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1), EE_MODEL);
break;
#endif
+21 -1
View File
@@ -1159,9 +1159,28 @@ 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);
unsigned int mode = v.mode;
unsigned int p = mode >> 1;
if (mode == TRIM_MODE_NONE) {
lcd_putsAtt(x, y, "--", att);
}
else {
if (mode % 2 == 0)
lcd_putcAtt(x, y, ':', att|FIXEDWIDTH);
else
lcd_putcAtt(x, y, '+', att|FIXEDWIDTH);
lcd_putcAtt(lcdNextPos, 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;
@@ -1172,6 +1191,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)
+11 -1
View File
@@ -1101,8 +1101,18 @@ 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;
uint16_t mode:5;
}) trim_t;
#define TRIM_MODE_NONE 0x1F // 0b11111
#else
#define trim_t int16_t
#endif
#define TRIMS_ARRAY trim_t trim[4]
#define TRIMS_ARRAY_SIZE 8
#endif
+70 -10
View File
@@ -1665,38 +1665,82 @@ 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<MAX_PHASES; i++) {
trim_t v = getRawTrimValue(phase, idx);
if (v.mode < 0) {
return result;
}
else {
unsigned int p = v.mode >> 1;
if (p == phase || phase == 0) {
return result + v.value;
}
else {
phase = p;
if (v.mode % 2 != 0) {
result += v.value;
}
}
}
}
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; i<MAX_PHASES; i++) {
trim_t & v = phaseAddress(phase)->trim[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) {
phase = p;
}
else {
v.value = limit<int>(TRIM_EXTENDED_MIN, trim - getTrimValue(p, idx), TRIM_EXTENDED_MAX);
break;
}
}
#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<MAX_PHASES; i++) {
if (phase == 0) return 0;
int16_t trim = getRawTrimValue(phase, idx);
trim_t trim = getRawTrimValue(phase, idx);
if (trim <= TRIM_EXTENDED_MAX) return phase;
uint8_t result = trim-TRIM_EXTENDED_MAX-1;
if (result >= phase) result++;
@@ -1704,6 +1748,7 @@ uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx)
}
return 0;
}
#endif
#if defined(ROTARY_ENCODERS)
uint8_t getRotaryEncoderFlightPhase(uint8_t idx)
@@ -2344,7 +2389,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)
@@ -2360,13 +2405,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;
@@ -4739,7 +4792,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<int16_t>(TRIM_EXTENDED_MIN, (anas[i] + trims[i]) / 2, TRIM_EXTENDED_MAX);
setTrimValue(trim_phase, i, trim);
}
}
@@ -4797,9 +4850,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<MAX_PHASES; phase++) {
int16_t trim = getRawTrimValue(phase, i);
#if defined(PCBTARANIS)
// TODO needs to be tested.
trim_t trim = getRawTrimValue(phase, i);
if (trim.mode / 2 == phase)
setTrimValue(phase, i, trim.value - original_trim);
#else
trim_t trim = getRawTrimValue(phase, i);
if (trim <= TRIM_EXTENDED_MAX)
setTrimValue(phase, i, trim - original_trim);
#endif
}
}
}
+9 -4
View File
@@ -875,10 +875,15 @@ int8_t getMovedSwitch();
#define getFlightPhase() 0
#endif
extern uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx);
extern int16_t getRawTrimValue(uint8_t phase, uint8_t idx);
extern int16_t getTrimValue(uint8_t phase, uint8_t idx);
extern void setTrimValue(uint8_t phase, uint8_t idx, int16_t trim);
#if !defined(PCBTARANIS)
uint8_t getTrimFlightPhase(uint8_t phase, uint8_t idx);
#else
#define getTrimFlightPhase(phase, idx) (phase)
#endif
trim_t getRawTrimValue(uint8_t phase, uint8_t idx);
int getTrimValue(uint8_t phase, uint8_t idx);
void setTrimValue(uint8_t phase, uint8_t idx, int trim);
#if defined(ROTARY_ENCODERS)
int16_t getRotaryEncoder(uint8_t idx);
+1 -1
View File
@@ -711,7 +711,7 @@
#endif
// Taranis column headers
#define TR_PHASES_HEADERS { " Name ", " Switch ", " Trims ", " Fade In ", " Fade Out " }
#define TR_PHASES_HEADERS { " Name ", " Switch ", " Rudder Trim ", " Elevator Trim ", " Throttle Trim ", " Aileron Trim ", " Fade In ", " Fade Out " }
#define TR_LIMITS_HEADERS { " Name ", " Subtrim ", " Min ", " Max ", " Direction ", " Curve ", " PPM Center ", " Subtrim mode " }
#define TR_CSW_HEADERS { " Function ", " V1 ", " V2 ", " AND Switch ", " Duration ", " Delay " }