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_KILL_SW_EN "KILLSWITCH MODE ENABLED"
79 #define OSD_MSG_NO_RC_LINK "NO RC LINK"
80 #define OSD_MSG_THROTTLE_NOT_LOW "THROTTLE IS NOT LOW"
81 #define OSD_MSG_ROLLPITCH_OFFCENTER "ROLLPITCH NOT CENTERED"
82 #define OSD_MSG_AUTOTRIM_ACTIVE "AUTOTRIM IS ACTIVE"
83 #define OSD_MSG_NOT_ENOUGH_MEMORY "NOT ENOUGH MEMORY"
84 #define OSD_MSG_INVALID_SETTING "INVALID SETTING"
85 #define OSD_MSG_CLI_ACTIVE "CLI IS ACTIVE"
86 #define OSD_MSG_PWM_INIT_ERROR "PWM INIT ERROR"
87 #define OSD_MSG_NO_PREARM "NO PREARM"
88 #define OSD_MSG_DSHOT_BEEPER "MOTOR BEEPER ACTIVE"
89 #define OSD_MSG_RTH_FS "(RTH)"
90 #define OSD_MSG_EMERG_LANDING_FS "(EMERGENCY LANDING)"
91 #define OSD_MSG_MOVE_EXIT_FS "!MOVE STICKS TO EXIT FS!"
92 #define OSD_MSG_STARTING_RTH "STARTING RTH"
93 #define OSD_MSG_RTH_CLIMB "ADJUSTING RTH ALTITUDE"
94 #define OSD_MSG_RTH_TRACKBACK "RTH BACK TRACKING"
95 #define OSD_MSG_HEADING_HOME "EN ROUTE TO HOME"
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_HEADFREE "(HEADFREE)"
116 #define OSD_MSG_NAV_SOARING "(SOARING)"
117 #define OSD_MSG_UNABLE_ARM "UNABLE TO ARM"
118 #define OSD_MSG_SAVING_SETTNGS "** SAVING SETTINGS **"
119 #define OSD_MSG_SETTINGS_SAVED "** SETTINGS SAVED **"
122 #define OSD_MSG_GRD_TEST_MODE "GRD TEST > MOTORS DISABLED"
125 #if defined(USE_SAFE_HOME)
126 #define OSD_MSG_DIVERT_SAFEHOME "DIVERTING TO SAFEHOME"
127 #define OSD_MSG_LOITERING_SAFEHOME "LOITERING AROUND SAFEHOME"
132 OSD_MAIN_BATT_VOLTAGE
,
134 OSD_ARTIFICIAL_HORIZON
,
135 OSD_HORIZON_SIDEBARS
,
163 OSD_MAIN_BATT_CELL_VOLTAGE
,
164 OSD_THROTTLE_POS_AUTO_THR
,
166 OSD_EFFICIENCY_MAH_PER_KM
,
168 OSD_BATTERY_REMAINING_CAPACITY
,
169 OSD_BATTERY_REMAINING_PERCENT
,
170 OSD_EFFICIENCY_WH_PER_KM
,
177 OSD_WIND_SPEED_HORIZONTAL
,
178 OSD_WIND_SPEED_VERTICAL
,
179 OSD_REMAINING_FLIGHT_TIME_BEFORE_RTH
,
180 OSD_REMAINING_DISTANCE_BEFORE_RTH
,
181 OSD_HOME_HEADING_ERROR
,
182 OSD_COURSE_HOLD_ERROR
,
183 OSD_COURSE_HOLD_ADJUSTMENT
,
184 OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE
,
185 OSD_MAIN_BATT_SAG_COMPENSATED_CELL_VOLTAGE
,
186 OSD_POWER_SUPPLY_IMPEDANCE
,
193 OSD_BOARD_ALIGN_ROLL
,
194 OSD_BOARD_ALIGN_PITCH
,
202 OSD_MANUAL_RC_YAW_EXPO
,
203 OSD_MANUAL_PITCH_RATE
,
204 OSD_MANUAL_ROLL_RATE
,
206 OSD_NAV_FW_CRUISE_THR
,
207 OSD_NAV_FW_PITCH2THR
,
208 OSD_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE
,
209 OSD_DEBUG
, // Intentionally absent from configurator and CMS. Set it from CLI.
210 OSD_FW_ALT_PID_OUTPUTS
,
211 OSD_FW_POS_PID_OUTPUTS
,
212 OSD_MC_VEL_X_PID_OUTPUTS
,
213 OSD_MC_VEL_Y_PID_OUTPUTS
,
214 OSD_MC_VEL_Z_PID_OUTPUTS
,
215 OSD_MC_POS_XYZ_P_OUTPUTS
,
218 OSD_BARO_TEMPERATURE
,
219 OSD_TEMP_SENSOR_0_TEMPERATURE
,
220 OSD_TEMP_SENSOR_1_TEMPERATURE
,
221 OSD_TEMP_SENSOR_2_TEMPERATURE
,
222 OSD_TEMP_SENSOR_3_TEMPERATURE
,
223 OSD_TEMP_SENSOR_4_TEMPERATURE
,
224 OSD_TEMP_SENSOR_5_TEMPERATURE
,
225 OSD_TEMP_SENSOR_6_TEMPERATURE
,
226 OSD_TEMP_SENSOR_7_TEMPERATURE
,
249 OSD_NAV_FW_CONTROL_SMOOTHNESS
,
252 OSD_PLIMIT_REMAINING_BURST_TIME
,
253 OSD_PLIMIT_ACTIVE_CURRENT_LIMIT
,
254 OSD_PLIMIT_ACTIVE_POWER_LIMIT
,
261 OSD_SWITCH_INDICATOR_0
,
262 OSD_SWITCH_INDICATOR_1
,
263 OSD_SWITCH_INDICATOR_2
,
264 OSD_SWITCH_INDICATOR_3
,
265 OSD_TPA_TIME_CONSTANT
,
267 OSD_GLIDE_TIME_REMAINING
,
269 OSD_CLIMB_EFFICIENCY
,
270 OSD_NAV_WP_MULTI_MISSION_INDEX
,
271 OSD_GROUND_COURSE
, // 140
272 OSD_CROSS_TRACK_ERROR
,
275 OSD_ITEM_COUNT
// MUST BE LAST
281 OSD_UNIT_METRIC_MPH
, // Old UK units, all metric except speed in mph
282 OSD_UNIT_UK
, // Show everything in imperial, temperature in C
283 OSD_UNIT_GA
, // General Aviation: Knots, Nautical Miles, Feet, Degrees C
285 OSD_UNIT_MAX
= OSD_UNIT_GA
,
289 OSD_STATS_ENERGY_UNIT_MAH
,
290 OSD_STATS_ENERGY_UNIT_WH
,
291 } osd_stats_energy_unit_e
;
294 OSD_STATS_MIN_VOLTAGE_UNIT_BATTERY
,
295 OSD_STATS_MIN_VOLTAGE_UNIT_CELL
,
296 } osd_stats_min_voltage_unit_e
;
299 OSD_CROSSHAIRS_STYLE_DEFAULT
,
300 OSD_CROSSHAIRS_STYLE_AIRCRAFT
,
301 OSD_CROSSHAIRS_STYLE_TYPE3
,
302 OSD_CROSSHAIRS_STYLE_TYPE4
,
303 OSD_CROSSHAIRS_STYLE_TYPE5
,
304 OSD_CROSSHAIRS_STYLE_TYPE6
,
305 OSD_CROSSHAIRS_STYLE_TYPE7
,
306 } osd_crosshairs_style_e
;
309 OSD_SIDEBAR_SCROLL_NONE
,
310 OSD_SIDEBAR_SCROLL_ALTITUDE
,
311 OSD_SIDEBAR_SCROLL_SPEED
,
312 OSD_SIDEBAR_SCROLL_HOME_DISTANCE
,
314 OSD_SIDEBAR_SCROLL_MAX
= OSD_SIDEBAR_SCROLL_HOME_DISTANCE
,
315 } osd_sidebar_scroll_e
;
323 OSD_AHI_STYLE_DEFAULT
,
331 } osd_crsf_lq_format_e
;
333 typedef struct osdLayoutsConfig_s
{
335 uint16_t item_pos
[OSD_LAYOUT_COUNT
][OSD_ITEM_COUNT
];
336 } osdLayoutsConfig_t
;
338 PG_DECLARE(osdLayoutsConfig_t
, osdLayoutsConfig
);
340 #define OSD_SWITCH_INDICATOR_NAME_LENGTH 4
342 typedef struct osdConfig_s
{
344 uint8_t rssi_alarm
; // rssi %
345 uint16_t time_alarm
; // fly minutes
346 uint16_t alt_alarm
; // positive altitude in m
347 uint16_t dist_alarm
; // home distance in m
348 uint16_t neg_alt_alarm
; // abs(negative altitude) in m
349 uint8_t current_alarm
; // current consumption in A
350 int16_t imu_temp_alarm_min
;
351 int16_t imu_temp_alarm_max
;
352 int16_t esc_temp_alarm_min
;
353 int16_t esc_temp_alarm_max
;
355 float gforce_axis_alarm_min
;
356 float gforce_axis_alarm_max
;
357 #ifdef USE_SERIALRX_CRSF
358 int8_t snr_alarm
; //CRSF SNR alarm in dB
359 int8_t link_quality_alarm
;
360 int16_t rssi_dbm_alarm
; // in dBm
361 int16_t rssi_dbm_max
; // Perfect RSSI. Set to High end of curve. RSSI at 100%
362 int16_t rssi_dbm_min
; // Worst RSSI. Set to low end of curve or RX sensitivity level. RSSI at 0%
365 int16_t baro_temp_alarm_min
;
366 int16_t baro_temp_alarm_max
;
368 #ifdef USE_TEMPERATURE_SENSOR
369 osd_alignment_e temp_label_align
;
372 float airspeed_alarm_min
;
373 float airspeed_alarm_max
;
376 videoSystem_e video_system
;
377 uint8_t row_shiftdown
;
378 int16_t msp_displayport_fullframe_interval
;
381 uint8_t main_voltage_decimals
;
382 uint8_t ahi_reverse_roll
;
383 uint8_t ahi_max_pitch
;
384 uint8_t crosshairs_style
; // from osd_crosshairs_style_e
385 int8_t horizon_offset
;
386 int8_t camera_uptilt
;
387 bool ahi_camera_uptilt_comp
;
388 uint8_t camera_fov_h
;
389 uint8_t camera_fov_v
;
390 uint8_t hud_margin_h
;
391 uint8_t hud_margin_v
;
394 uint8_t hud_radar_disp
;
395 uint16_t hud_radar_range_min
;
396 uint16_t hud_radar_range_max
;
397 uint8_t hud_radar_alt_difference_display_time
;
398 uint8_t hud_radar_distance_display_time
;
401 uint8_t left_sidebar_scroll
; // from osd_sidebar_scroll_e
402 uint8_t right_sidebar_scroll
; // from osd_sidebar_scroll_e
403 uint8_t sidebar_scroll_arrows
;
405 uint8_t units
; // from osd_unit_e
406 uint8_t stats_energy_unit
; // from osd_stats_energy_unit_e
407 uint8_t stats_min_voltage_unit
; // from osd_stats_min_voltage_unit_e
408 uint8_t stats_page_auto_swap_time
; // stats page auto swap interval time (seconds)
410 #ifdef USE_WIND_ESTIMATOR
411 bool estimations_wind_compensation
; // use wind compensation for estimated remaining flight/distance
414 uint8_t coordinate_digits
;
416 bool osd_failsafe_switch_layout
;
417 uint8_t plus_code_digits
; // Number of digits to use in OSD_PLUS_CODE
418 uint8_t plus_code_short
;
420 uint8_t force_grid
; // Force a pixel based OSD to use grid mode.
421 uint8_t ahi_bordered
; // Only used by the AHI widget
422 uint8_t ahi_width
; // In pixels, only used by the AHI widget
423 uint8_t ahi_height
; // In pixels, only used by the AHI widget
424 int8_t ahi_vertical_offset
; // Offset from center in pixels. Positive moves the AHI down. Widget only.
425 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.
426 uint8_t left_sidebar_scroll_step
; // How many units each sidebar step represents. 0 means the default value for the scroll type.
427 uint8_t right_sidebar_scroll_step
; // Same as left_sidebar_scroll_step, but for the right sidebar.
428 bool osd_home_position_arm_screen
;
429 uint8_t pan_servo_index
; // Index of the pan servo used for home direction offset
430 int8_t pan_servo_pwm2centideg
; // Centidegrees of servo rotation per us pwm
431 uint8_t crsf_lq_format
;
432 uint8_t sidebar_height
; // sidebar height in rows, 0 turns off sidebars leaving only level indicator arrows
433 uint8_t telemetry
; // use telemetry on displayed pixel line 0
434 uint8_t esc_rpm_precision
; // Number of characters used for the RPM numbers.
435 uint16_t system_msg_display_time
; // system message display time for multiple messages (ms)
436 uint8_t mAh_used_precision
; // Number of numbers used for mAh drawn. Plently of packs now are > 9999 mAh
437 uint8_t ahi_pitch_interval
; // redraws AHI at set pitch interval (Not pixel OSD)
438 char osd_switch_indicator0_name
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1]; // Name to use for switch indicator 0.
439 uint8_t osd_switch_indicator0_channel
; // RC Channel to use for switch indicator 0.
440 char osd_switch_indicator1_name
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1]; // Name to use for switch indicator 1.
441 uint8_t osd_switch_indicator1_channel
; // RC Channel to use for switch indicator 1.
442 char osd_switch_indicator2_name
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1]; // Name to use for switch indicator 2.
443 uint8_t osd_switch_indicator2_channel
; // RC Channel to use for switch indicator 2.
444 char osd_switch_indicator3_name
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1]; // Name to use for switch indicator 3.
445 uint8_t osd_switch_indicator3_channel
; // RC Channel to use for switch indicator 3.
446 bool osd_switch_indicators_align_left
; // Align switch indicator name to left of the switch.
449 PG_DECLARE(osdConfig_t
, osdConfig
);
451 typedef struct displayPort_s displayPort_t
;
452 typedef struct displayCanvas_s displayCanvas_t
;
454 void osdInit(displayPort_t
*osdDisplayPort
);
455 bool osdDisplayIsPAL(void);
456 void osdUpdate(timeUs_t currentTimeUs
);
457 void osdStartFullRedraw(void);
458 // Sets a fixed OSD layout ignoring the RC input. Set it
459 // to -1 to disable the override. If layout is >= 0 and
460 // duration is > 0, the override is automatically cleared by
461 // the OSD after the given duration. Otherwise, the caller must
462 // explicitely remove it.
463 void osdOverrideLayout(int layout
, timeMs_t duration
);
464 // Returns the current current layout as well as wether its
465 // set by the user configuration (modes, etc..) or by overriding it.
466 int osdGetActiveLayout(bool *overridden
);
467 bool osdItemIsFixed(osd_items_e item
);
468 uint8_t osdIncElementIndex(uint8_t elementIndex
);
470 displayPort_t
*osdGetDisplayPort(void);
471 displayCanvas_t
*osdGetDisplayPortCanvas(void);
473 int16_t osdGetHeading(void);
474 int32_t osdGetAltitude(void);
476 void osdStartedSaveProcess(void);
477 void osdShowEEPROMSavedNotification(void);
479 void osdCrosshairPosition(uint8_t *x
, uint8_t *y
);
480 bool osdFormatCentiNumber(char *buff
, int32_t centivalue
, uint32_t scale
, int maxDecimals
, int maxScaledDecimals
, int length
);
481 void osdFormatAltitudeSymbol(char *buff
, int32_t alt
);
482 void osdFormatVelocityStr(char* buff
, int32_t vel
, bool _3D
, bool _max
);
483 // Returns a heading angle in degrees normalized to [0, 360).
484 int osdGetHeadingAngle(int angle
);
486 void resetOsdWarningFlags(void);
489 * @brief Get the OSD system message
490 * @param buff pointer to the message buffer
491 * @param buff_size size of the buffer array
492 * @param isCenteredText if true, centered text based on buff_size
493 * @return osd text attributes (Blink, Inverted, Solid)
495 textAttributes_t
osdGetSystemMessage(char *buff
, size_t buff_size
, bool isCenteredText
);