From cde13120ae276a182300fa36f6efc5d747b0a92f Mon Sep 17 00:00:00 2001 From: Michel Pastor Date: Wed, 12 Aug 2020 17:08:02 +0200 Subject: [PATCH] Take into account video aspect ratio when drawing AHI (#5962) --- src/main/io/osd.c | 8 ++++++-- src/main/io/osd.h | 1 + src/main/io/osd_grid.c | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 29bdaedd9..0e4586075 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -110,7 +110,6 @@ FILE_COMPILE_FOR_SPEED #endif #define VIDEO_BUFFER_CHARS_PAL 480 -#define IS_DISPLAY_PAL (displayScreenSize(osdDisplayPort) == VIDEO_BUFFER_CHARS_PAL) #define GFORCE_FILTER_TC 0.2 @@ -201,6 +200,11 @@ static int digitCount(int32_t value) return digits; } +bool osdDisplayIsPAL(void) +{ + return displayScreenSize(osdDisplayPort) == VIDEO_BUFFER_CHARS_PAL; +} + /** * Formats a number given in cents, to support non integer values * without using floating point math. Value is always right aligned @@ -2874,7 +2878,7 @@ static void osdShowStats(void) displayBeginTransaction(osdDisplayPort, DISPLAY_TRANSACTION_OPT_RESET_DRAWING); displayClearScreen(osdDisplayPort); - if (IS_DISPLAY_PAL) + if (osdDisplayIsPAL()) displayWrite(osdDisplayPort, statNameX, top++, " --- STATS ---"); if (STATE(GPS_FIX)) { diff --git a/src/main/io/osd.h b/src/main/io/osd.h index 6415b7530..f1510ac41 100755 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -280,6 +280,7 @@ typedef struct displayPort_s displayPort_t; typedef struct displayCanvas_s displayCanvas_t; void osdInit(displayPort_t *osdDisplayPort); +bool osdDisplayIsPAL(void); void osdUpdate(timeUs_t currentTimeUs); void osdStartFullRedraw(void); // Sets a fixed OSD layout ignoring the RC input. Set it diff --git a/src/main/io/osd_grid.c b/src/main/io/osd_grid.c index 26a1c6433..fe8124b97 100644 --- a/src/main/io/osd_grid.c +++ b/src/main/io/osd_grid.c @@ -34,6 +34,7 @@ #include "common/utils.h" #include "drivers/display.h" +#include "drivers/osd.h" #include "drivers/osd_symbols.h" #include "drivers/time.h" @@ -103,6 +104,11 @@ void osdGridDrawDirArrow(displayPort_t *display, unsigned gx, unsigned gy, float displayWriteChar(display, gx, gy, SYM_ARROW_UP + arrowOffset); } +static float osdGetAspectRatioCorrection(void) +{ + return osdDisplayIsPAL() ? 12.0f/15.0f : 12.0f/18.46f; +} + void osdGridDrawArtificialHorizon(displayPort_t *display, unsigned gx, unsigned gy, float pitchAngle, float rollAngle) { UNUSED(gx); @@ -117,10 +123,11 @@ void osdGridDrawArtificialHorizon(displayPort_t *display, unsigned gx, unsigned static int8_t previous_written[OSD_AHI_PREV_SIZE]; static int8_t previous_orient = -1; - float pitch_rad_to_char = (float)(OSD_AHI_HEIGHT / 2 + 0.5) / DEGREES_TO_RADIANS(osdConfig()->ahi_max_pitch); + const float pitch_rad_to_char = (float)(OSD_AHI_HEIGHT / 2 + 0.5) / DEGREES_TO_RADIANS(osdConfig()->ahi_max_pitch); - float ky = sin_approx(rollAngle); - float kx = cos_approx(rollAngle); + const float ky = sin_approx(rollAngle); + const float kx = cos_approx(rollAngle); + const float ratio = osdGetAspectRatioCorrection(); if (previous_orient != -1) { for (int i = 0; i < OSD_AHI_PREV_SIZE; ++i) { @@ -138,7 +145,7 @@ void osdGridDrawArtificialHorizon(displayPort_t *display, unsigned gx, unsigned previous_orient = 0; for (int8_t dx = -OSD_AHI_WIDTH / 2; dx <= OSD_AHI_WIDTH / 2; dx++) { - float fy = dx * (ky / kx) + pitchAngle * pitch_rad_to_char + 0.49f; + float fy = (ratio * dx) * (ky / kx) + pitchAngle * pitch_rad_to_char + 0.49f; int8_t dy = floorf(fy); const uint8_t chX = elemPosX + dx, chY = elemPosY - dy; uint16_t c; @@ -155,7 +162,7 @@ void osdGridDrawArtificialHorizon(displayPort_t *display, unsigned gx, unsigned previous_orient = 1; for (int8_t dy = -OSD_AHI_HEIGHT / 2; dy <= OSD_AHI_HEIGHT / 2; dy++) { - const float fx = (dy - pitchAngle * pitch_rad_to_char) * (kx / ky) + 0.5f; + const float fx = ((dy / ratio) - pitchAngle * pitch_rad_to_char) * (kx / ky) + 0.5f; const int8_t dx = floorf(fx); const uint8_t chX = elemPosX + dx, chY = elemPosY - dy; uint16_t c; -- 2.11.4.GIT