2 * This file is part of INAV.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 * You can obtain one at http://mozilla.org/MPL/2.0/.
8 * Alternatively, the contents of this file may be used under the terms
9 * of the GNU General Public License Version 3, as described below:
11 * This file is free software: you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by the
13 * Free Software Foundation, either version 3 of the License, or (at your
14 * option) any later version.
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see http://www.gnu.org/licenses/.
24 * @author Alberto Garcia Hierro <alberto@garciahierro.com>
29 #include "common/utils.h"
31 #include "config/parameter_group.h"
32 #include "config/parameter_group_ids.h"
34 #include "drivers/display.h"
35 #include "drivers/display_canvas.h"
36 #include "drivers/osd.h"
38 #include "fc/settings.h"
40 #include "io/osd_canvas.h"
41 #include "io/osd_common.h"
42 #include "io/osd_grid.h"
44 #include "navigation/navigation.h"
45 #include "sensors/pitotmeter.h"
47 #if defined(USE_OSD) || defined(USE_DJI_HD_OSD)
49 PG_REGISTER_WITH_RESET_TEMPLATE(osdCommonConfig_t
, osdCommonConfig
, PG_OSD_COMMON_CONFIG
, 0);
51 PG_RESET_TEMPLATE(osdCommonConfig_t
, osdCommonConfig
,
52 .speedSource
= SETTING_OSD_SPEED_SOURCE_DEFAULT
55 int16_t osdGetSpeedFromSelectedSource(void) {
57 switch (osdCommonConfig()->speedSource
) {
58 case OSD_SPEED_SOURCE_GROUND
:
59 speed
= gpsSol
.groundSpeed
;
61 case OSD_SPEED_SOURCE_3D
:
62 speed
= osdGet3DSpeed();
64 case OSD_SPEED_SOURCE_AIR
:
66 speed
= (int16_t)getAirspeedEstimate();
73 #endif // defined(USE_OSD) || defined(USE_DJI_HD_OSD)
77 #define CANVAS_DEFAULT_GRID_ELEMENT_WIDTH OSD_CHAR_WIDTH
78 #define CANVAS_DEFAULT_GRID_ELEMENT_HEIGHT OSD_CHAR_HEIGHT
80 void osdDrawPointGetGrid(uint8_t *gx
, uint8_t *gy
, const displayPort_t
*display
, const displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
)
85 case OSD_DRAW_POINT_TYPE_GRID
:
89 case OSD_DRAW_POINT_TYPE_PIXEL
:
90 *gx
= p
->pixel
.px
/ (canvas
? canvas
->gridElementWidth
: CANVAS_DEFAULT_GRID_ELEMENT_WIDTH
);
91 *gy
= p
->pixel
.py
/ (canvas
? canvas
->gridElementHeight
: OSD_CHAR_HEIGHT
);
96 void osdDrawPointGetPixels(int *px
, int *py
, const displayPort_t
*display
, const displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
)
101 case OSD_DRAW_POINT_TYPE_GRID
:
102 *px
= p
->grid
.gx
* (canvas
? canvas
->gridElementWidth
: CANVAS_DEFAULT_GRID_ELEMENT_WIDTH
);
103 *py
= p
->grid
.gy
* (canvas
? canvas
->gridElementHeight
: CANVAS_DEFAULT_GRID_ELEMENT_HEIGHT
);
105 case OSD_DRAW_POINT_TYPE_PIXEL
:
112 void osdDrawVario(displayPort_t
*display
, displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
, float zvel
)
117 #if defined(USE_CANVAS)
119 osdCanvasDrawVario(display
, canvas
, p
, zvel
);
122 osdDrawPointGetGrid(&gx
, &gy
, display
, canvas
, p
);
123 osdGridDrawVario(display
, gx
, gy
, zvel
);
124 #if defined(USE_CANVAS)
129 void osdDrawDirArrow(displayPort_t
*display
, displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
, float degrees
)
134 #if defined(USE_CANVAS)
136 osdCanvasDrawDirArrow(display
, canvas
, p
, degrees
);
139 osdDrawPointGetGrid(&gx
, &gy
, display
, canvas
, p
);
140 osdGridDrawDirArrow(display
, gx
, gy
, degrees
);
141 #if defined(USE_CANVAS)
146 void osdDrawArtificialHorizon(displayPort_t
*display
, displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
, float rollAngle
, float pitchAngle
)
151 #if defined(USE_CANVAS)
153 osdCanvasDrawArtificialHorizon(display
, canvas
, p
, pitchAngle
, rollAngle
);
156 // Correct pitch when inverted
157 if (rollAngle
< -1.570796f
|| rollAngle
> 1.570796f
) {
158 pitchAngle
= -pitchAngle
;
161 osdDrawPointGetGrid(&gx
, &gy
, display
, canvas
, p
);
162 osdGridDrawArtificialHorizon(display
, gx
, gy
, pitchAngle
, rollAngle
);
163 #if defined(USE_CANVAS)
168 void osdDrawHeadingGraph(displayPort_t
*display
, displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
, int heading
)
172 #if defined(USE_CANVAS)
174 osdCanvasDrawHeadingGraph(display
, canvas
, p
, heading
);
177 osdDrawPointGetGrid(&gx
, &gy
, display
, canvas
, p
);
178 osdGridDrawHeadingGraph(display
, gx
, gy
, heading
);
179 #if defined(USE_CANVAS)
184 void osdDrawSidebars(displayPort_t
*display
, displayCanvas_t
*canvas
)
186 #if defined(USE_CANVAS)
187 if (osdCanvasDrawSidebars(display
, canvas
)) {
193 osdGridDrawSidebars(display
);
199 int16_t osdGet3DSpeed(void)
201 int16_t vert_speed
= getEstimatedActualVelocity(Z
);
202 int16_t hor_speed
= gpsSol
.groundSpeed
;
203 return (int16_t)calc_length_pythagorean_2D(hor_speed
, vert_speed
);