Merge pull request #6242 from Scavanger/TPA-Adjusment-V2
[inav.git] / src / main / io / osd.h
blobbd912a1b4ff34b1ffa4bf3cf6ee67a6ae342a0bf
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include "common/time.h"
22 #include "config/parameter_group.h"
24 #include "drivers/osd.h"
25 #include "drivers/display.h"
27 #ifndef OSD_ALTERNATE_LAYOUT_COUNT
28 #define OSD_ALTERNATE_LAYOUT_COUNT 3
29 #endif
30 #define OSD_LAYOUT_COUNT (OSD_ALTERNATE_LAYOUT_COUNT + 1)
32 #define OSD_VISIBLE_FLAG 0x0800
33 #define OSD_VISIBLE(x) ((x) & OSD_VISIBLE_FLAG)
34 #define OSD_POS(x,y) ((x) | ((y) << 5))
35 #define OSD_X(x) ((x) & 0x001F)
36 #define OSD_Y(x) (((x) >> 5) & 0x001F)
37 #define OSD_POS_MAX 0x3FF
38 #define OSD_POS_MAX_CLI (OSD_POS_MAX | OSD_VISIBLE_FLAG)
40 #define OSD_HOMING_LIM_H1 6
41 #define OSD_HOMING_LIM_H2 16
42 #define OSD_HOMING_LIM_H3 38
43 #define OSD_HOMING_LIM_V1 5
44 #define OSD_HOMING_LIM_V2 10
45 #define OSD_HOMING_LIM_V3 15
47 // Message defines to be use in OSD and/or telemetry exports
48 #define OSD_MSG_RC_RX_LINK_LOST "!RC RX LINK LOST!"
49 #define OSD_MSG_TURN_ARM_SW_OFF "TURN ARM SWITCH OFF"
50 #define OSD_MSG_DISABLED_BY_FS "DISABLED BY FAILSAFE"
51 #define OSD_MSG_AIRCRAFT_UNLEVEL "AIRCRAFT IS NOT LEVEL"
52 #define OSD_MSG_SENSORS_CAL "SENSORS CALIBRATING"
53 #define OSD_MSG_SYS_OVERLOADED "SYSTEM OVERLOADED"
54 #define OSD_MSG_WAITING_GPS_FIX "WAITING FOR GPS FIX"
55 #define OSD_MSG_DISABLE_NAV_FIRST "DISABLE NAVIGATION FIRST"
56 #define OSD_MSG_1ST_WP_TOO_FAR "FIRST WAYPOINT IS TOO FAR"
57 #define OSD_MSG_JUMP_WP_MISCONFIG "JUMP WAYPOINT MISCONFIGURED"
58 #define OSD_MSG_MAG_NOT_CAL "COMPASS NOT CALIBRATED"
59 #define OSD_MSG_ACC_NOT_CAL "ACCELEROMETER NOT CALIBRATED"
60 #define OSD_MSG_DISARM_1ST "DISABLE ARM SWITCH FIRST"
61 #define OSD_MSG_GYRO_FAILURE "GYRO FAILURE"
62 #define OSD_MSG_ACC_FAIL "ACCELEROMETER FAILURE"
63 #define OSD_MSG_MAG_FAIL "COMPASS FAILURE"
64 #define OSD_MSG_BARO_FAIL "BAROMETER FAILURE"
65 #define OSD_MSG_GPS_FAIL "GPS FAILURE"
66 #define OSD_MSG_RANGEFINDER_FAIL "RANGE FINDER FAILURE"
67 #define OSD_MSG_PITOT_FAIL "PITOT METER FAILURE"
68 #define OSD_MSG_HW_FAIL "HARDWARE FAILURE"
69 #define OSD_MSG_FS_EN "FAILSAFE MODE ENABLED"
70 #define OSD_MSG_KILL_SW_EN "KILLSWITCH MODE ENABLED"
71 #define OSD_MSG_NO_RC_LINK "NO RC LINK"
72 #define OSD_MSG_THROTTLE_NOT_LOW "THROTTLE IS NOT LOW"
73 #define OSD_MSG_ROLLPITCH_OFFCENTER "ROLLPITCH NOT CENTERED"
74 #define OSD_MSG_AUTOTRIM_ACTIVE "AUTOTRIM IS ACTIVE"
75 #define OSD_MSG_NOT_ENOUGH_MEMORY "NOT ENOUGH MEMORY"
76 #define OSD_MSG_INVALID_SETTING "INVALID SETTING"
77 #define OSD_MSG_CLI_ACTIVE "CLI IS ACTIVE"
78 #define OSD_MSG_PWM_INIT_ERROR "PWM INIT ERROR"
79 #define OSD_MSG_RTH_FS "(RTH)"
80 #define OSD_MSG_EMERG_LANDING_FS "(EMERGENCY LANDING)"
81 #define OSD_MSG_MOVE_EXIT_FS "!MOVE STICKS TO EXIT FS!"
82 #define OSD_MSG_STARTING_RTH "STARTING RTH"
83 #define OSD_MSG_HEADING_HOME "EN ROUTE TO HOME"
84 #define OSD_MSG_HOLDING_WAYPOINT "HOLDING WAYPOINT"
85 #define OSD_MSG_TO_WP "TO WP"
86 #define OSD_MSG_PREPARE_NEXT_WP "PREPARING FOR NEXT WAYPOINT"
87 #define OSD_MSG_EMERG_LANDING "EMERGENCY LANDING"
88 #define OSD_MSG_LANDING "LANDING"
89 #define OSD_MSG_LOITERING_HOME "LOITERING AROUND HOME"
90 #define OSD_MSG_HOVERING "HOVERING"
91 #define OSD_MSG_LANDED "LANDED"
92 #define OSD_MSG_PREPARING_LAND "PREPARING TO LAND"
93 #define OSD_MSG_AUTOLAUNCH "AUTOLAUNCH"
94 #define OSD_MSG_ALTITUDE_HOLD "(ALTITUDE HOLD)"
95 #define OSD_MSG_AUTOTRIM "(AUTOTRIM)"
96 #define OSD_MSG_AUTOTUNE "(AUTOTUNE)"
97 #define OSD_MSG_HEADFREE "(HEADFREE)"
98 #define OSD_MSG_UNABLE_ARM "UNABLE TO ARM"
100 typedef enum {
101 OSD_RSSI_VALUE,
102 OSD_MAIN_BATT_VOLTAGE,
103 OSD_CROSSHAIRS,
104 OSD_ARTIFICIAL_HORIZON,
105 OSD_HORIZON_SIDEBARS,
106 OSD_ONTIME,
107 OSD_FLYTIME,
108 OSD_FLYMODE,
109 OSD_CRAFT_NAME,
110 OSD_THROTTLE_POS,
111 OSD_VTX_CHANNEL,
112 OSD_CURRENT_DRAW,
113 OSD_MAH_DRAWN,
114 OSD_GPS_SPEED,
115 OSD_GPS_SATS,
116 OSD_ALTITUDE,
117 OSD_ROLL_PIDS,
118 OSD_PITCH_PIDS,
119 OSD_YAW_PIDS,
120 OSD_POWER,
121 OSD_GPS_LON,
122 OSD_GPS_LAT,
123 OSD_HOME_DIR,
124 OSD_HOME_DIST,
125 OSD_HEADING,
126 OSD_VARIO,
127 OSD_VARIO_NUM,
128 OSD_AIR_SPEED,
129 OSD_ONTIME_FLYTIME,
130 OSD_RTC_TIME,
131 OSD_MESSAGES,
132 OSD_GPS_HDOP,
133 OSD_MAIN_BATT_CELL_VOLTAGE,
134 OSD_THROTTLE_POS_AUTO_THR,
135 OSD_HEADING_GRAPH,
136 OSD_EFFICIENCY_MAH_PER_KM,
137 OSD_WH_DRAWN,
138 OSD_BATTERY_REMAINING_CAPACITY,
139 OSD_BATTERY_REMAINING_PERCENT,
140 OSD_EFFICIENCY_WH_PER_KM,
141 OSD_TRIP_DIST,
142 OSD_ATTITUDE_PITCH,
143 OSD_ATTITUDE_ROLL,
144 OSD_MAP_NORTH,
145 OSD_MAP_TAKEOFF,
146 OSD_RADAR,
147 OSD_WIND_SPEED_HORIZONTAL,
148 OSD_WIND_SPEED_VERTICAL,
149 OSD_REMAINING_FLIGHT_TIME_BEFORE_RTH,
150 OSD_REMAINING_DISTANCE_BEFORE_RTH,
151 OSD_HOME_HEADING_ERROR,
152 OSD_CRUISE_HEADING_ERROR,
153 OSD_CRUISE_HEADING_ADJUSTMENT,
154 OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE,
155 OSD_MAIN_BATT_SAG_COMPENSATED_CELL_VOLTAGE,
156 OSD_POWER_SUPPLY_IMPEDANCE,
157 OSD_LEVEL_PIDS,
158 OSD_POS_XY_PIDS,
159 OSD_POS_Z_PIDS,
160 OSD_VEL_XY_PIDS,
161 OSD_VEL_Z_PIDS,
162 OSD_HEADING_P,
163 OSD_BOARD_ALIGN_ROLL,
164 OSD_BOARD_ALIGN_PITCH,
165 OSD_RC_EXPO,
166 OSD_RC_YAW_EXPO,
167 OSD_THROTTLE_EXPO,
168 OSD_PITCH_RATE,
169 OSD_ROLL_RATE,
170 OSD_YAW_RATE,
171 OSD_MANUAL_RC_EXPO,
172 OSD_MANUAL_RC_YAW_EXPO,
173 OSD_MANUAL_PITCH_RATE,
174 OSD_MANUAL_ROLL_RATE,
175 OSD_MANUAL_YAW_RATE,
176 OSD_NAV_FW_CRUISE_THR,
177 OSD_NAV_FW_PITCH2THR,
178 OSD_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE,
179 OSD_DEBUG, // Intentionally absent from configurator and CMS. Set it from CLI.
180 OSD_FW_ALT_PID_OUTPUTS,
181 OSD_FW_POS_PID_OUTPUTS,
182 OSD_MC_VEL_X_PID_OUTPUTS,
183 OSD_MC_VEL_Y_PID_OUTPUTS,
184 OSD_MC_VEL_Z_PID_OUTPUTS,
185 OSD_MC_POS_XYZ_P_OUTPUTS,
186 OSD_3D_SPEED,
187 OSD_IMU_TEMPERATURE,
188 OSD_BARO_TEMPERATURE,
189 OSD_TEMP_SENSOR_0_TEMPERATURE,
190 OSD_TEMP_SENSOR_1_TEMPERATURE,
191 OSD_TEMP_SENSOR_2_TEMPERATURE,
192 OSD_TEMP_SENSOR_3_TEMPERATURE,
193 OSD_TEMP_SENSOR_4_TEMPERATURE,
194 OSD_TEMP_SENSOR_5_TEMPERATURE,
195 OSD_TEMP_SENSOR_6_TEMPERATURE,
196 OSD_TEMP_SENSOR_7_TEMPERATURE,
197 OSD_ALTITUDE_MSL,
198 OSD_PLUS_CODE,
199 OSD_MAP_SCALE,
200 OSD_MAP_REFERENCE,
201 OSD_GFORCE,
202 OSD_GFORCE_X,
203 OSD_GFORCE_Y,
204 OSD_GFORCE_Z,
205 OSD_RC_SOURCE,
206 OSD_VTX_POWER,
207 OSD_ESC_RPM,
208 OSD_ESC_TEMPERATURE,
209 OSD_AZIMUTH,
210 OSD_CRSF_RSSI_DBM,
211 OSD_CRSF_LQ,
212 OSD_CRSF_SNR_DB,
213 OSD_CRSF_TX_POWER,
214 OSD_GVAR_0,
215 OSD_GVAR_1,
216 OSD_GVAR_2,
217 OSD_GVAR_3,
218 OSD_TPA,
219 OSD_ITEM_COUNT // MUST BE LAST
220 } osd_items_e;
222 typedef enum {
223 OSD_UNIT_IMPERIAL,
224 OSD_UNIT_METRIC,
225 OSD_UNIT_UK, // Show speed in mp/h, other values in metric
227 OSD_UNIT_MAX = OSD_UNIT_UK,
228 } osd_unit_e;
230 typedef enum {
231 OSD_STATS_ENERGY_UNIT_MAH,
232 OSD_STATS_ENERGY_UNIT_WH,
233 } osd_stats_energy_unit_e;
235 typedef enum {
236 OSD_CROSSHAIRS_STYLE_DEFAULT,
237 OSD_CROSSHAIRS_STYLE_AIRCRAFT,
238 OSD_CROSSHAIRS_STYLE_TYPE3,
239 OSD_CROSSHAIRS_STYLE_TYPE4,
240 OSD_CROSSHAIRS_STYLE_TYPE5,
241 OSD_CROSSHAIRS_STYLE_TYPE6,
242 OSD_CROSSHAIRS_STYLE_TYPE7,
243 } osd_crosshairs_style_e;
245 typedef enum {
246 OSD_SIDEBAR_SCROLL_NONE,
247 OSD_SIDEBAR_SCROLL_ALTITUDE,
248 OSD_SIDEBAR_SCROLL_GROUND_SPEED,
249 OSD_SIDEBAR_SCROLL_HOME_DISTANCE,
251 OSD_SIDEBAR_SCROLL_MAX = OSD_SIDEBAR_SCROLL_HOME_DISTANCE,
252 } osd_sidebar_scroll_e;
254 typedef enum {
255 OSD_ALIGN_LEFT,
256 OSD_ALIGN_RIGHT
257 } osd_alignment_e;
259 typedef enum {
260 OSD_AHI_STYLE_DEFAULT,
261 OSD_AHI_STYLE_LINE,
262 } osd_ahi_style_e;
264 typedef enum {
265 OSD_CRSF_LQ_TYPE1,
266 OSD_CRSF_LQ_TYPE2,
267 } osd_crsf_lq_format_e;
269 typedef struct osdLayoutsConfig_s {
270 // Layouts
271 uint16_t item_pos[OSD_LAYOUT_COUNT][OSD_ITEM_COUNT];
272 } osdLayoutsConfig_t;
274 PG_DECLARE(osdLayoutsConfig_t, osdLayoutsConfig);
276 typedef struct osdConfig_s {
277 // Alarms
278 uint8_t rssi_alarm; // rssi %
279 uint16_t time_alarm; // fly minutes
280 uint16_t alt_alarm; // positive altitude in m
281 uint16_t dist_alarm; // home distance in m
282 uint16_t neg_alt_alarm; // abs(negative altitude) in m
283 uint8_t current_alarm; // current consumption in A
284 int16_t imu_temp_alarm_min;
285 int16_t imu_temp_alarm_max;
286 int16_t esc_temp_alarm_min;
287 int16_t esc_temp_alarm_max;
288 float gforce_alarm;
289 float gforce_axis_alarm_min;
290 float gforce_axis_alarm_max;
291 #ifdef USE_SERIALRX_CRSF
292 int16_t snr_alarm; //CRSF SNR alarm in dB
293 int8_t link_quality_alarm;
294 #endif
295 #ifdef USE_BARO
296 int16_t baro_temp_alarm_min;
297 int16_t baro_temp_alarm_max;
298 #endif
299 #ifdef USE_TEMPERATURE_SENSOR
300 osd_alignment_e temp_label_align;
301 #endif
303 videoSystem_e video_system;
304 uint8_t row_shiftdown;
306 // Preferences
307 uint8_t main_voltage_decimals;
308 uint8_t ahi_reverse_roll;
309 uint8_t ahi_max_pitch;
310 uint8_t crosshairs_style; // from osd_crosshairs_style_e
311 int8_t horizon_offset;
312 int8_t camera_uptilt;
313 uint8_t camera_fov_h;
314 uint8_t camera_fov_v;
315 uint8_t hud_margin_h;
316 uint8_t hud_margin_v;
317 bool hud_homing;
318 bool hud_homepoint;
319 uint8_t hud_radar_disp;
320 uint16_t hud_radar_range_min;
321 uint16_t hud_radar_range_max;
322 uint16_t hud_radar_nearest;
323 uint8_t hud_wp_disp;
325 uint8_t left_sidebar_scroll; // from osd_sidebar_scroll_e
326 uint8_t right_sidebar_scroll; // from osd_sidebar_scroll_e
327 uint8_t sidebar_scroll_arrows;
329 uint8_t units; // from osd_unit_e
330 uint8_t stats_energy_unit; // from osd_stats_energy_unit_e
332 bool estimations_wind_compensation; // use wind compensation for estimated remaining flight/distance
333 uint8_t coordinate_digits;
335 bool osd_failsafe_switch_layout;
336 uint8_t plus_code_digits; // Number of digits to use in OSD_PLUS_CODE
337 uint8_t osd_ahi_style;
338 uint8_t force_grid; // Force a pixel based OSD to use grid mode.
339 uint8_t ahi_bordered; // Only used by the AHI widget
340 uint8_t ahi_width; // In pixels, only used by the AHI widget
341 uint8_t ahi_height; // In pixels, only used by the AHI widget
342 int8_t ahi_vertical_offset; // Offset from center in pixels. Positive moves the AHI down. Widget only.
343 int8_t sidebar_horizontal_offset; // Horizontal offset from default position. Units are grid slots for grid OSDs, pixels for pixel based OSDs. Positive values move sidebars closer to the edges.
344 uint8_t left_sidebar_scroll_step; // How many units each sidebar step represents. 0 means the default value for the scroll type.
345 uint8_t right_sidebar_scroll_step; // Same as left_sidebar_scroll_step, but for the right sidebar.
347 uint8_t crsf_lq_format;
349 } osdConfig_t;
351 PG_DECLARE(osdConfig_t, osdConfig);
353 typedef struct displayPort_s displayPort_t;
354 typedef struct displayCanvas_s displayCanvas_t;
356 void osdInit(displayPort_t *osdDisplayPort);
357 bool osdDisplayIsPAL(void);
358 void osdUpdate(timeUs_t currentTimeUs);
359 void osdStartFullRedraw(void);
360 // Sets a fixed OSD layout ignoring the RC input. Set it
361 // to -1 to disable the override. If layout is >= 0 and
362 // duration is > 0, the override is automatically cleared by
363 // the OSD after the given duration. Otherwise, the caller must
364 // explicitely remove it.
365 void osdOverrideLayout(int layout, timeMs_t duration);
366 // Returns the current current layout as well as wether its
367 // set by the user configuration (modes, etc..) or by overriding it.
368 int osdGetActiveLayout(bool *overridden);
369 bool osdItemIsFixed(osd_items_e item);
371 displayPort_t *osdGetDisplayPort(void);
372 displayCanvas_t *osdGetDisplayPortCanvas(void);
374 int16_t osdGetHeading(void);
375 int32_t osdGetAltitude(void);
377 void osdCrosshairPosition(uint8_t *x, uint8_t *y);
378 bool osdFormatCentiNumber(char *buff, int32_t centivalue, uint32_t scale, int maxDecimals, int maxScaledDecimals, int length);
379 void osdFormatAltitudeSymbol(char *buff, int32_t alt);
380 void osdFormatVelocityStr(char* buff, int32_t vel, bool _3D);
381 // Returns a heading angle in degrees normalized to [0, 360).
382 int osdGetHeadingAngle(int angle);
385 * @brief Get the OSD system message
386 * @param buff pointer to the message buffer
387 * @param buff_size size of the buffer array
388 * @param isCenteredText if true, centered text based on buff_size
389 * @return osd text attributes (Blink, Inverted, Solid)
391 textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenteredText);