[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / osd / osd.h
blobc7c53f9ced859af5149311aac6036e1cc0842000
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "common/time.h"
24 #include "common/unit.h"
26 #include "drivers/display.h"
28 #include "pg/pg.h"
30 #include "sensors/esc_sensor.h"
32 #define OSD_NUM_TIMER_TYPES 4
33 extern const char * const osdTimerSourceNames[OSD_NUM_TIMER_TYPES];
35 #define OSD_ELEMENT_BUFFER_LENGTH 32
37 #define OSD_PROFILE_NAME_LENGTH 16
39 #ifdef USE_OSD_PROFILES
40 #define OSD_PROFILE_COUNT 3
41 #else
42 #define OSD_PROFILE_COUNT 1
43 #endif
45 #define OSD_RCCHANNELS_COUNT 4
47 #define OSD_CAMERA_FRAME_MIN_WIDTH 2
48 #define OSD_CAMERA_FRAME_MAX_WIDTH 30 // Characters per row supportes by MAX7456
49 #define OSD_CAMERA_FRAME_MIN_HEIGHT 2
50 #define OSD_CAMERA_FRAME_MAX_HEIGHT 16 // Rows supported by MAX7456 (PAL)
52 #define OSD_FRAMERATE_MIN_HZ 1
53 #define OSD_FRAMERATE_MAX_HZ 60
54 #define OSD_FRAMERATE_DEFAULT_HZ 12
56 #define OSD_PROFILE_BITS_POS 11
57 #define OSD_PROFILE_MASK (((1 << OSD_PROFILE_COUNT) - 1) << OSD_PROFILE_BITS_POS)
58 #define OSD_POS_MAX 0x7FF
59 #define OSD_POSCFG_MAX UINT16_MAX // element positions now use all 16 bits
60 #define OSD_PROFILE_FLAG(x) (1 << ((x) - 1 + OSD_PROFILE_BITS_POS))
61 #define OSD_PROFILE_1_FLAG OSD_PROFILE_FLAG(1)
64 #ifdef USE_OSD_PROFILES
65 #define VISIBLE(x) osdElementVisible(x)
66 #define VISIBLE_IN_OSD_PROFILE(item, profile) ((item) & ((OSD_PROFILE_1_FLAG) << ((profile)-1)))
67 #else
68 #define VISIBLE(x) ((x) & OSD_PROFILE_MASK)
69 #define VISIBLE_IN_OSD_PROFILE(item, profile) VISIBLE(item)
70 #endif
73 // Character coordinate
74 #define OSD_POSITION_BITS 5 // 5 bits gives a range 0-31
75 #define OSD_POSITION_BIT_XHD 10 // extra bit used to extend X range in a backward compatible manner for HD displays
76 #define OSD_POSITION_XHD_MASK (1 << OSD_POSITION_BIT_XHD)
77 #define OSD_POSITION_XY_MASK ((1 << OSD_POSITION_BITS) - 1)
78 #define OSD_TYPE_MASK 0xC000 // bits 14-15
79 #define OSD_POS(x,y) ((x & OSD_POSITION_XY_MASK) | ((x << (OSD_POSITION_BIT_XHD - OSD_POSITION_BITS)) & OSD_POSITION_XHD_MASK) | \
80 ((y & OSD_POSITION_XY_MASK) << OSD_POSITION_BITS))
81 #define OSD_X(x) ((x & OSD_POSITION_XY_MASK) | ((x & OSD_POSITION_XHD_MASK) >> (OSD_POSITION_BIT_XHD - OSD_POSITION_BITS)))
82 #define OSD_Y(x) ((x >> OSD_POSITION_BITS) & OSD_POSITION_XY_MASK)
83 #define OSD_TYPE(x) ((x & OSD_TYPE_MASK) >> 14)
85 #define OSD_SD_COLS VIDEO_COLUMNS_SD
86 #define OSD_SD_ROWS VIDEO_LINES_PAL
88 // Default HD OSD canvas size to be applied unless the goggles announce otherwise
89 #define OSD_HD_COLS 53
90 #define OSD_HD_ROWS 20
92 // Timer configuration
93 // Stored as 15[alarm:8][precision:4][source:4]0
94 #define OSD_TIMER(src, prec, alarm) ((src & 0x0F) | ((prec & 0x0F) << 4) | ((alarm & 0xFF ) << 8))
95 #define OSD_TIMER_SRC(timer) (timer & 0x0F)
96 #define OSD_TIMER_PRECISION(timer) ((timer >> 4) & 0x0F)
97 #define OSD_TIMER_ALARM(timer) ((timer >> 8) & 0xFF)
99 #ifdef USE_MAX7456
100 #define OSD_DRAW_FREQ_DENOM 5
101 #else
102 // MWOSD @ 115200 baud
103 #define OSD_DRAW_FREQ_DENOM 10
104 #endif
106 // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry.
108 // *** IMPORTANT ***
109 // See the information at the top of osd/osd_elements.c for instructions
110 // on how to add OSD elements.
111 typedef enum {
112 OSD_RSSI_VALUE,
113 OSD_MAIN_BATT_VOLTAGE,
114 OSD_CROSSHAIRS,
115 OSD_ARTIFICIAL_HORIZON,
116 OSD_HORIZON_SIDEBARS,
117 OSD_ITEM_TIMER_1,
118 OSD_ITEM_TIMER_2,
119 OSD_FLYMODE,
120 OSD_CRAFT_NAME,
121 OSD_THROTTLE_POS,
122 OSD_VTX_CHANNEL,
123 OSD_CURRENT_DRAW,
124 OSD_MAH_DRAWN,
125 OSD_GPS_SPEED,
126 OSD_GPS_SATS,
127 OSD_ALTITUDE,
128 OSD_ROLL_PIDS,
129 OSD_PITCH_PIDS,
130 OSD_YAW_PIDS,
131 OSD_POWER,
132 OSD_PIDRATE_PROFILE,
133 OSD_WARNINGS,
134 OSD_AVG_CELL_VOLTAGE,
135 OSD_GPS_LON,
136 OSD_GPS_LAT,
137 OSD_DEBUG,
138 OSD_PITCH_ANGLE,
139 OSD_ROLL_ANGLE,
140 OSD_MAIN_BATT_USAGE,
141 OSD_DISARMED,
142 OSD_HOME_DIR,
143 OSD_HOME_DIST,
144 OSD_NUMERICAL_HEADING,
145 OSD_NUMERICAL_VARIO,
146 OSD_COMPASS_BAR,
147 OSD_ESC_TMP,
148 OSD_ESC_RPM,
149 OSD_REMAINING_TIME_ESTIMATE,
150 OSD_RTC_DATETIME,
151 OSD_ADJUSTMENT_RANGE,
152 OSD_CORE_TEMPERATURE,
153 OSD_ANTI_GRAVITY,
154 OSD_G_FORCE,
155 OSD_MOTOR_DIAG,
156 OSD_LOG_STATUS,
157 OSD_FLIP_ARROW,
158 OSD_LINK_QUALITY,
159 OSD_FLIGHT_DIST,
160 OSD_STICK_OVERLAY_LEFT,
161 OSD_STICK_OVERLAY_RIGHT,
162 OSD_PILOT_NAME,
163 OSD_ESC_RPM_FREQ,
164 OSD_RATE_PROFILE_NAME,
165 OSD_PID_PROFILE_NAME,
166 OSD_PROFILE_NAME,
167 OSD_RSSI_DBM_VALUE,
168 OSD_RC_CHANNELS,
169 OSD_CAMERA_FRAME,
170 OSD_EFFICIENCY,
171 OSD_TOTAL_FLIGHTS,
172 OSD_UP_DOWN_REFERENCE,
173 OSD_TX_UPLINK_POWER,
174 OSD_WATT_HOURS_DRAWN,
175 OSD_AUX_VALUE,
176 OSD_READY_MODE,
177 OSD_RSNR_VALUE,
178 OSD_SYS_GOGGLE_VOLTAGE,
179 OSD_SYS_VTX_VOLTAGE,
180 OSD_SYS_BITRATE,
181 OSD_SYS_DELAY,
182 OSD_SYS_DISTANCE,
183 OSD_SYS_LQ,
184 OSD_SYS_GOGGLE_DVR,
185 OSD_SYS_VTX_DVR,
186 OSD_SYS_WARNINGS,
187 OSD_SYS_VTX_TEMP,
188 OSD_SYS_FAN_SPEED,
189 OSD_ITEM_COUNT // MUST BE LAST
190 } osd_items_e;
192 // *** IMPORTANT ***
193 // Whenever new elements are added to 'osd_items_e', make sure to increment
194 // the parameter group version for 'osdConfig' in 'osd.c'
196 // *** IMPORTANT ***
197 // DO NOT REORDER THE STATS ENUMERATION. The order here cooresponds to the enabled flag bit position
198 // storage and changing the order will corrupt user settings. Any new stats MUST be added to the end
199 // just before the OSD_STAT_COUNT entry. YOU MUST ALSO add the new stat to the
200 // osdStatsDisplayOrder array in osd.c.
202 // IF YOU WANT TO REORDER THE STATS DISPLAY, then adjust the ordering of the osdStatsDisplayOrder array
203 typedef enum {
204 OSD_STAT_RTC_DATE_TIME,
205 OSD_STAT_TIMER_1,
206 OSD_STAT_TIMER_2,
207 OSD_STAT_MAX_SPEED,
208 OSD_STAT_MAX_DISTANCE,
209 OSD_STAT_MIN_BATTERY,
210 OSD_STAT_END_BATTERY,
211 OSD_STAT_BATTERY,
212 OSD_STAT_MIN_RSSI,
213 OSD_STAT_MAX_CURRENT,
214 OSD_STAT_USED_MAH,
215 OSD_STAT_MAX_ALTITUDE,
216 OSD_STAT_BLACKBOX,
217 OSD_STAT_BLACKBOX_NUMBER,
218 OSD_STAT_MAX_G_FORCE,
219 OSD_STAT_MAX_ESC_TEMP,
220 OSD_STAT_MAX_ESC_RPM,
221 OSD_STAT_MIN_LINK_QUALITY,
222 OSD_STAT_FLIGHT_DISTANCE,
223 OSD_STAT_MAX_FFT,
224 OSD_STAT_TOTAL_FLIGHTS,
225 OSD_STAT_TOTAL_TIME,
226 OSD_STAT_TOTAL_DIST,
227 OSD_STAT_MIN_RSSI_DBM,
228 OSD_STAT_WATT_HOURS_DRAWN,
229 OSD_STAT_MIN_RSNR,
230 OSD_STAT_COUNT // MUST BE LAST
231 } osd_stats_e;
233 // Make sure the number of stats do not exceed the available 32bit storage
234 STATIC_ASSERT(OSD_STAT_COUNT <= 32, osdstats_overflow);
236 typedef enum {
237 OSD_TIMER_1,
238 OSD_TIMER_2,
239 OSD_TIMER_COUNT
240 } osd_timer_e;
242 typedef enum {
243 OSD_TIMER_SRC_ON,
244 OSD_TIMER_SRC_TOTAL_ARMED,
245 OSD_TIMER_SRC_LAST_ARMED,
246 OSD_TIMER_SRC_ON_OR_ARMED,
247 OSD_TIMER_SRC_COUNT
248 } osd_timer_source_e;
250 typedef enum {
251 OSD_TIMER_PREC_SECOND,
252 OSD_TIMER_PREC_HUNDREDTHS,
253 OSD_TIMER_PREC_TENTHS,
254 OSD_TIMER_PREC_COUNT
255 } osd_timer_precision_e;
257 typedef enum {
258 OSD_WARNING_ARMING_DISABLE,
259 OSD_WARNING_BATTERY_NOT_FULL,
260 OSD_WARNING_BATTERY_WARNING,
261 OSD_WARNING_BATTERY_CRITICAL,
262 OSD_WARNING_VISUAL_BEEPER,
263 OSD_WARNING_CRASH_FLIP,
264 OSD_WARNING_ESC_FAIL,
265 OSD_WARNING_CORE_TEMPERATURE,
266 OSD_WARNING_RC_SMOOTHING,
267 OSD_WARNING_FAIL_SAFE,
268 OSD_WARNING_LAUNCH_CONTROL,
269 OSD_WARNING_GPS_RESCUE_UNAVAILABLE,
270 OSD_WARNING_GPS_RESCUE_DISABLED,
271 OSD_WARNING_RSSI,
272 OSD_WARNING_LINK_QUALITY,
273 OSD_WARNING_RSSI_DBM,
274 OSD_WARNING_OVER_CAP,
275 OSD_WARNING_RSNR,
276 OSD_WARNING_COUNT // MUST BE LAST
277 } osdWarningsFlags_e;
279 typedef enum {
280 OSD_DISPLAYPORT_DEVICE_NONE = 0,
281 OSD_DISPLAYPORT_DEVICE_AUTO,
282 OSD_DISPLAYPORT_DEVICE_MAX7456,
283 OSD_DISPLAYPORT_DEVICE_MSP,
284 OSD_DISPLAYPORT_DEVICE_FRSKYOSD,
285 } osdDisplayPortDevice_e;
287 // Make sure the number of warnings do not exceed the available 32bit storage
288 STATIC_ASSERT(OSD_WARNING_COUNT <= 32, osdwarnings_overflow);
290 #define ESC_RPM_ALARM_OFF -1
291 #define ESC_TEMP_ALARM_OFF 0
292 #define ESC_CURRENT_ALARM_OFF -1
294 #define OSD_GPS_RESCUE_DISABLED_WARNING_DURATION_US 3000000 // 3 seconds
296 extern const uint16_t osdTimerDefault[OSD_TIMER_COUNT];
297 extern const osd_stats_e osdStatsDisplayOrder[OSD_STAT_COUNT];
299 typedef struct osdConfig_s {
300 // Alarms
301 uint16_t cap_alarm;
302 uint16_t alt_alarm;
303 uint8_t rssi_alarm;
305 uint8_t units;
307 uint16_t timers[OSD_TIMER_COUNT];
308 uint32_t enabledWarnings;
310 uint8_t ahMaxPitch;
311 uint8_t ahMaxRoll;
312 uint32_t enabled_stats;
313 uint8_t esc_temp_alarm;
314 int16_t esc_rpm_alarm;
315 int16_t esc_current_alarm;
316 uint8_t core_temp_alarm;
317 uint8_t ahInvert; // invert the artificial horizon
318 uint8_t osdProfileIndex;
319 uint8_t overlay_radio_mode;
320 char profile[OSD_PROFILE_COUNT][OSD_PROFILE_NAME_LENGTH + 1];
321 uint16_t link_quality_alarm;
322 int16_t rssi_dbm_alarm;
323 int16_t rsnr_alarm;
324 uint8_t gps_sats_show_hdop;
325 int8_t rcChannels[OSD_RCCHANNELS_COUNT]; // RC channel values to display, -1 if none
326 uint8_t displayPortDevice; // osdDisplayPortDevice_e
327 uint16_t distance_alarm;
328 uint8_t logo_on_arming; // show the logo on arming
329 uint8_t logo_on_arming_duration; // display duration in 0.1s units
330 uint8_t camera_frame_width; // The width of the box for the camera frame element
331 uint8_t camera_frame_height; // The height of the box for the camera frame element
332 uint16_t framerate_hz;
333 uint8_t cms_background_type; // For supporting devices, determines whether the CMS background is transparent or opaque
334 uint8_t stat_show_cell_value;
335 #ifdef USE_CRAFTNAME_MSGS
336 uint8_t osd_craftname_msgs; // Insert LQ/RSSI-dBm and warnings into CraftName
337 #endif //USE_CRAFTNAME_MSGS
338 uint8_t aux_channel;
339 uint16_t aux_scale;
340 uint8_t aux_symbol;
341 uint8_t canvas_cols; // Canvas dimensions for HD display
342 uint8_t canvas_rows;
343 } osdConfig_t;
345 PG_DECLARE(osdConfig_t, osdConfig);
347 typedef struct osdElementConfig_s {
348 uint16_t item_pos[OSD_ITEM_COUNT];
349 } osdElementConfig_t;
351 PG_DECLARE(osdElementConfig_t, osdElementConfig);
353 typedef struct statistic_s {
354 timeUs_t armed_time;
355 int16_t max_speed;
356 int16_t min_voltage; // /100
357 uint16_t end_voltage;
358 int16_t max_current; // /10
359 uint8_t min_rssi;
360 int32_t max_altitude;
361 int16_t max_distance;
362 float max_g_force;
363 int16_t max_esc_temp_ix;
364 int16_t max_esc_temp;
365 int32_t max_esc_rpm;
366 uint16_t min_link_quality;
367 int16_t min_rssi_dbm;
368 int16_t min_rsnr;
369 } statistic_t;
371 extern timeUs_t resumeRefreshAt;
372 extern timeUs_t osdFlyTime;
373 #if defined(USE_ACC)
374 extern float osdGForce;
375 #endif
376 #ifdef USE_ESC_SENSOR
377 extern escSensorData_t *osdEscDataCombined;
378 #endif
379 extern uint16_t osdAuxValue;
381 void osdInit(displayPort_t *osdDisplayPort, osdDisplayPortDevice_e displayPortDevice);
382 bool osdUpdateCheck(timeUs_t currentTimeUs, timeDelta_t currentDeltaTimeUs);
383 void osdUpdate(timeUs_t currentTimeUs);
385 void osdStatSetState(uint8_t statIndex, bool enabled);
386 bool osdStatGetState(uint8_t statIndex);
387 void osdSuppressStats(bool flag);
388 void osdAnalyzeActiveElements(void);
389 void changeOsdProfileIndex(uint8_t profileIndex);
390 uint8_t getCurrentOsdProfileIndex(void);
391 displayPort_t *osdGetDisplayPort(osdDisplayPortDevice_e *displayPortDevice);
393 void osdWarnSetState(uint8_t warningIndex, bool enabled);
394 bool osdWarnGetState(uint8_t warningIndex);
395 bool osdElementVisible(uint16_t value);
396 bool osdGetVisualBeeperState(void);
397 void osdSetVisualBeeperState(bool state);
398 statistic_t *osdGetStats(void);
399 bool osdNeedsAccelerometer(void);
400 int osdPrintFloat(char *buffer, char leadingSymbol, float value, char *formatString, unsigned decimalPlaces, bool round, char trailingSymbol);