Support for Flash Memory W25N01G of 128MB (#8166)
[inav.git] / src / main / io / osd_common.c
blob9daa1dd7489331acdd42f2a413f97d68e865b0c9
1 /*
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>
27 #include "platform.h"
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) {
57 int speed = 0;
58 switch (osdCommonConfig()->speedSource) {
59 case OSD_SPEED_SOURCE_GROUND:
60 speed = gpsSol.groundSpeed;
61 break;
62 case OSD_SPEED_SOURCE_3D:
63 speed = osdGet3DSpeed();
64 break;
65 case OSD_SPEED_SOURCE_AIR:
66 #ifdef USE_PITOT
67 speed = pitot.airSpeed;
68 #endif
69 break;
71 return speed;
74 #endif // defined(USE_OSD) || defined(USE_DJI_HD_OSD)
76 #if defined(USE_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)
83 UNUSED(display);
85 switch (p->type) {
86 case OSD_DRAW_POINT_TYPE_GRID:
87 *gx = p->grid.gx;
88 *gy = p->grid.gy;
89 break;
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);
93 break;
97 void osdDrawPointGetPixels(int *px, int *py, const displayPort_t *display, const displayCanvas_t *canvas, const osdDrawPoint_t *p)
99 UNUSED(display);
101 switch (p->type) {
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);
105 break;
106 case OSD_DRAW_POINT_TYPE_PIXEL:
107 *px = p->pixel.px;
108 *py = p->pixel.py;
109 break;
113 void osdDrawVario(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float zvel)
115 uint8_t gx;
116 uint8_t gy;
118 #if defined(USE_CANVAS)
119 if (canvas) {
120 osdCanvasDrawVario(display, canvas, p, zvel);
121 } else {
122 #endif
123 osdDrawPointGetGrid(&gx, &gy, display, canvas, p);
124 osdGridDrawVario(display, gx, gy, zvel);
125 #if defined(USE_CANVAS)
127 #endif
130 void osdDrawDirArrow(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float degrees)
132 uint8_t gx;
133 uint8_t gy;
135 #if defined(USE_CANVAS)
136 if (canvas) {
137 osdCanvasDrawDirArrow(display, canvas, p, degrees);
138 } else {
139 #endif
140 osdDrawPointGetGrid(&gx, &gy, display, canvas, p);
141 osdGridDrawDirArrow(display, gx, gy, degrees);
142 #if defined(USE_CANVAS)
144 #endif
147 void osdDrawArtificialHorizon(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, float rollAngle, float pitchAngle)
149 uint8_t gx;
150 uint8_t gy;
151 #if defined(USE_CANVAS)
152 if (canvas) {
153 osdCanvasDrawArtificialHorizon(display, canvas, p, pitchAngle, rollAngle);
154 } else {
155 #endif
156 osdDrawPointGetGrid(&gx, &gy, display, canvas, p);
157 osdGridDrawArtificialHorizon(display, gx, gy, pitchAngle, rollAngle);
158 #if defined(USE_CANVAS)
160 #endif
163 void osdDrawHeadingGraph(displayPort_t *display, displayCanvas_t *canvas, const osdDrawPoint_t *p, int heading)
165 uint8_t gx;
166 uint8_t gy;
167 #if defined(USE_CANVAS)
168 if (canvas) {
169 osdCanvasDrawHeadingGraph(display, canvas, p, heading);
170 } else {
171 #endif
172 osdDrawPointGetGrid(&gx, &gy, display, canvas, p);
173 osdGridDrawHeadingGraph(display, gx, gy, heading);
174 #if defined(USE_CANVAS)
176 #endif
179 void osdDrawSidebars(displayPort_t *display, displayCanvas_t *canvas)
181 #if defined(USE_CANVAS)
182 if (osdCanvasDrawSidebars(display, canvas)) {
183 return;
185 #else
186 UNUSED(canvas);
187 #endif
188 osdGridDrawSidebars(display);
191 #endif
193 #ifdef USE_GPS
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);
200 #endif