Merge pull request #454 from EdgeTX/trim-fixes

Trim fixes
This commit is contained in:
Raphael Coeffic
2021-07-15 16:27:35 +02:00
committed by GitHub
2 changed files with 24 additions and 9 deletions
+13 -4
View File
@@ -44,13 +44,17 @@ void MainViewHorizontalTrim::paint(BitmapBuffer * dc)
trimMax = TRIM_MAX; trimMax = TRIM_MAX;
} }
int16_t dispVal = value;
if (dispVal < trimMin) dispVal = trimMin;
if (dispVal > trimMax) dispVal = trimMax;
// Trim line // Trim line
dc->drawSolidFilledRect( dc->drawSolidFilledRect(
TRIM_SQUARE_SIZE / 2, (height() - TRIM_LINE_WIDTH - 1) / 2, TRIM_SQUARE_SIZE / 2, (height() - TRIM_LINE_WIDTH - 1) / 2,
width() - TRIM_SQUARE_SIZE + 1, TRIM_LINE_WIDTH, DEFAULT_COLOR); width() - TRIM_SQUARE_SIZE + 1, TRIM_LINE_WIDTH, DEFAULT_COLOR);
// Trim square // Trim square
coord_t x = divRoundClosest((width() - TRIM_SQUARE_SIZE) * (value - trimMin), coord_t x = divRoundClosest((width() - TRIM_SQUARE_SIZE) * (dispVal - trimMin),
trimMax - trimMin); trimMax - trimMin);
drawTrimSquare(dc, x, 0, drawTrimSquare(dc, x, 0,
(value < TRIM_MIN || value > TRIM_MAX) (value < TRIM_MIN || value > TRIM_MAX)
@@ -85,15 +89,20 @@ void MainViewVerticalTrim::paint(BitmapBuffer * dc)
trimMax = TRIM_MAX; trimMax = TRIM_MAX;
} }
int16_t dispVal = value;
if (dispVal < trimMin) dispVal = trimMin;
if (dispVal > trimMax) dispVal = trimMax;
// Trim line // Trim line
dc->drawSolidFilledRect((width() - TRIM_LINE_WIDTH) / 2, TRIM_SQUARE_SIZE / 2, dc->drawSolidFilledRect((width() - TRIM_LINE_WIDTH) / 2, TRIM_SQUARE_SIZE / 2,
TRIM_LINE_WIDTH, height() - TRIM_SQUARE_SIZE + 1, TRIM_LINE_WIDTH, height() - TRIM_SQUARE_SIZE + 1,
DEFAULT_COLOR); DEFAULT_COLOR);
// Trim square // Trim square
coord_t y = height() - TRIM_SQUARE_SIZE - coord_t y =
divRoundClosest((height() - TRIM_SQUARE_SIZE) * (value - trimMin), height() - TRIM_SQUARE_SIZE -
trimMax - trimMin); divRoundClosest((height() - TRIM_SQUARE_SIZE) * (dispVal - trimMin),
trimMax - trimMin);
drawTrimSquare(dc, 0, y, drawTrimSquare(dc, 0, y,
(value < TRIM_MIN || value > TRIM_MAX) (value < TRIM_MIN || value > TRIM_MAX)
? HIGHLIGHT_COLOR /* TODO add a color */ ? HIGHLIGHT_COLOR /* TODO add a color */
+11 -5
View File
@@ -1003,21 +1003,26 @@ void checkTrims()
else else
#endif #endif
{ {
if (before>TRIM_MIN && after<=TRIM_MIN) { int16_t tMax = g_model.extendedTrims ? TRIM_EXTENDED_MAX : TRIM_MAX;
int16_t tMin = g_model.extendedTrims ? TRIM_EXTENDED_MIN : TRIM_MIN;
if (before > tMin && after <= tMin) {
beepTrim = true; beepTrim = true;
AUDIO_TRIM_MIN(); AUDIO_TRIM_MIN();
killEvents(event); killEvents(event);
} }
else if (before<TRIM_MAX && after>=TRIM_MAX) { else if (before < tMax && after >= tMax) {
beepTrim = true; beepTrim = true;
AUDIO_TRIM_MAX(); AUDIO_TRIM_MAX();
killEvents(event); killEvents(event);
} }
if ((before<after && after>TRIM_MAX) || (before>after && after<TRIM_MIN)) { // Allow only move into the right direction if over the limits
if (!g_model.extendedTrims) after = before; if ((before < after && after > tMax) || // increasing over tMax
(before > after && after < tMin)) { // decreasing under tMin
after = before;
} }
// Clip at hard limits
if (after < TRIM_EXTENDED_MIN) { if (after < TRIM_EXTENDED_MIN) {
after = TRIM_EXTENDED_MIN; after = TRIM_EXTENDED_MIN;
} }
@@ -1586,7 +1591,8 @@ void instantTrim()
} }
} }
if (addTrim && abs(delta) >= INSTANT_TRIM_MARGIN) { if (addTrim && abs(delta) >= INSTANT_TRIM_MARGIN) {
int16_t trim = limit<int16_t>(TRIM_EXTENDED_MIN, (delta + trims[stick]) / 2, TRIM_EXTENDED_MAX); int16_t trim = limit<int16_t>(
TRIM_EXTENDED_MIN, (delta + trims[stick]) / 2, TRIM_EXTENDED_MAX);
setTrimValue(trimFlightMode, stick, trim); setTrimValue(trimFlightMode, stick, trim);
} }
} }