Skip to content

Add throttle gauge option to OSD #10725

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/main/drivers/osd_symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@
#define SYM_RX_BAND 0x169 // 361 RX Band
#define SYM_RX_MODE 0x16A // 362 RX Mode

#define SYM_THR_GAUGE_EMPTY 0x16B // 363 Throttle gauge empty
#define SYM_THR_GAUGE_HALF 0x16C // 364 Throttle gauge 1 step
#define SYM_THR_GAUGE_FULL 0x16D // 365 Throttle gauge 2 steps

#define SYM_AH_CH_TYPE3 0x190 // 400 to 402, crosshair 3
#define SYM_AH_CH_TYPE4 0x193 // 403 to 405, crosshair 4
#define SYM_AH_CH_TYPE5 0x196 // 406 to 408, crosshair 5
Expand Down
8 changes: 8 additions & 0 deletions src/main/io/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,13 @@ static bool osdDrawSingleElement(uint8_t item)
return true;
}

case OSD_THROTTLE_GAUGE:
{
bool useScaled = navigationIsControllingThrottle();
osdThrottleGauge(osdDisplayPort, osdGetDisplayPortCanvas(), OSD_DRAW_POINT_GRID(elemPosX, elemPosY), getThrottlePercent(useScaled));
return true;
}

#if defined(USE_BARO) || defined(USE_GPS)
case OSD_VARIO:
{
Expand Down Expand Up @@ -4246,6 +4253,7 @@ void pgResetFn_osdLayoutsConfig(osdLayoutsConfig_t *osdLayoutsConfig)
osdLayoutsConfig->item_pos[0][OSD_ATTITUDE_ROLL] = OSD_POS(1, 7);
osdLayoutsConfig->item_pos[0][OSD_ATTITUDE_PITCH] = OSD_POS(1, 8);

osdLayoutsConfig->item_pos[0][OSD_THROTTLE_GAUGE] = OSD_POS(23, 5);
// avoid OSD_VARIO under OSD_CROSSHAIRS
osdLayoutsConfig->item_pos[0][OSD_VARIO] = OSD_POS(23, 5);
// OSD_VARIO_NUM at the right of OSD_VARIO
Expand Down
1 change: 1 addition & 0 deletions src/main/io/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ typedef enum {
OSD_H_DIST_TO_FENCE,
OSD_V_DIST_TO_FENCE,
OSD_NAV_FW_ALT_CONTROL_RESPONSE,
OSD_THROTTLE_GAUGE,
OSD_ITEM_COUNT // MUST BE LAST
} osd_items_e;

Expand Down
61 changes: 61 additions & 0 deletions src/main/io/osd_canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,67 @@ static void osdCanvasVarioRect(int *y, int *h, displayCanvas_t *canvas, int midY
*h = height;
}

void osdCanvasDrawThrottleGauge(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, uint8_t thrPos)
{
UNUSED(display);

static uint8_t prevThr = 0;

if (ABS(prevThr - thrPos) < 10) {
return;
}

// Make sure we clear the grid buffer
uint8_t gx;
uint8_t gy;
osdDrawPointGetGrid(&gx, &gy, display, canvas, p);
osdGridBufferClearGridRect(gx, gy, 1, OSD_THROTTLE_GAUGE_HEIGHT_ROWS);

int x = gx * canvas->gridElementWidth;
int w = canvas->gridElementWidth;
int y = gy * canvas->gridElementHeight;
int h = OSD_THROTTLE_GAUGE_HEIGHT_ROWS * canvas->gridElementHeight;

displayCanvasClearRect(canvas, x, y, w, h);

if (thrPos >= 100)
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 4), SYM_THR_GAUGE_FULL, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else if (thrPos >= 90)
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 4), SYM_THR_GAUGE_HALF, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 4), SYM_THR_GAUGE_EMPTY, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);

if (thrPos >= 80)
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 3), SYM_THR_GAUGE_FULL, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else if (thrPos >= 70)
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 3), SYM_THR_GAUGE_HALF, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 3), SYM_THR_GAUGE_EMPTY, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);

if (thrPos >= 60)
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 2), SYM_THR_GAUGE_FULL, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else if (thrPos >= 50)
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 2), SYM_THR_GAUGE_HALF, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else
displayCanvasDrawCharacter(canvas, x, y + (canvas->gridElementHeight * 2), SYM_THR_GAUGE_EMPTY, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);

