Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ahi pitch when inverted #9609

Merged
merged 6 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/main/io/osd_canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void osdDrawArtificialHorizonLine(displayCanvas_t *canvas, float pitchAngle, flo
displayCanvasContextPop(canvas);
}

static bool osdCanvasDrawArtificialHorizonWidget(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float pitchAngle, float rollAngle)
static bool osdCanvasDrawArtificialHorizonWidget(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float pitchAngle, float rollAngle, bool isInverted)
{
UNUSED(display);
UNUSED(p);
Expand All @@ -345,7 +345,12 @@ static bool osdCanvasDrawArtificialHorizonWidget(displayPort_t *display, display
int ahiWidth = osdConfig()->ahi_width;
int ahiX = (canvas->width - ahiWidth) / 2;
int ahiHeight = osdConfig()->ahi_height;
int ahiY = ((canvas->height - ahiHeight) / 2) + osdConfig()->ahi_vertical_offset;
int ahiY = ((canvas->height - ahiHeight) / 2);
if (isInverted)
ahiY -= osdConfig()->ahi_vertical_offset;
else
ahiY += osdConfig()->ahi_vertical_offset;

if (ahiY < 0) {
ahiY = 0;
}
Expand Down Expand Up @@ -397,7 +402,7 @@ static bool osdCanvasDrawArtificialHorizonWidget(displayPort_t *display, display
return false;
}

void osdCanvasDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float pitchAngle, float rollAngle)
void osdCanvasDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float pitchAngle, float rollAngle, bool isInverted)
{
UNUSED(display);
UNUSED(p);
Expand All @@ -412,7 +417,7 @@ void osdCanvasDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *can
float totalError = fabsf(prevPitchAngle - pitchAngle) + fabsf(prevRollAngle - rollAngle);
if ((now > nextDrawMinMs && totalError > 0.05f)|| now > nextDrawMaxMs) {

if (!osdCanvasDrawArtificialHorizonWidget(display, canvas, p, pitchAngle, rollAngle)) {
if (!osdCanvasDrawArtificialHorizonWidget(display, canvas, p, pitchAngle, rollAngle, isInverted)) {
switch ((osd_ahi_style_e)osdConfig()->ahi_style) {
case OSD_AHI_STYLE_DEFAULT:
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/io/osd_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ typedef struct osdDrawPoint_s osdDrawPoint_t;

void osdCanvasDrawVario(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float zvel);
void osdCanvasDrawDirArrow(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float degrees);
void osdCanvasDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float pitchAngle, float rollAngle);
void osdCanvasDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float pitchAngle, float rollAngle, bool isInverted);
void osdCanvasDrawHeadingGraph(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, int heading);
bool osdCanvasDrawSidebars(displayPort_t *display, displayCanvas_t *canvas);
13 changes: 10 additions & 3 deletions src/main/io/osd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include "navigation/navigation.h"
#include "sensors/pitotmeter.h"


#if defined(USE_OSD) || defined(USE_DJI_HD_OSD)

PG_REGISTER_WITH_RESET_TEMPLATE(osdCommonConfig_t, osdCommonConfig, PG_OSD_COMMON_CONFIG, 0);
Expand Down Expand Up @@ -148,13 +147,21 @@ void osdDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *canvas, c
{
uint8_t gx;
uint8_t gy;
bool isInverted = false;

// Correct pitch when inverted
if (rollAngle < -1.570796f || rollAngle > 1.570796f) {
isInverted = true;
pitchAngle = -pitchAngle;
}

#if defined(USE_CANVAS)
if (canvas) {
osdCanvasDrawArtificialHorizon(display, canvas, p, pitchAngle, rollAngle);
osdCanvasDrawArtificialHorizon(display, canvas, p, pitchAngle, rollAngle, isInverted);
} else {
#endif
osdDrawPointGetGrid(&gx, &gy, display, canvas, p);
osdGridDrawArtificialHorizon(display, gx, gy, pitchAngle, rollAngle);
osdGridDrawArtificialHorizon(display, gx, gy, pitchAngle, rollAngle, isInverted);
#if defined(USE_CANVAS)
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/main/io/osd_grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ 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)
void osdGridDrawArtificialHorizon(displayPort_t *display, unsigned gx, unsigned gy, float pitchAngle, float rollAngle, bool isInverted)
{
UNUSED(gx);
UNUSED(gy);
UNUSED(isInverted);

uint8_t elemPosX;
uint8_t elemPosY;
Expand Down
2 changes: 1 addition & 1 deletion src/main/io/osd_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ typedef struct displayPort_s displayPort_t;

void osdGridDrawVario(displayPort_t *display, unsigned gx, unsigned gy, float zvel);
void osdGridDrawDirArrow(displayPort_t *display, unsigned gx, unsigned gy, float degrees);
void osdGridDrawArtificialHorizon(displayPort_t *display, unsigned gx, unsigned gy, float pitchAngle, float rollAngle);
void osdGridDrawArtificialHorizon(displayPort_t *display, unsigned gx, unsigned gy, float pitchAngle, float rollAngle, bool isInverted);
void osdGridDrawHeadingGraph(displayPort_t *display, unsigned gx, unsigned gy, int heading);
void osdGridDrawSidebars(displayPort_t *display);
Loading