PixelOSD: add setting to chose source for sidebar displayed speed (#6944)
[inav.git] / src / main / io / osd.h
blobcd0f5ee68afcbf6ab70b713cc22d258d82fe46d5
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_NO_PREARM "NO PREARM"
80 #define OSD_MSG_DSHOT_BEEPER "MOTOR BEEPER ACTIVE"
81 #define OSD_MSG_RTH_FS "(RTH)"
82 #define OSD_MSG_EMERG_LANDING_FS "(EMERGENCY LANDING)"
83 #define OSD_MSG_MOVE_EXIT_FS "!MOVE STICKS TO EXIT FS!"
84 #define OSD_MSG_STARTING_RTH "STARTING RTH"
85 #define OSD_MSG_RTH_CLIMB "ADJUSTING RTH ALTITUDE"
86 #define OSD_MSG_HEADING_HOME "EN ROUTE TO HOME"
87 #define OSD_MSG_HOLDING_WAYPOINT "HOLDING WAYPOINT"
88 #define OSD_MSG_TO_WP "TO WP"
89 #define OSD_MSG_PREPARE_NEXT_WP "PREPARING FOR NEXT WAYPOINT"
90 #define OSD_MSG_WP_RTH_CANCEL "CANCEL WP MODE TO EXIT RTH"
91 #define OSD_MSG_EMERG_LANDING "EMERGENCY LANDING"
92 #define OSD_MSG_LANDING "LANDING"
93 #define OSD_MSG_LOITERING_HOME "LOITERING AROUND HOME"
94 #define OSD_MSG_HOVERING "HOVERING"
95 #define OSD_MSG_LANDED "LANDED"
96 #define OSD_MSG_PREPARING_LAND "PREPARING TO LAND"
97 #define OSD_MSG_AUTOLAUNCH "AUTOLAUNCH"
98 #define OSD_MSG_ALTITUDE_HOLD "(ALTITUDE HOLD)"
99 #define OSD_MSG_AUTOTRIM "(AUTOTRIM)"
100 #define OSD_MSG_AUTOTUNE "(AUTOTUNE)"
101 #define OSD_MSG_HEADFREE "(HEADFREE)"
102 #define OSD_MSG_UNABLE_ARM "UNABLE TO ARM"
104 #if defined(USE_SAFE_HOME)
105 #define OSD_MSG_DIVERT_SAFEHOME "DIVERTING TO SAFEHOME"
106 #define OSD_MSG_LOITERING_SAFEHOME "LOITERING AROUND SAFEHOME"
107 #endif
109 typedef enum {
110 OSD_RSSI_VALUE,
111 OSD_MAIN_BATT_VOLTAGE,
112 OSD_CROSSHAIRS,
113 OSD_ARTIFICIAL_HORIZON,
114 OSD_HORIZON_SIDEBARS,
115 OSD_ONTIME,
116 OSD_FLYTIME,
117 OSD_FLYMODE,
118 OSD_CRAFT_NAME,
119 OSD_THROTTLE_POS,
120 OSD_VTX_CHANNEL,
121 OSD_CURRENT_DRAW,
122 OSD_MAH_DRAWN,
123 OSD_GPS_SPEED,
124 OSD_GPS_SATS,
125 OSD_ALTITUDE,
126 OSD_ROLL_PIDS,
127 OSD_PITCH_PIDS,
128 OSD_YAW_PIDS,
129 OSD_POWER,
130 OSD_GPS_LON,
131 OSD_GPS_LAT,
132 OSD_HOME_DIR,
133 OSD_HOME_DIST,
134 OSD_HEADING,
135 OSD_VARIO,
136 OSD_VARIO_NUM,
137 OSD_AIR_SPEED,
138 OSD_ONTIME_FLYTIME,
139 OSD_RTC_TIME,
140 OSD_MESSAGES,
141 OSD_GPS_HDOP,
142 OSD_MAIN_BATT_CELL_VOLTAGE,
143 OSD_THROTTLE_POS_AUTO_THR,
144 OSD_HEADING_GRAPH,
145 OSD_EFFICIENCY_MAH_PER_KM,
146 OSD_WH_DRAWN,
147 OSD_BATTERY_REMAINING_CAPACITY,
148 OSD_BATTERY_REMAINING_PERCENT,
149 OSD_EFFICIENCY_WH_PER_KM,
150 OSD_TRIP_DIST,
151 OSD_ATTITUDE_PITCH,
152 OSD_ATTITUDE_ROLL,
153 OSD_MAP_NORTH,
154 OSD_MAP_TAKEOFF,
155 OSD_RADAR,
156 OSD_WIND_SPEED_HORIZONTAL,
157 OSD_WIND_SPEED_VERTICAL,
158 OSD_REMAINING_FLIGHT_TIME_BEFORE_RTH,
159 OSD_REMAINING_DISTANCE_BEFORE_RTH,
160 OSD_HOME_HEADING_ERROR,
161 OSD_COURSE_HOLD_ERROR,
162 OSD_COURSE_HOLD_ADJUSTMENT,
163 OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE,
164 OSD_MAIN_BATT_SAG_COMPENSATED_CELL_VOLTAGE,
165 OSD_POWER_SUPPLY_IMPEDANCE,
166 OSD_LEVEL_PIDS,
167 OSD_POS_XY_PIDS,
168 OSD_POS_Z_PIDS,
169 OSD_VEL_XY_PIDS,
170 OSD_VEL_Z_PIDS,
171 OSD_HEADING_P,
172 OSD_BOARD_ALIGN_ROLL,
173 OSD_BOARD_ALIGN_PITCH,
174 OSD_RC_EXPO,
175 OSD_RC_YAW_EXPO,
176 OSD_THROTTLE_EXPO,
177 OSD_PITCH_RATE,
178 OSD_ROLL_RATE,
179 OSD_YAW_RATE,
180 OSD_MANUAL_RC_EXPO,
181 OSD_MANUAL_RC_YAW_EXPO,
182 OSD_MANUAL_PITCH_RATE,
183 OSD_MANUAL_ROLL_RATE,
184 OSD_MANUAL_YAW_RATE,
185 OSD_NAV_FW_CRUISE_THR,
186 OSD_NAV_FW_PITCH2THR,
187 OSD_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE,
188 OSD_DEBUG, // Intentionally absent from configurator and CMS. Set it from CLI.
189 OSD_FW_ALT_PID_OUTPUTS,
190 OSD_FW_POS_PID_OUTPUTS,
191 OSD_MC_VEL_X_PID_OUTPUTS,
192 OSD_MC_VEL_Y_PID_OUTPUTS,
193 OSD_MC_VEL_Z_PID_OUTPUTS,
194 OSD_MC_POS_XYZ_P_OUTPUTS,
195 OSD_3D_SPEED,
196 OSD_IMU_TEMPERATURE,
197 OSD_BARO_TEMPERATURE,
198 OSD_TEMP_SENSOR_0_TEMPERATURE,
199 OSD_TEMP_SENSOR_1_TEMPERATURE,
200 OSD_TEMP_SENSOR_2_TEMPERATURE,
201 OSD_TEMP_SENSOR_3_TEMPERATURE,
202 OSD_TEMP_SENSOR_4_TEMPERATURE,
203 OSD_TEMP_SENSOR_5_TEMPERATURE,
204 OSD_TEMP_SENSOR_6_TEMPERATURE,
205 OSD_TEMP_SENSOR_7_TEMPERATURE,
206 OSD_ALTITUDE_MSL,
207 OSD_PLUS_CODE,
208 OSD_MAP_SCALE,
209 OSD_MAP_REFERENCE,
210 OSD_GFORCE,
211 OSD_GFORCE_X,
212 OSD_GFORCE_Y,
213 OSD_GFORCE_Z,
214 OSD_RC_SOURCE,
215 OSD_VTX_POWER,
216 OSD_ESC_RPM,
217 OSD_ESC_TEMPERATURE,
218 OSD_AZIMUTH,
219 OSD_CRSF_RSSI_DBM,
220 OSD_CRSF_LQ,
221 OSD_CRSF_SNR_DB,
222 OSD_CRSF_TX_POWER,
223 OSD_GVAR_0,
224 OSD_GVAR_1,
225 OSD_GVAR_2,
226 OSD_GVAR_3,
227 OSD_TPA,
228 OSD_NAV_FW_CONTROL_SMOOTHNESS,
229 OSD_VERSION,
230 OSD_RANGEFINDER,
231 OSD_PLIMIT_REMAINING_BURST_TIME,
232 OSD_PLIMIT_ACTIVE_CURRENT_LIMIT,
233 OSD_PLIMIT_ACTIVE_POWER_LIMIT,
234 OSD_ITEM_COUNT // MUST BE LAST
235 } osd_items_e;
237 typedef enum {
238 OSD_UNIT_IMPERIAL,
239 OSD_UNIT_METRIC,
240 OSD_UNIT_UK, // Show speed in mp/h, other values in metric
242 OSD_UNIT_MAX = OSD_UNIT_UK,
243 } osd_unit_e;
245 typedef enum {
246 OSD_STATS_ENERGY_UNIT_MAH,
247 OSD_STATS_ENERGY_UNIT_WH,
248 } osd_stats_energy_unit_e;
250 typedef enum {
251 OSD_STATS_MIN_VOLTAGE_UNIT_BATTERY,
252 OSD_STATS_MIN_VOLTAGE_UNIT_CELL,
253 } osd_stats_min_voltage_unit_e;
255 typedef enum {
256 OSD_CROSSHAIRS_STYLE_DEFAULT,
257 OSD_CROSSHAIRS_STYLE_AIRCRAFT,
258 OSD_CROSSHAIRS_STYLE_TYPE3,
259 OSD_CROSSHAIRS_STYLE_TYPE4,
260 OSD_CROSSHAIRS_STYLE_TYPE5,
261 OSD_CROSSHAIRS_STYLE_TYPE6,
262 OSD_CROSSHAIRS_STYLE_TYPE7,
263 } osd_crosshairs_style_e;
265 typedef enum {
266 OSD_SIDEBAR_SCROLL_NONE,
267 OSD_SIDEBAR_SCROLL_ALTITUDE,
268 OSD_SIDEBAR_SCROLL_SPEED,
269 OSD_SIDEBAR_SCROLL_HOME_DISTANCE,
271 OSD_SIDEBAR_SCROLL_MAX = OSD_SIDEBAR_SCROLL_HOME_DISTANCE,
272 } osd_sidebar_scroll_e;
274 typedef enum {
275 OSD_ALIGN_LEFT,
276 OSD_ALIGN_RIGHT
277 } osd_alignment_e;
279 typedef enum {
280 OSD_AHI_STYLE_DEFAULT,
281 OSD_AHI_STYLE_LINE,
282 } osd_ahi_style_e;
284 typedef enum {
285 OSD_CRSF_LQ_TYPE1,
286 OSD_CRSF_LQ_TYPE2,
287 } osd_crsf_lq_format_e;
289 typedef struct osdLayoutsConfig_s {
290 // Layouts
291 uint16_t item_pos[OSD_LAYOUT_COUNT][OSD_ITEM_COUNT];
292 } osdLayoutsConfig_t;
294 PG_DECLARE(osdLayoutsConfig_t, osdLayoutsConfig);
296 typedef struct osdConfig_s {
297 // Alarms
298 uint8_t rssi_alarm; // rssi %
299 uint16_t time_alarm; // fly minutes
300 uint16_t alt_alarm; // positive altitude in m
301 uint16_t dist_alarm; // home distance in m
302 uint16_t neg_alt_alarm; // abs(negative altitude) in m
303 uint8_t current_alarm; // current consumption in A
304 int16_t imu_temp_alarm_min;
305 int16_t imu_temp_alarm_max;
306 int16_t esc_temp_alarm_min;
307 int16_t esc_temp_alarm_max;
308 float gforce_alarm;
309 float gforce_axis_alarm_min;
310 float gforce_axis_alarm_max;
311 #ifdef USE_SERIALRX_CRSF
312 int8_t snr_alarm; //CRSF SNR alarm in dB
313 int8_t link_quality_alarm;
314 #endif
315 #ifdef USE_BARO
316 int16_t baro_temp_alarm_min;
317 int16_t baro_temp_alarm_max;
318 #endif
319 #ifdef USE_TEMPERATURE_SENSOR
320 osd_alignment_e temp_label_align;
321 #endif
323 videoSystem_e video_system;
324 uint8_t row_shiftdown;
326 // Preferences
327 uint8_t main_voltage_decimals;
328 uint8_t ahi_reverse_roll;
329 uint8_t ahi_max_pitch;
330 uint8_t crosshairs_style; // from osd_crosshairs_style_e
331 int8_t horizon_offset;
332 int8_t camera_uptilt;
333 uint8_t camera_fov_h;
334 uint8_t camera_fov_v;
335 uint8_t hud_margin_h;
336 uint8_t hud_margin_v;
337 bool hud_homing;
338 bool hud_homepoint;
339 uint8_t hud_radar_disp;
340 uint16_t hud_radar_range_min;
341 uint16_t hud_radar_range_max;
342 uint16_t hud_radar_nearest;
343 uint8_t hud_wp_disp;
345 uint8_t left_sidebar_scroll; // from osd_sidebar_scroll_e
346 uint8_t right_sidebar_scroll; // from osd_sidebar_scroll_e
347 uint8_t sidebar_scroll_arrows;
349 uint8_t units; // from osd_unit_e
350 uint8_t stats_energy_unit; // from osd_stats_energy_unit_e
351 uint8_t stats_min_voltage_unit; // from osd_stats_min_voltage_unit_e
353 #ifdef USE_WIND_ESTIMATOR
354 bool estimations_wind_compensation; // use wind compensation for estimated remaining flight/distance
355 #endif
357 uint8_t coordinate_digits;
359 bool osd_failsafe_switch_layout;
360 uint8_t plus_code_digits; // Number of digits to use in OSD_PLUS_CODE
361 uint8_t plus_code_short;
362 uint8_t ahi_style;
363 uint8_t force_grid; // Force a pixel based OSD to use grid mode.
364 uint8_t ahi_bordered; // Only used by the AHI widget
365 uint8_t ahi_width; // In pixels, only used by the AHI widget
366 uint8_t ahi_height; // In pixels, only used by the AHI widget
367 int8_t ahi_vertical_offset; // Offset from center in pixels. Positive moves the AHI down. Widget only.
368 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.
369 uint8_t left_sidebar_scroll_step; // How many units each sidebar step represents. 0 means the default value for the scroll type.
370 uint8_t right_sidebar_scroll_step; // Same as left_sidebar_scroll_step, but for the right sidebar.
371 bool osd_home_position_arm_screen;
372 uint8_t pan_servo_index; // Index of the pan servo used for home direction offset
373 int8_t pan_servo_pwm2centideg; // Centidegrees of servo rotation per us pwm
374 uint8_t crsf_lq_format;
375 uint8_t sidebar_height; // sidebar height in rows, 0 turns off sidebars leaving only level indicator arrows
376 uint8_t telemetry; // use telemetry on displayed pixel line 0
378 } osdConfig_t;
380 PG_DECLARE(osdConfig_t, osdConfig);
382 typedef struct displayPort_s displayPort_t;
383 typedef struct displayCanvas_s displayCanvas_t;
385 void osdInit(displayPort_t *osdDisplayPort);
386 bool osdDisplayIsPAL(void);
387 void osdUpdate(timeUs_t currentTimeUs);
388 void osdStartFullRedraw(void);
389 // Sets a fixed OSD layout ignoring the RC input. Set it
390 // to -1 to disable the override. If layout is >= 0 and
391 // duration is > 0, the override is automatically cleared by
392 // the OSD after the given duration. Otherwise, the caller must
393 // explicitely remove it.
394 void osdOverrideLayout(int layout, timeMs_t duration);
395 // Returns the current current layout as well as wether its
396 // set by the user configuration (modes, etc..) or by overriding it.
397 int osdGetActiveLayout(bool *overridden);
398 bool osdItemIsFixed(osd_items_e item);
400 displayPort_t *osdGetDisplayPort(void);
401 displayCanvas_t *osdGetDisplayPortCanvas(void);
403 int16_t osdGetHeading(void);
404 int32_t osdGetAltitude(void);
406 void osdCrosshairPosition(uint8_t *x, uint8_t *y);
407 bool osdFormatCentiNumber(char *buff, int32_t centivalue, uint32_t scale, int maxDecimals, int maxScaledDecimals, int length);
408 void osdFormatAltitudeSymbol(char *buff, int32_t alt);
409 void osdFormatVelocityStr(char* buff, int32_t vel, bool _3D);
410 // Returns a heading angle in degrees normalized to [0, 360).
411 int osdGetHeadingAngle(int angle);
414 * @brief Get the OSD system message
415 * @param buff pointer to the message buffer
416 * @param buff_size size of the buffer array
417 * @param isCenteredText if true, centered text based on buff_size
418 * @return osd text attributes (Blink, Inverted, Solid)
420 textAttributes_t osdGetSystemMessage(char *buff, size_t buff_size, bool isCenteredText);