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/>.
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
30 #define OSD_LAYOUT_COUNT (OSD_ALTERNATE_LAYOUT_COUNT + 1)
32 // 00vb yyyy yyxx xxxx
33 // (visible)(blink)(yCoord)(xCoord)
35 #define OSD_VISIBLE_FLAG 0x2000
36 #define OSD_VISIBLE(x) ((x) & OSD_VISIBLE_FLAG)
38 #define OSD_POS(x,y) (((x) & 0x3F) | (((y) & 0x3F) << 6))
39 #define OSD_X(x) ((x) & 0x3F)
40 #define OSD_Y(x) (((x) >> 6) & 0x3F)
41 #define OSD_POS_MAX 0xFFF
43 // For DJI compatibility
44 #define OSD_VISIBLE_FLAG_SD 0x0800
45 #define OSD_POS_SD(x,y) (((x) & 0x1F) | (((y) & 0x1F) << 5))
47 #define OSD_POS_MAX_CLI (OSD_POS_MAX | OSD_VISIBLE_FLAG)
49 #define OSD_HOMING_LIM_H1 6
50 #define OSD_HOMING_LIM_H2 16
51 #define OSD_HOMING_LIM_H3 38
52 #define OSD_HOMING_LIM_V1 5
53 #define OSD_HOMING_LIM_V2 10
54 #define OSD_HOMING_LIM_V3 15
56 // Message defines to be use in OSD and/or telemetry exports
57 #define OSD_MSG_RC_RX_LINK_LOST "!RC RX LINK LOST!"
58 #define OSD_MSG_TURN_ARM_SW_OFF "TURN ARM SWITCH OFF"
59 #define OSD_MSG_DISABLED_BY_FS "DISABLED BY FAILSAFE"
60 #define OSD_MSG_AIRCRAFT_UNLEVEL "AIRCRAFT IS NOT LEVEL"
61 #define OSD_MSG_SENSORS_CAL "SENSORS CALIBRATING"
62 #define OSD_MSG_SYS_OVERLOADED "SYSTEM OVERLOADED"
63 #define OSD_MSG_WAITING_GPS_FIX "WAITING FOR GPS FIX"
64 #define OSD_MSG_DISABLE_NAV_FIRST "DISABLE NAVIGATION FIRST"
65 #define OSD_MSG_JUMP_WP_MISCONFIG "JUMP WAYPOINT MISCONFIGURED"
66 #define OSD_MSG_MAG_NOT_CAL "COMPASS NOT CALIBRATED"
67 #define OSD_MSG_ACC_NOT_CAL "ACCELEROMETER NOT CALIBRATED"
68 #define OSD_MSG_DISARM_1ST "DISABLE ARM SWITCH FIRST"
69 #define OSD_MSG_GYRO_FAILURE "GYRO FAILURE"
70 #define OSD_MSG_ACC_FAIL "ACCELEROMETER FAILURE"
71 #define OSD_MSG_MAG_FAIL "COMPASS FAILURE"
72 #define OSD_MSG_BARO_FAIL "BAROMETER FAILURE"
73 #define OSD_MSG_GPS_FAIL "GPS FAILURE"
74 #define OSD_MSG_RANGEFINDER_FAIL "RANGE FINDER FAILURE"
75 #define OSD_MSG_PITOT_FAIL "PITOT METER FAILURE"
76 #define OSD_MSG_HW_FAIL "HARDWARE FAILURE"
77 #define OSD_MSG_FS_EN "FAILSAFE MODE ENABLED"
78 #define OSD_MSG_NO_RC_LINK "NO RC LINK"
79 #define OSD_MSG_THROTTLE_NOT_LOW "THROTTLE IS NOT LOW"
80 #define OSD_MSG_ROLLPITCH_OFFCENTER "ROLLPITCH NOT CENTERED"
81 #define OSD_MSG_AUTOTRIM_ACTIVE "AUTOTRIM IS ACTIVE"
82 #define OSD_MSG_NOT_ENOUGH_MEMORY "NOT ENOUGH MEMORY"
83 #define OSD_MSG_INVALID_SETTING "INVALID SETTING"
84 #define OSD_MSG_CLI_ACTIVE "CLI IS ACTIVE"
85 #define OSD_MSG_PWM_INIT_ERROR "PWM INIT ERROR"
86 #define OSD_MSG_NO_PREARM "NO PREARM"
87 #define OSD_MSG_DSHOT_BEEPER "MOTOR BEEPER ACTIVE"
88 #define OSD_MSG_RTH_FS "(RTH)"
89 #define OSD_MSG_EMERG_LANDING_FS "(EMERGENCY LANDING)"
90 #define OSD_MSG_MOVE_EXIT_FS "!MOVE STICKS TO EXIT FS!"
91 #define OSD_MSG_STARTING_RTH "STARTING RTH"
92 #define OSD_MSG_RTH_CLIMB "ADJUSTING RTH ALTITUDE"
93 #define OSD_MSG_RTH_TRACKBACK "RTH BACK TRACKING"
94 #define OSD_MSG_HEADING_HOME "EN ROUTE TO HOME"
95 #define OSD_MSG_RTH_LINEAR_DESCENT "BEGIN LINEAR DESCENT"
96 #define OSD_MSG_WP_FINISHED "WP END>HOLDING POSITION"
97 #define OSD_MSG_WP_LANDED "WP END>LANDED"
98 #define OSD_MSG_PREPARE_NEXT_WP "PREPARING FOR NEXT WAYPOINT"
99 #define OSD_MSG_ADJUSTING_WP_ALT "ADJUSTING WP ALTITUDE"
100 #define OSD_MSG_MISSION_PLANNER "(WP MISSION PLANNER)"
101 #define OSD_MSG_WP_RTH_CANCEL "CANCEL WP TO EXIT RTH"
102 #define OSD_MSG_WP_MISSION_LOADED "* MISSION LOADED *"
103 #define OSD_MSG_EMERG_LANDING "EMERGENCY LANDING"
104 #define OSD_MSG_LANDING "LANDING"
105 #define OSD_MSG_LOITERING_HOME "LOITERING AROUND HOME"
106 #define OSD_MSG_HOVERING "HOVERING"
107 #define OSD_MSG_LANDED "LANDED"
108 #define OSD_MSG_PREPARING_LAND "PREPARING TO LAND"
109 #define OSD_MSG_AUTOLAUNCH "AUTOLAUNCH"
110 #define OSD_MSG_AUTOLAUNCH_MANUAL "AUTOLAUNCH (MANUAL)"
111 #define OSD_MSG_ALTITUDE_HOLD "(ALTITUDE HOLD)"
112 #define OSD_MSG_AUTOTRIM "(AUTOTRIM)"
113 #define OSD_MSG_AUTOTUNE "(AUTOTUNE)"
114 #define OSD_MSG_AUTOTUNE_ACRO "SWITCH TO ACRO"
115 #define OSD_MSG_AUTOLEVEL "(AUTO LEVEL TRIM)"
116 #define OSD_MSG_HEADFREE "(HEADFREE)"
117 #define OSD_MSG_NAV_SOARING "(SOARING)"
118 #define OSD_MSG_UNABLE_ARM "UNABLE TO ARM"
119 #define OSD_MSG_SAVING_SETTNGS "** SAVING SETTINGS **"
120 #define OSD_MSG_SETTINGS_SAVED "** SETTINGS SAVED **"
121 #define OSD_MSG_ANGLEHOLD_ROLL "(ANGLEHOLD ROLL)"
122 #define OSD_MSG_ANGLEHOLD_PITCH "(ANGLEHOLD PITCH)"
123 #define OSD_MSG_ANGLEHOLD_LEVEL "(ANGLEHOLD LEVEL)"
124 #define OSD_MSG_MOVE_STICKS "MOVE STICKS TO ABORT"
127 #define OSD_MSG_GRD_TEST_MODE "GRD TEST > MOTORS DISABLED"
130 #if defined(USE_SAFE_HOME)
131 #define OSD_MSG_DIVERT_SAFEHOME "DIVERTING TO SAFEHOME"
132 #define OSD_MSG_LOITERING_SAFEHOME "LOITERING AROUND SAFEHOME"
137 OSD_MAIN_BATT_VOLTAGE
,
139 OSD_ARTIFICIAL_HORIZON
,
140 OSD_HORIZON_SIDEBARS
,
168 OSD_MAIN_BATT_CELL_VOLTAGE
,
169 OSD_SCALED_THROTTLE_POS
,
171 OSD_EFFICIENCY_MAH_PER_KM
,
173 OSD_BATTERY_REMAINING_CAPACITY
,
174 OSD_BATTERY_REMAINING_PERCENT
,
175 OSD_EFFICIENCY_WH_PER_KM
,
182 OSD_WIND_SPEED_HORIZONTAL
,
183 OSD_WIND_SPEED_VERTICAL
,
184 OSD_REMAINING_FLIGHT_TIME_BEFORE_RTH
,
185 OSD_REMAINING_DISTANCE_BEFORE_RTH
,
186 OSD_HOME_HEADING_ERROR
,
187 OSD_COURSE_HOLD_ERROR
,
188 OSD_COURSE_HOLD_ADJUSTMENT
,
189 OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE
,
190 OSD_MAIN_BATT_SAG_COMPENSATED_CELL_VOLTAGE
,
191 OSD_POWER_SUPPLY_IMPEDANCE
,
198 OSD_BOARD_ALIGN_ROLL
,
199 OSD_BOARD_ALIGN_PITCH
,
207 OSD_MANUAL_RC_YAW_EXPO
,
208 OSD_MANUAL_PITCH_RATE
,
209 OSD_MANUAL_ROLL_RATE
,
211 OSD_NAV_FW_CRUISE_THR
,
212 OSD_NAV_FW_PITCH2THR
,
213 OSD_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE
,
214 OSD_DEBUG
, // Intentionally absent from configurator and CMS. Set it from CLI.
215 OSD_FW_ALT_PID_OUTPUTS
,
216 OSD_FW_POS_PID_OUTPUTS
,
217 OSD_MC_VEL_X_PID_OUTPUTS
,
218 OSD_MC_VEL_Y_PID_OUTPUTS
,
219 OSD_MC_VEL_Z_PID_OUTPUTS
,
220 OSD_MC_POS_XYZ_P_OUTPUTS
,
223 OSD_BARO_TEMPERATURE
,
224 OSD_TEMP_SENSOR_0_TEMPERATURE
,
225 OSD_TEMP_SENSOR_1_TEMPERATURE
,
226 OSD_TEMP_SENSOR_2_TEMPERATURE
,
227 OSD_TEMP_SENSOR_3_TEMPERATURE
,
228 OSD_TEMP_SENSOR_4_TEMPERATURE
,
229 OSD_TEMP_SENSOR_5_TEMPERATURE
,
230 OSD_TEMP_SENSOR_6_TEMPERATURE
,
231 OSD_TEMP_SENSOR_7_TEMPERATURE
,
254 OSD_NAV_FW_CONTROL_SMOOTHNESS
,
257 OSD_PLIMIT_REMAINING_BURST_TIME
,
258 OSD_PLIMIT_ACTIVE_CURRENT_LIMIT
,
259 OSD_PLIMIT_ACTIVE_POWER_LIMIT
,
266 OSD_SWITCH_INDICATOR_0
,
267 OSD_SWITCH_INDICATOR_1
,
268 OSD_SWITCH_INDICATOR_2
,
269 OSD_SWITCH_INDICATOR_3
,
270 OSD_TPA_TIME_CONSTANT
,
272 OSD_GLIDE_TIME_REMAINING
,
274 OSD_CLIMB_EFFICIENCY
,
275 OSD_NAV_WP_MULTI_MISSION_INDEX
,
276 OSD_GROUND_COURSE
, // 140
277 OSD_CROSS_TRACK_ERROR
,
279 OSD_PAN_SERVO_CENTRED
,
283 OSD_CUSTOM_ELEMENT_1
,
284 OSD_CUSTOM_ELEMENT_2
,
285 OSD_CUSTOM_ELEMENT_3
,
286 OSD_ADSB_WARNING
, //150
289 OSD_FORMATION_FLIGHT
, //153
290 OSD_ITEM_COUNT
// MUST BE LAST
296 OSD_UNIT_METRIC_MPH
, // Old UK units, all metric except speed in mph
297 OSD_UNIT_UK
, // Show everything in imperial, temperature in C
298 OSD_UNIT_GA
, // General Aviation: Knots, Nautical Miles, Feet, Degrees C
300 OSD_UNIT_MAX
= OSD_UNIT_GA
,
304 OSD_STATS_ENERGY_UNIT_MAH
,
305 OSD_STATS_ENERGY_UNIT_WH
,
306 } osd_stats_energy_unit_e
;
309 OSD_CROSSHAIRS_STYLE_DEFAULT
,
310 OSD_CROSSHAIRS_STYLE_AIRCRAFT
,
311 OSD_CROSSHAIRS_STYLE_TYPE3
,
312 OSD_CROSSHAIRS_STYLE_TYPE4
,
313 OSD_CROSSHAIRS_STYLE_TYPE5
,
314 OSD_CROSSHAIRS_STYLE_TYPE6
,
315 OSD_CROSSHAIRS_STYLE_TYPE7
,
316 } osd_crosshairs_style_e
;
319 OSD_SIDEBAR_SCROLL_NONE
,
320 OSD_SIDEBAR_SCROLL_ALTITUDE
,
321 OSD_SIDEBAR_SCROLL_SPEED
,
322 OSD_SIDEBAR_SCROLL_HOME_DISTANCE
,
324 OSD_SIDEBAR_SCROLL_MAX
= OSD_SIDEBAR_SCROLL_HOME_DISTANCE
,
325 } osd_sidebar_scroll_e
;
333 OSD_AHI_STYLE_DEFAULT
,
341 } osd_crsf_lq_format_e
;
343 typedef struct osdLayoutsConfig_s
{
345 uint16_t item_pos
[OSD_LAYOUT_COUNT
][OSD_ITEM_COUNT
];
346 } osdLayoutsConfig_t
;
348 PG_DECLARE(osdLayoutsConfig_t
, osdLayoutsConfig
);
350 #define OSD_SWITCH_INDICATOR_NAME_LENGTH 4
352 typedef struct osdConfig_s
{
354 uint8_t rssi_alarm
; // rssi %
355 uint16_t time_alarm
; // fly minutes
356 uint16_t alt_alarm
; // positive altitude in m
357 uint16_t dist_alarm
; // home distance in m
358 uint16_t neg_alt_alarm
; // abs(negative altitude) in m
359 uint8_t current_alarm
; // current consumption in A
360 int16_t imu_temp_alarm_min
;
361 int16_t imu_temp_alarm_max
;
362 int16_t esc_temp_alarm_min
;
363 int16_t esc_temp_alarm_max
;
365 float gforce_axis_alarm_min
;
366 float gforce_axis_alarm_max
;
367 #ifdef USE_SERIALRX_CRSF
368 int8_t snr_alarm
; //CRSF SNR alarm in dB
369 int8_t link_quality_alarm
;
370 int16_t rssi_dbm_alarm
; // in dBm
371 int16_t rssi_dbm_max
; // Perfect RSSI. Set to High end of curve. RSSI at 100%
372 int16_t rssi_dbm_min
; // Worst RSSI. Set to low end of curve or RX sensitivity level. RSSI at 0%
375 int16_t baro_temp_alarm_min
;
376 int16_t baro_temp_alarm_max
;
378 #ifdef USE_TEMPERATURE_SENSOR
379 osd_alignment_e temp_label_align
;
382 float airspeed_alarm_min
;
383 float airspeed_alarm_max
;
386 videoSystem_e video_system
;
387 uint8_t row_shiftdown
;
388 int16_t msp_displayport_fullframe_interval
;
391 uint8_t main_voltage_decimals
;
392 uint8_t ahi_reverse_roll
;
393 uint8_t ahi_max_pitch
;
394 uint8_t crosshairs_style
; // from osd_crosshairs_style_e
395 int8_t horizon_offset
;
396 int8_t camera_uptilt
;
397 bool ahi_camera_uptilt_comp
;
398 uint8_t camera_fov_h
;
399 uint8_t camera_fov_v
;
400 uint8_t hud_margin_h
;
401 uint8_t hud_margin_v
;
404 uint8_t hud_radar_disp
;
405 uint16_t hud_radar_range_min
;
406 uint16_t hud_radar_range_max
;
407 uint8_t hud_radar_alt_difference_display_time
;
408 uint8_t hud_radar_distance_display_time
;
411 uint8_t left_sidebar_scroll
; // from osd_sidebar_scroll_e
412 uint8_t right_sidebar_scroll
; // from osd_sidebar_scroll_e
413 uint8_t sidebar_scroll_arrows
;
415 uint8_t units
; // from osd_unit_e
416 uint8_t stats_energy_unit
; // from osd_stats_energy_unit_e
417 uint8_t stats_page_auto_swap_time
; // stats page auto swap interval time (seconds)
418 bool stats_show_metric_efficiency
; // If true, show metric efficiency as well as for the selected units
420 #ifdef USE_WIND_ESTIMATOR
421 bool estimations_wind_compensation
; // use wind compensation for estimated remaining flight/distance
422 bool estimations_wind_mps
; // wind speed estimation in m/s
424 uint8_t coordinate_digits
;
425 bool osd_failsafe_switch_layout
;
426 uint8_t plus_code_digits
; // Number of digits to use in OSD_PLUS_CODE
427 uint8_t plus_code_short
;
429 uint8_t force_grid
; // Force a pixel based OSD to use grid mode.
430 uint8_t ahi_bordered
; // Only used by the AHI widget
431 uint8_t ahi_width
; // In pixels, only used by the AHI widget
432 uint8_t ahi_height
; // In pixels, only used by the AHI widget
433 int8_t ahi_vertical_offset
; // Offset from center in pixels. Positive moves the AHI down. Widget only.
434 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.
435 uint8_t left_sidebar_scroll_step
; // How many units each sidebar step represents. 0 means the default value for the scroll type.
436 uint8_t right_sidebar_scroll_step
; // Same as left_sidebar_scroll_step, but for the right sidebar.
437 bool osd_home_position_arm_screen
;
438 uint8_t pan_servo_index
; // Index of the pan servo used for home direction offset
439 int8_t pan_servo_pwm2centideg
; // Centidegrees of servo rotation per us pwm
440 uint8_t pan_servo_offcentre_warning
; // Degrees around the centre, that is assumed camera is wanted to be facing forwards, but isn't centred
441 bool pan_servo_indicator_show_degrees
; // Show the degrees of offset for the pan servo
442 uint8_t crsf_lq_format
;
443 uint8_t sidebar_height
; // sidebar height in rows, 0 turns off sidebars leaving only level indicator arrows
444 uint8_t telemetry
; // use telemetry on displayed pixel line 0
445 uint8_t esc_rpm_precision
; // Number of characters used for the RPM numbers.
446 uint16_t system_msg_display_time
; // system message display time for multiple messages (ms)
447 uint8_t mAh_precision
; // Number of numbers used for mAh drawn. Plently of packs now are > 9999 mAh
448 uint8_t ahi_pitch_interval
; // redraws AHI at set pitch interval (Not pixel OSD)
449 char osd_switch_indicator0_name
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1]; // Name to use for switch indicator 0.
450 uint8_t osd_switch_indicator0_channel
; // RC Channel to use for switch indicator 0.
451 char osd_switch_indicator1_name
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1]; // Name to use for switch indicator 1.
452 uint8_t osd_switch_indicator1_channel
; // RC Channel to use for switch indicator 1.
453 char osd_switch_indicator2_name
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1]; // Name to use for switch indicator 2.
454 uint8_t osd_switch_indicator2_channel
; // RC Channel to use for switch indicator 2.
455 char osd_switch_indicator3_name
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1]; // Name to use for switch indicator 3.
456 uint8_t osd_switch_indicator3_channel
; // RC Channel to use for switch indicator 3.
457 bool osd_switch_indicators_align_left
; // Align switch indicator name to left of the switch.
458 bool use_pilot_logo
; // If enabled, the pilot logo (last 40 characters of page 2 font) will be used with the INAV logo.
459 uint8_t inav_to_pilot_logo_spacing
; // The space between the INAV and pilot logos, if pilot logo is used. This number may be adjusted so that it fits the odd/even col width.
460 uint16_t arm_screen_display_time
; // Length of time the arm screen is displayed
461 #ifndef DISABLE_MSP_DJI_COMPAT
462 bool highlight_djis_missing_characters
; // If enabled, show question marks where there is no character in DJI's font to represent an OSD element symbol
465 uint16_t adsb_distance_warning
; // in metres
466 uint16_t adsb_distance_alert
; // in metres
467 uint16_t adsb_ignore_plane_above_me_limit
; // in metres
469 uint8_t radar_peers_display_time
; // in seconds
472 PG_DECLARE(osdConfig_t
, osdConfig
);
474 typedef struct displayPort_s displayPort_t
;
475 typedef struct displayCanvas_s displayCanvas_t
;
477 void osdInit(displayPort_t
*osdDisplayPort
);
478 bool osdDisplayIsPAL(void);
479 void osdUpdate(timeUs_t currentTimeUs
);
480 void osdStartFullRedraw(void);
481 // Sets a fixed OSD layout ignoring the RC input. Set it
482 // to -1 to disable the override. If layout is >= 0 and
483 // duration is > 0, the override is automatically cleared by
484 // the OSD after the given duration. Otherwise, the caller must
485 // explicitely remove it.
486 void osdOverrideLayout(int layout
, timeMs_t duration
);
487 // Returns the current current layout as well as wether its
488 // set by the user configuration (modes, etc..) or by overriding it.
489 int osdGetActiveLayout(bool *overridden
);
490 bool osdItemIsFixed(osd_items_e item
);
491 uint8_t osdIncElementIndex(uint8_t elementIndex
);
493 displayPort_t
*osdGetDisplayPort(void);
494 displayCanvas_t
*osdGetDisplayPortCanvas(void);
496 int16_t osdGetHeading(void);
497 int32_t osdGetAltitude(void);
499 bool osdUsingScaledThrottle(void);
501 void osdStartedSaveProcess(void);
502 void osdShowEEPROMSavedNotification(void);
504 void osdCrosshairPosition(uint8_t *x
, uint8_t *y
);
505 bool osdFormatCentiNumber(char *buff
, int32_t centivalue
, uint32_t scale
, int maxDecimals
, int maxScaledDecimals
, int length
, bool leadingZeros
);
506 void osdFormatAltitudeSymbol(char *buff
, int32_t alt
);
507 void osdFormatVelocityStr(char* buff
, int32_t vel
, bool _3D
, bool _max
);
508 // Returns a heading angle in degrees normalized to [0, 360).
509 int osdGetHeadingAngle(int angle
);
511 void osdResetWarningFlags(void);
513 int16_t osdGetPanServoOffset(void);
516 * @brief Get the OSD system message
517 * @param buff pointer to the message buffer
518 * @param buff_size size of the buffer array
519 * @param isCenteredText if true, centered text based on buff_size
520 * @return osd text attributes (Blink, Inverted, Solid)
522 textAttributes_t
osdGetSystemMessage(char *buff
, size_t buff_size
, bool isCenteredText
);