1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 00:35:18 +03:00

[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
This commit is contained in:
Bertrand Songis 2014-01-24 16:49:33 +01:00
parent 6fd9c47649
commit 046a4d253d
5 changed files with 128 additions and 47 deletions

View file

@ -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<NUM_STICKS; t++) {
putsTrimMode(x+t*FW, y, phase, t, (active && (s_editMode <= 0 || cursorPos==t)) ? INVERS : 0);
putsTrimMode(x+t*(3*FW-2), y, phase, t, (active && (s_editMode <= 0 || cursorPos==t)) ? INVERS : 0);
}
if (active) {
@ -1747,18 +1747,13 @@ void editPhaseTrims(uint8_t x, uint8_t y, uint8_t phase, uint8_t event, uint8_t
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);
}
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 (cur<NUM_STICKS-1) cur++;
break;
#endif
#if defined(ROTARY_ENCODER_NAVIGATION) || defined(PCBTARANIS)
case EVT_ROTARY_LONG:
case EVT_KEY_LONG(KEY_ENTER):
s_editMode = 0;
killEvents(event);
break;
#endif
}
}
else {
@ -1831,32 +1814,32 @@ void menuModelFlightModesAll(uint8_t event)
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-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,

View file

@ -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)

View file

@ -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

View file

@ -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<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;
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; 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) {
v.value = limit<int>(-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<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++;
@ -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<int16_t>(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<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
}
}
}

View file

@ -867,10 +867,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);