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"
48 #if defined(USE_OSD) || defined(USE_DJI_HD_OSD)
50 PG_REGISTER_WITH_RESET_TEMPLATE(osdCommonConfig_t
, osdCommonConfig
, PG_OSD_COMMON_CONFIG
, 0);
52 PG_RESET_TEMPLATE(osdCommonConfig_t
, osdCommonConfig
,
53 .speedSource
= SETTING_OSD_SPEED_SOURCE_DEFAULT
56 int osdGetSpeedFromSelectedSource(void) {
58 switch (osdCommonConfig()->speedSource
) {
59 case OSD_SPEED_SOURCE_GROUND
:
60 speed
= gpsSol
.groundSpeed
;
62 case OSD_SPEED_SOURCE_3D
:
63 speed
= osdGet3DSpeed();
65 case OSD_SPEED_SOURCE_AIR
:
67 speed
= pitot
.airSpeed
;
74 #endif // defined(USE_OSD) || defined(USE_DJI_HD_OSD)
78 #define CANVAS_DEFAULT_GRID_ELEMENT_WIDTH OSD_CHAR_WIDTH
79 #define CANVAS_DEFAULT_GRID_ELEMENT_HEIGHT OSD_CHAR_HEIGHT
81 void osdDrawPointGetGrid(uint8_t *gx
, uint8_t *gy
, const displayPort_t
*display
, const displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
)
86 case OSD_DRAW_POINT_TYPE_GRID
:
90 case OSD_DRAW_POINT_TYPE_PIXEL
:
91 *gx
= p
->pixel
.px
/ (canvas
? canvas
->gridElementWidth
: CANVAS_DEFAULT_GRID_ELEMENT_WIDTH
);
92 *gy
= p
->pixel
.py
/ (canvas
? canvas
->gridElementHeight
: OSD_CHAR_HEIGHT
);
97 void osdDrawPointGetPixels(int *px
, int *py
, const displayPort_t
*display
, const displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
)
102 case OSD_DRAW_POINT_TYPE_GRID
:
103 *px
= p
->grid
.gx
* (canvas
? canvas
->gridElementWidth
: CANVAS_DEFAULT_GRID_ELEMENT_WIDTH
);
104 *py
= p
->grid
.gy
* (canvas
? canvas
->gridElementHeight
: CANVAS_DEFAULT_GRID_ELEMENT_HEIGHT
);
106 case OSD_DRAW_POINT_TYPE_PIXEL
:
113 void osdDrawVario(displayPort_t
*display
, displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
, float zvel
)
118 #if defined(USE_CANVAS)
120 osdCanvasDrawVario(display
, canvas
, p
, zvel
);
123 osdDrawPointGetGrid(&gx
, &gy
, display
, canvas
, p
);
124 osdGridDrawVario(display
, gx
, gy
, zvel
);
125 #if defined(USE_CANVAS)
130 void osdDrawDirArrow(displayPort_t
*display
, displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
, float degrees
)
135 #if defined(USE_CANVAS)
137 osdCanvasDrawDirArrow(display
, canvas
, p
, degrees
);
140 osdDrawPointGetGrid(&gx
, &gy
, display
, canvas
, p
);
141 osdGridDrawDirArrow(display
, gx
, gy
, degrees
);
142 #if defined(USE_CANVAS)
147 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 osdDrawPointGetGrid(&gx
, &gy
, display
, canvas
, p
);
157 osdGridDrawArtificialHorizon(display
, gx
, gy
, pitchAngle
, rollAngle
);
158 #if defined(USE_CANVAS)
163 void osdDrawHeadingGraph(displayPort_t
*display
, displayCanvas_t
*canvas
, const osdDrawPoint_t
*p
, int heading
)
167 #if defined(USE_CANVAS)
169 osdCanvasDrawHeadingGraph(display
, canvas
, p
, heading
);
172 osdDrawPointGetGrid(&gx
, &gy
, display
, canvas
, p
);
173 osdGridDrawHeadingGraph(display
, gx
, gy
, heading
);
174 #if defined(USE_CANVAS)
179 void osdDrawSidebars(displayPort_t
*display
, displayCanvas_t
*canvas
)
181 #if defined(USE_CANVAS)
182 if (osdCanvasDrawSidebars(display
, canvas
)) {
188 osdGridDrawSidebars(display
);
194 int16_t osdGet3DSpeed(void)
196 int16_t vert_speed
= getEstimatedActualVelocity(Z
);
197 int16_t hor_speed
= gpsSol
.groundSpeed
;
198 return (int16_t)calc_length_pythagorean_2D(hor_speed
, vert_speed
);