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

Merge pull request #5535 from iNavFlight/agh_canvas_ahi_line

[CANVAS] Add alternate AHI style with a single line
This commit is contained in:
giacomo892 2020-04-15 13:52:58 +02:00 committed by GitHub
commit a70ac0399b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 10 deletions

View file

@ -138,6 +138,9 @@ tables:
- name: pidTypeTable
values: ["NONE", "PID", "PIFF", "AUTO"]
enum: pidType_e
- name: osd_ahi_style
values: ["DEFAULT", "LINE"]
enum: osd_ahi_style_e
groups:
- name: PG_GYRO_CONFIG
@ -1999,6 +2002,9 @@ groups:
min: 10
max: 13
- name: osd_ahi_style
table: osd_ahi_style
- name: PG_SYSTEM_CONFIG
type: systemConfig_t
headers: ["fc/config.h"]

View file

@ -198,7 +198,7 @@ static bool osdDisplayHasCanvas;
#define AH_SIDEBAR_WIDTH_POS 7
#define AH_SIDEBAR_HEIGHT_POS 3
PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 10);
PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 11);
static int digitCount(int32_t value)
{

View file

@ -187,6 +187,11 @@ typedef enum {
OSD_ALIGN_RIGHT
} osd_alignment_e;
typedef enum {
OSD_AHI_STYLE_DEFAULT,
OSD_AHI_STYLE_LINE,
} osd_ahi_style_e;
typedef struct osdConfig_s {
// Layouts
uint16_t item_pos[OSD_LAYOUT_COUNT][OSD_ITEM_COUNT];
@ -245,6 +250,7 @@ typedef struct osdConfig_s {
bool osd_failsafe_switch_layout;
uint8_t plus_code_digits; // Number of digits to use in OSD_PLUS_CODE
uint8_t osd_ahi_style;
} osdConfig_t;
PG_DECLARE(osdConfig_t, osdConfig);

View file

@ -32,6 +32,7 @@
#define AHI_MIN_DRAW_INTERVAL_MS 100
#define AHI_MAX_DRAW_INTERVAL_MS 1000
#define AHI_CROSSHAIR_MARGIN 6
#include "common/log.h"
#include "common/maths.h"
@ -45,6 +46,7 @@
#include "drivers/time.h"
#include "io/osd_common.h"
#include "io/osd.h"
void osdCanvasDrawVarioShape(displayCanvas_t *canvas, unsigned ex, unsigned ey, float zvel, bool erase)
{
@ -162,7 +164,6 @@ static void osdDrawArtificialHorizonShapes(displayCanvas_t *canvas, float pitchA
{
int barWidth = (OSD_AHI_WIDTH - 1) * canvas->gridElementWidth;
int levelBarWidth = barWidth * (3.0/4);
int crosshairMargin = 6;
float pixelsPerDegreeLevel = 3.5f;
int borderSize = 3;
char buf[12];
@ -220,9 +221,9 @@ static void osdDrawArtificialHorizonShapes(displayCanvas_t *canvas, float pitchA
if (ii == 0) {
displayCanvasSetLineOutlineType(canvas, DISPLAY_CANVAS_OUTLINE_TYPE_BOTTOM);
displayCanvasMoveToPoint(canvas, -barWidth / 2, 0);
displayCanvasStrokeLineToPoint(canvas, -crosshairMargin, 0);
displayCanvasStrokeLineToPoint(canvas, -AHI_CROSSHAIR_MARGIN, 0);
displayCanvasMoveToPoint(canvas, barWidth / 2, 0);
displayCanvasStrokeLineToPoint(canvas, crosshairMargin, 0);
displayCanvasStrokeLineToPoint(canvas, AHI_CROSSHAIR_MARGIN, 0);
continue;
}
@ -257,6 +258,48 @@ static void osdDrawArtificialHorizonShapes(displayCanvas_t *canvas, float pitchA
displayCanvasContextPop(canvas);
}
void osdDrawArtificialHorizonLine(displayCanvas_t *canvas, float pitchAngle, float rollAngle, bool erase)
{
int barWidth = (OSD_AHI_WIDTH - 1) * canvas->gridElementWidth;
int maxHeight = canvas->height;
float pixelsPerDegreeLevel = 1.5f;
int maxWidth = (OSD_AHI_WIDTH + 1) * canvas->gridElementWidth;
int lx = (canvas->width - maxWidth) / 2;
displayCanvasContextPush(canvas);
displayCanvasClipToRect(canvas, lx, 0, maxWidth, maxHeight);
osdGridBufferClearPixelRect(canvas, lx, 0, maxWidth, maxHeight);
if (erase) {
displayCanvasSetStrokeColor(canvas, DISPLAY_CANVAS_COLOR_TRANSPARENT);
displayCanvasSetLineOutlineColor(canvas, DISPLAY_CANVAS_COLOR_TRANSPARENT);
} else {
displayCanvasSetStrokeColor(canvas, DISPLAY_CANVAS_COLOR_WHITE);
displayCanvasSetLineOutlineColor(canvas, DISPLAY_CANVAS_COLOR_BLACK);
}
float pitchDegrees = RADIANS_TO_DEGREES(pitchAngle);
float pitchOffset = -pitchDegrees * pixelsPerDegreeLevel;
float translateX = canvas->width / 2;
float translateY = canvas->height / 2;
displayCanvasCtmTranslate(canvas, 0, pitchOffset);
displayCanvasCtmRotate(canvas, rollAngle);
displayCanvasCtmTranslate(canvas, translateX, translateY);
displayCanvasSetStrokeWidth(canvas, 2);
displayCanvasSetLineOutlineType(canvas, DISPLAY_CANVAS_OUTLINE_TYPE_BOTTOM);
displayCanvasMoveToPoint(canvas, -barWidth / 2, 0);
displayCanvasStrokeLineToPoint(canvas, -AHI_CROSSHAIR_MARGIN, 0);
displayCanvasMoveToPoint(canvas, barWidth / 2, 0);
displayCanvasStrokeLineToPoint(canvas, AHI_CROSSHAIR_MARGIN, 0);
displayCanvasContextPop(canvas);
}
void osdCanvasDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float pitchAngle, float rollAngle)
{
UNUSED(display);
@ -271,12 +314,20 @@ void osdCanvasDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *can
float totalError = fabsf(prevPitchAngle - pitchAngle) + fabsf(prevRollAngle - rollAngle);
if ((now > nextDrawMinMs && totalError > 0.05f)|| now > nextDrawMaxMs) {
int x, y, w, h;
osdArtificialHorizonRect(canvas, &x, &y, &w, &h);
displayCanvasClearRect(canvas, x, y, w, h);
osdDrawArtificialHorizonShapes(canvas, pitchAngle, rollAngle);
switch ((osd_ahi_style_e)osdConfig()->osd_ahi_style) {
case OSD_AHI_STYLE_DEFAULT:
{
int x, y, w, h;
osdArtificialHorizonRect(canvas, &x, &y, &w, &h);
displayCanvasClearRect(canvas, x, y, w, h);
osdDrawArtificialHorizonShapes(canvas, pitchAngle, rollAngle);
break;
}
case OSD_AHI_STYLE_LINE:
osdDrawArtificialHorizonLine(canvas, prevPitchAngle, prevRollAngle, true);
osdDrawArtificialHorizonLine(canvas, pitchAngle, rollAngle, false);
break;
}
prevPitchAngle = pitchAngle;
prevRollAngle = rollAngle;
nextDrawMinMs = now + AHI_MIN_DRAW_INTERVAL_MS;