if (thrPos >= 40)
displayCanvasDrawCharacter(canvas, x, y + canvas->gridElementHeight, SYM_THR_GAUGE_FULL, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else if (thrPos >= 30)
displayCanvasDrawCharacter(canvas, x, y + canvas->gridElementHeight, SYM_THR_GAUGE_HALF, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else
displayCanvasDrawCharacter(canvas, x, y + canvas->gridElementHeight, SYM_THR_GAUGE_EMPTY, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);

if (thrPos >= 20)
displayCanvasDrawCharacter(canvas, x, y, SYM_THR_GAUGE_FULL, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else if (thrPos >= 10)
displayCanvasDrawCharacter(canvas, x, y, SYM_THR_GAUGE_HALF, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);
else
displayCanvasDrawCharacter(canvas, x, y, SYM_THR_GAUGE_EMPTY, DISPLAY_CANVAS_BITMAP_OPT_ERASE_TRANSPARENT);

prevThr = thrPos;
}

void osdCanvasDrawVario(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float zvel)
{
UNUSED(display);
Expand Down
1 change: 1 addition & 0 deletions src/main/io/osd_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct displayPort_s displayPort_t;
typedef struct displayCanvas_s displayCanvas_t;
typedef struct osdDrawPoint_s osdDrawPoint_t;

void osdCanvasDrawThrottleGauge(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, uint8_t thrPos);
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);
Expand Down
17 changes: 17 additions & 0 deletions src/main/io/osd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ void osdDrawPointGetPixels(int *px, int *py, const displayPort_t *display, const
}
}

void osdThrottleGauge(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, uint8_t thrPos)
{
uint8_t gx;
uint8_t gy;

#if defined(USE_CANVAS)
if (canvas) {
osdCanvasDrawThrottleGauge(display, canvas, p, thrPos);
} else {
#endif
osdDrawPointGetGrid(&gx, &gy, display, canvas, p);
osdGridDrawThrottleGauge(display, gx, gy, thrPos);
#if defined(USE_CANVAS)
}
#endif
}

void osdDrawVario(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float zvel)
{
uint8_t gx;
Expand Down
3 changes: 3 additions & 0 deletions src/main/io/osd_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ int16_t osdGetSpeedFromSelectedSource(void);
#define OSD_VARIO_CM_S_PER_ARROW 50 // 1 arrow = 50cm/s
#define OSD_VARIO_HEIGHT_ROWS 5

#define OSD_THROTTLE_GAUGE_HEIGHT_ROWS 5

#define OSD_AHI_HEIGHT 9
#define OSD_AHI_WIDTH 11
#define OSD_AHI_PREV_SIZE (OSD_AHI_WIDTH > OSD_AHI_HEIGHT ? OSD_AHI_WIDTH : OSD_AHI_HEIGHT)
Expand Down Expand Up @@ -92,6 +94,7 @@ typedef struct osdDrawPoint_s {
void osdDrawPointGetGrid(uint8_t *gx, uint8_t *gy, const displayPort_t *display, const displayCanvas_t *canvas, const osdDrawPoint_t *p);
void osdDrawPointGetPixels(int *px, int *py, const displayPort_t *display, const displayCanvas_t *canvas, const osdDrawPoint_t *p);

void osdThrottleGauge(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, uint8_t thrPos);
void osdDrawVario(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float zvel);
// Draws an arrow at the given point, where 0 degrees points to the top of the viewport and
// positive angles result in clockwise rotation. If eraseBefore is true, the rect surrouing
Expand Down
32 changes: 32 additions & 0 deletions src/main/io/osd_grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,38 @@ typedef struct osd_sidebar_s {
uint8_t idle;
} osd_sidebar_t;

void osdGridDrawThrottleGauge(displayPort_t *display, unsigned gx, unsigned gy, uint8_t thrPos)
{
uint16_t thrChars[] = {SYM_THR_GAUGE_EMPTY, SYM_THR_GAUGE_EMPTY, SYM_THR_GAUGE_EMPTY, SYM_THR_GAUGE_EMPTY, SYM_THR_GAUGE_EMPTY};

if (thrPos >= 100)
thrChars[0] = SYM_THR_GAUGE_FULL;
else if (thrPos >= 90)
thrChars[0] = SYM_THR_GAUGE_HALF;
if (thrPos >= 80)
thrChars[1] = SYM_THR_GAUGE_FULL;
else if (thrPos >= 70)
thrChars[1] = SYM_THR_GAUGE_HALF;
if (thrPos >= 60)
thrChars[2] = SYM_THR_GAUGE_FULL;
else if (thrPos >= 50)
thrChars[2] = SYM_THR_GAUGE_HALF;
if (thrPos >= 40)
thrChars[3] = SYM_THR_GAUGE_FULL;
else if (thrPos >= 30)
thrChars[3] = SYM_THR_GAUGE_HALF;
if (thrPos >= 20)
thrChars[4] = SYM_THR_GAUGE_FULL;
else if (thrPos >= 10)
thrChars[4] = SYM_THR_GAUGE_HALF;

displayWriteChar(display, gx, gy, thrChars[0]);
displayWriteChar(display, gx, gy + 1, thrChars[1]);
displayWriteChar(display, gx, gy + 2, thrChars[2]);
displayWriteChar(display, gx, gy + 3, thrChars[3]);
displayWriteChar(display, gx, gy + 4, thrChars[4]);
}

void osdGridDrawVario(displayPort_t *display, unsigned gx, unsigned gy, float zvel)
{
int v = zvel / OSD_VARIO_CM_S_PER_ARROW;
Expand Down
1 change: 1 addition & 0 deletions src/main/io/osd_grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

typedef struct displayPort_s displayPort_t;

void osdGridDrawThrottleGauge(displayPort_t *display, unsigned gx, unsigned gy, uint8_t thrPos);
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);
Expand Down
Loading