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/>.
19 Created by Marcin Baliniak
20 some functions based on MinimOSD
22 OSD-CMS separation by jflyper
34 FILE_COMPILE_FOR_SPEED
38 #include "build/debug.h"
39 #include "build/version.h"
42 #include "cms/cms_types.h"
43 #include "cms/cms_menu_osd.h"
45 #include "common/axis.h"
46 #include "common/constants.h"
47 #include "common/filter.h"
48 #include "common/log.h"
49 #include "common/olc.h"
50 #include "common/printf.h"
51 #include "common/string_light.h"
52 #include "common/time.h"
53 #include "common/typeconversion.h"
54 #include "common/utils.h"
56 #include "config/feature.h"
57 #include "config/parameter_group.h"
58 #include "config/parameter_group_ids.h"
60 #include "drivers/display.h"
61 #include "drivers/display_canvas.h"
62 #include "drivers/display_font_metadata.h"
63 #include "drivers/osd_symbols.h"
64 #include "drivers/time.h"
65 #include "drivers/vtx_common.h"
67 #include "io/flashfs.h"
70 #include "io/osd_common.h"
71 #include "io/osd_hud.h"
73 #include "io/vtx_string.h"
75 #include "fc/config.h"
76 #include "fc/controlrate_profile.h"
77 #include "fc/fc_core.h"
78 #include "fc/fc_tasks.h"
79 #include "fc/rc_adjustments.h"
80 #include "fc/rc_controls.h"
81 #include "fc/rc_modes.h"
82 #include "fc/runtime_config.h"
83 #include "fc/settings.h"
85 #include "flight/imu.h"
86 #include "flight/mixer.h"
87 #include "flight/pid.h"
88 #include "flight/power_limits.h"
89 #include "flight/rth_estimator.h"
90 #include "flight/secondary_imu.h"
91 #include "flight/servos.h"
92 #include "flight/wind_estimator.h"
94 #include "navigation/navigation.h"
95 #include "navigation/navigation_private.h"
98 #include "rx/msp_override.h"
100 #include "sensors/acceleration.h"
101 #include "sensors/battery.h"
102 #include "sensors/boardalignment.h"
103 #include "sensors/diagnostics.h"
104 #include "sensors/sensors.h"
105 #include "sensors/pitotmeter.h"
106 #include "sensors/temperature.h"
107 #include "sensors/esc_sensor.h"
108 #include "sensors/rangefinder.h"
110 #include "programming/logic_condition.h"
111 #include "programming/global_variables.h"
113 #ifdef USE_HARDWARE_REVISION_DETECTION
114 #include "hardware_revision.h"
117 #define VIDEO_BUFFER_CHARS_PAL 480
119 #define GFORCE_FILTER_TC 0.2
121 #define DELAYED_REFRESH_RESUME_COMMAND (checkStickPosition(THR_HI) || checkStickPosition(PIT_HI))
122 #define STATS_PAGE2 (checkStickPosition(ROL_HI))
123 #define STATS_PAGE1 (checkStickPosition(ROL_LO))
125 #define SPLASH_SCREEN_DISPLAY_TIME 4000 // ms
126 #define ARMED_SCREEN_DISPLAY_TIME 1500 // ms
127 #define STATS_SCREEN_DISPLAY_TIME 60000 // ms
129 #define EFFICIENCY_UPDATE_INTERVAL (5 * 1000)
131 // Adjust OSD_MESSAGE's default position when
132 // changing OSD_MESSAGE_LENGTH
133 #define OSD_MESSAGE_LENGTH 28
134 #define OSD_ALTERNATING_CHOICES(ms, num_choices) ((millis() / ms) % num_choices)
135 #define _CONST_STR_SIZE(s) ((sizeof(s)/sizeof(s[0]))-1) // -1 to avoid counting final '\0'
136 // Wrap all string constants intenteded for display as messages with
137 // this macro to ensure compile time length validation.
138 #define OSD_MESSAGE_STR(x) ({ \
139 STATIC_ASSERT(_CONST_STR_SIZE(x) <= OSD_MESSAGE_LENGTH, message_string_ ## __COUNTER__ ## _too_long); \
143 #define OSD_CHR_IS_NUM(c) (c >= '0' && c <= '9')
145 #define OSD_CENTER_LEN(x) ((osdDisplayPort->cols - x) / 2)
146 #define OSD_CENTER_S(s) OSD_CENTER_LEN(strlen(s))
148 #define OSD_MIN_FONT_VERSION 3
150 static unsigned currentLayout
= 0;
151 static int layoutOverride
= -1;
152 static bool hasExtendedFont
= false; // Wether the font supports characters > 256
153 static timeMs_t layoutOverrideUntil
= 0;
154 static pt1Filter_t GForceFilter
, GForceFilterAxis
[XYZ_AXIS_COUNT
];
155 static float GForce
, GForceAxis
[XYZ_AXIS_COUNT
];
157 typedef struct statistic_s
{
159 uint16_t max_3D_speed
;
160 uint16_t max_air_speed
;
161 uint16_t min_voltage
; // /100
165 int16_t min_lq
; // for CRSF
166 int16_t min_rssi_dbm
; // for CRSF
167 int32_t max_altitude
;
168 uint32_t max_distance
;
171 static statistic_t stats
;
173 static timeUs_t resumeRefreshAt
= 0;
174 static bool refreshWaitForResumeCmdRelease
;
176 static bool fullRedraw
= false;
178 static uint8_t armState
;
179 static uint8_t statsPagesCheck
= 0;
181 typedef struct osdMapData_s
{
183 char referenceSymbol
;
186 static osdMapData_t osdMapData
;
188 static displayPort_t
*osdDisplayPort
;
189 static bool osdDisplayIsReady
= false;
190 #if defined(USE_CANVAS)
191 static displayCanvas_t osdCanvas
;
192 static bool osdDisplayHasCanvas
;
194 #define osdDisplayHasCanvas false
197 #define AH_MAX_PITCH_DEFAULT 20 // Specify default maximum AHI pitch value displayed (degrees)
199 PG_REGISTER_WITH_RESET_TEMPLATE(osdConfig_t
, osdConfig
, PG_OSD_CONFIG
, 5);
200 PG_REGISTER_WITH_RESET_FN(osdLayoutsConfig_t
, osdLayoutsConfig
, PG_OSD_LAYOUTS_CONFIG
, 0);
202 static int digitCount(int32_t value
)
215 bool osdDisplayIsPAL(void)
217 return displayScreenSize(osdDisplayPort
) == VIDEO_BUFFER_CHARS_PAL
;
221 * Formats a number given in cents, to support non integer values
222 * without using floating point math. Value is always right aligned
223 * and spaces are inserted before the number to always yield a string
224 * of the same length. If the value doesn't fit into the provided length
225 * it will be divided by scale and true will be returned.
227 bool osdFormatCentiNumber(char *buff
, int32_t centivalue
, uint32_t scale
, int maxDecimals
, int maxScaledDecimals
, int length
)
231 int decimals
= maxDecimals
;
232 bool negative
= false;
237 if (centivalue
< 0) {
239 centivalue
= -centivalue
;
243 int32_t integerPart
= centivalue
/ 100;
245 int32_t millis
= (centivalue
% 100) * 10;
247 int digits
= digitCount(integerPart
);
248 int remaining
= length
- digits
;
250 if (remaining
< 0 && scale
> 0) {
253 decimals
= maxScaledDecimals
;
254 integerPart
= integerPart
/ scale
;
255 // Multiply by 10 to get 3 decimal digits
256 millis
= ((centivalue
% (100 * scale
)) * 10) / scale
;
257 digits
= digitCount(integerPart
);
258 remaining
= length
- digits
;
261 // 3 decimals at most
262 decimals
= MIN(remaining
, MIN(decimals
, 3));
263 remaining
-= decimals
;
265 // Done counting. Time to write the characters.
267 // Write spaces at the start
268 while (remaining
> 0) {
274 // Write the minus sign if required
279 // Now write the digits.
280 ui2a(integerPart
, 10, 0, ptr
);
283 *(ptr
-1) += SYM_ZERO_HALF_TRAILING_DOT
- '0';
285 int factor
= 3; // we're getting the decimal part in millis first
286 while (decimals
< factor
) {
290 int decimalDigits
= digitCount(millis
);
291 while (decimalDigits
< decimals
) {
296 ui2a(millis
, 10, 0, ptr
);
297 *dec
+= SYM_ZERO_HALF_LEADING_DOT
- '0';
303 * Aligns text to the left side. Adds spaces at the end to keep string length unchanged.
305 static void osdLeftAlignString(char *buff
)
307 uint8_t sp
= 0, ch
= 0;
308 uint8_t len
= strlen(buff
);
309 while (buff
[sp
] == ' ') sp
++;
310 for (ch
= 0; ch
< (len
- sp
); ch
++) buff
[ch
] = buff
[ch
+ sp
];
311 for (sp
= ch
; sp
< len
; sp
++) buff
[sp
] = ' ';
315 * Converts distance into a string based on the current unit system
316 * prefixed by a a symbol to indicate the unit used.
317 * @param dist Distance in centimeters
319 static void osdFormatDistanceSymbol(char *buff
, int32_t dist
, uint8_t decimals
)
321 switch ((osd_unit_e
)osdConfig()->units
) {
324 case OSD_UNIT_IMPERIAL
:
325 if (osdFormatCentiNumber(buff
, CENTIMETERS_TO_CENTIFEET(dist
), FEET_PER_MILE
, decimals
, 3, 3)) {
326 buff
[3] = SYM_DIST_MI
;
328 buff
[3] = SYM_DIST_FT
;
332 case OSD_UNIT_METRIC_MPH
:
334 case OSD_UNIT_METRIC
:
335 if (osdFormatCentiNumber(buff
, dist
, METERS_PER_KILOMETER
, decimals
, 3, 3)) {
336 buff
[3] = SYM_DIST_KM
;
338 buff
[3] = SYM_DIST_M
;
343 if (osdFormatCentiNumber(buff
, CENTIMETERS_TO_CENTIFEET(dist
), FEET_PER_NAUTICALMILE
, decimals
, 3, 3)) {
344 buff
[3] = SYM_DIST_NM
;
346 buff
[3] = SYM_DIST_FT
;
354 * Converts distance into a string based on the current unit system.
355 * @param dist Distance in centimeters
357 static void osdFormatDistanceStr(char *buff
, int32_t dist
)
360 switch ((osd_unit_e
)osdConfig()->units
) {
363 case OSD_UNIT_IMPERIAL
:
364 centifeet
= CENTIMETERS_TO_CENTIFEET(dist
);
365 if (abs(centifeet
) < FEET_PER_MILE
* 100 / 2) {
366 // Show feet when dist < 0.5mi
367 tfp_sprintf(buff
, "%d%c", (int)(centifeet
/ 100), SYM_FT
);
369 // Show miles when dist >= 0.5mi
370 tfp_sprintf(buff
, "%d.%02d%c", (int)(centifeet
/ (100*FEET_PER_MILE
)),
371 (abs(centifeet
) % (100 * FEET_PER_MILE
)) / FEET_PER_MILE
, SYM_MI
);
374 case OSD_UNIT_METRIC_MPH
:
376 case OSD_UNIT_METRIC
:
377 if (abs(dist
) < METERS_PER_KILOMETER
* 100) {
378 // Show meters when dist < 1km
379 tfp_sprintf(buff
, "%d%c", (int)(dist
/ 100), SYM_M
);
381 // Show kilometers when dist >= 1km
382 tfp_sprintf(buff
, "%d.%02d%c", (int)(dist
/ (100*METERS_PER_KILOMETER
)),
383 (abs(dist
) % (100 * METERS_PER_KILOMETER
)) / METERS_PER_KILOMETER
, SYM_KM
);
387 centifeet
= CENTIMETERS_TO_CENTIFEET(dist
);
388 if (abs(centifeet
) < 100000) {
389 // Show feet when dist < 1000ft
390 tfp_sprintf(buff
, "%d%c", (int)(centifeet
/ 100), SYM_FT
);
392 // Show nautical miles when dist >= 1000ft
393 tfp_sprintf(buff
, "%d.%02d%c", (int)(centifeet
/ (100 * FEET_PER_NAUTICALMILE
)),
394 (int)((abs(centifeet
) % (int)(100 * FEET_PER_NAUTICALMILE
)) / FEET_PER_NAUTICALMILE
), SYM_NM
);
401 * Converts velocity based on the current unit system (kmh or mph).
402 * @param alt Raw velocity (i.e. as taken from gpsSol.groundSpeed in centimeters/second)
404 static int32_t osdConvertVelocityToUnit(int32_t vel
)
406 switch ((osd_unit_e
)osdConfig()->units
) {
409 case OSD_UNIT_METRIC_MPH
:
411 case OSD_UNIT_IMPERIAL
:
412 return CMSEC_TO_CENTIMPH(vel
) / 100; // Convert to mph
413 case OSD_UNIT_METRIC
:
414 return CMSEC_TO_CENTIKPH(vel
) / 100; // Convert to kmh
416 return CMSEC_TO_CENTIKNOTS(vel
) / 100; // Convert to Knots
423 * Converts velocity into a string based on the current unit system.
424 * @param vel Raw velocity (i.e. as taken from gpsSol.groundSpeed in centimeters/seconds)
425 * @param _3D is a 3D velocity
426 * @param _max is a maximum velocity
428 void osdFormatVelocityStr(char* buff
, int32_t vel
, bool _3D
, bool _max
)
430 switch ((osd_unit_e
)osdConfig()->units
) {
433 case OSD_UNIT_METRIC_MPH
:
435 case OSD_UNIT_IMPERIAL
:
437 tfp_sprintf(buff
, "%c%3d%c", SYM_MAX
, (int)osdConvertVelocityToUnit(vel
), (_3D
? SYM_3D_MPH
: SYM_MPH
));
439 tfp_sprintf(buff
, "%3d%c", (int)osdConvertVelocityToUnit(vel
), (_3D
? SYM_3D_MPH
: SYM_MPH
));
442 case OSD_UNIT_METRIC
:
444 tfp_sprintf(buff
, "%c%3d%c", SYM_MAX
, (int)osdConvertVelocityToUnit(vel
), (_3D
? SYM_3D_KMH
: SYM_KMH
));
446 tfp_sprintf(buff
, "%3d%c", (int)osdConvertVelocityToUnit(vel
), (_3D
? SYM_3D_KMH
: SYM_KMH
));
451 tfp_sprintf(buff
, "%c%3d%c", SYM_MAX
, (int)osdConvertVelocityToUnit(vel
), (_3D
? SYM_3D_KT
: SYM_KT
));
453 tfp_sprintf(buff
, "%3d%c", (int)osdConvertVelocityToUnit(vel
), (_3D
? SYM_3D_KT
: SYM_KT
));
460 * Returns the average velocity. This always uses stats, so can be called as an OSD element later if wanted, to show a real time average
462 static void osdGenerateAverageVelocityStr(char* buff
) {
463 uint32_t cmPerSec
= getTotalTravelDistance() / getFlightTime();
464 osdFormatVelocityStr(buff
, cmPerSec
, false, false);
468 * Converts wind speed into a string based on the current unit system, using
469 * always 3 digits and an additional character for the unit at the right. buff
470 * is null terminated.
471 * @param ws Raw wind speed in cm/s
473 #ifdef USE_WIND_ESTIMATOR
474 static void osdFormatWindSpeedStr(char *buff
, int32_t ws
, bool isValid
)
478 switch (osdConfig()->units
) {
481 case OSD_UNIT_METRIC_MPH
:
483 case OSD_UNIT_IMPERIAL
:
484 centivalue
= CMSEC_TO_CENTIMPH(ws
);
488 centivalue
= CMSEC_TO_CENTIKNOTS(ws
);
492 case OSD_UNIT_METRIC
:
493 centivalue
= CMSEC_TO_CENTIKPH(ws
);
498 osdFormatCentiNumber(buff
, centivalue
, 0, 2, 0, 3);
500 buff
[0] = buff
[1] = buff
[2] = '-';
508 * Converts altitude into a string based on the current unit system
509 * prefixed by a a symbol to indicate the unit used.
510 * @param alt Raw altitude/distance (i.e. as taken from baro.BaroAlt in centimeters)
512 void osdFormatAltitudeSymbol(char *buff
, int32_t alt
)
521 switch ((osd_unit_e
)osdConfig()->units
) {
526 case OSD_UNIT_IMPERIAL
:
527 if (osdFormatCentiNumber(buff
+ 4 - digits
, CENTIMETERS_TO_CENTIFEET(alt
), 1000, 0, 2, digits
)) {
529 buff
[4] = SYM_ALT_KFT
;
532 buff
[4] = SYM_ALT_FT
;
536 case OSD_UNIT_METRIC_MPH
:
538 case OSD_UNIT_METRIC
:
539 // alt is alredy in cm
540 if (osdFormatCentiNumber(buff
+ 4 - digits
, alt
, 1000, 0, 2, digits
)) {
542 buff
[4] = SYM_ALT_KM
;
553 * Converts altitude into a string based on the current unit system.
554 * @param alt Raw altitude/distance (i.e. as taken from baro.BaroAlt in centimeters)
556 static void osdFormatAltitudeStr(char *buff
, int32_t alt
)
559 switch ((osd_unit_e
)osdConfig()->units
) {
564 case OSD_UNIT_IMPERIAL
:
565 value
= CENTIMETERS_TO_FEET(alt
);
566 tfp_sprintf(buff
, "%d%c", (int)value
, SYM_FT
);
568 case OSD_UNIT_METRIC_MPH
:
570 case OSD_UNIT_METRIC
:
571 value
= CENTIMETERS_TO_METERS(alt
);
572 tfp_sprintf(buff
, "%d%c", (int)value
, SYM_M
);
577 static void osdFormatTime(char *buff
, uint32_t seconds
, char sym_m
, char sym_h
)
579 uint32_t value
= seconds
;
581 // Maximum value we can show in minutes is 99 minutes and 59 seconds
582 if (seconds
> (99 * 60) + 59) {
584 value
= seconds
/ 60;
587 tfp_sprintf(buff
+ 1, "%02d:%02d", (int)(value
/ 60), (int)(value
% 60));
590 static inline void osdFormatOnTime(char *buff
)
592 osdFormatTime(buff
, micros() / 1000000, SYM_ON_M
, SYM_ON_H
);
595 static inline void osdFormatFlyTime(char *buff
, textAttributes_t
*attr
)
597 uint32_t seconds
= getFlightTime();
598 osdFormatTime(buff
, seconds
, SYM_FLY_M
, SYM_FLY_H
);
599 if (attr
&& osdConfig()->time_alarm
> 0) {
600 if (seconds
/ 60 >= osdConfig()->time_alarm
&& ARMING_FLAG(ARMED
)) {
601 TEXT_ATTRIBUTES_ADD_BLINK(*attr
);
607 * Converts RSSI into a % value used by the OSD.
609 static uint16_t osdConvertRSSI(void)
611 // change range to [0, 99]
612 return constrain(getRSSI() * 100 / RSSI_MAX_VALUE
, 0, 99);
615 static uint16_t osdGetCrsfLQ(void)
617 int16_t statsLQ
= rxLinkStatistics
.uplinkLQ
;
618 int16_t scaledLQ
= scaleRange(constrain(statsLQ
, 0, 100), 0, 100, 170, 300);
620 switch (osdConfig()->crsf_lq_format
) {
621 case OSD_CRSF_LQ_TYPE1
:
622 displayedLQ
= statsLQ
;
624 case OSD_CRSF_LQ_TYPE2
:
625 displayedLQ
= statsLQ
;
627 case OSD_CRSF_LQ_TYPE3
:
628 displayedLQ
= rxLinkStatistics
.rfMode
>= 2 ? scaledLQ
: statsLQ
;
634 static int16_t osdGetCrsfdBm(void)
636 return rxLinkStatistics
.uplinkRSSI
;
639 * Displays a temperature postfixed with a symbol depending on the current unit system
640 * @param label to display
641 * @param valid true if measurement is valid
642 * @param temperature in deciDegrees Celcius
644 static void osdDisplayTemperature(uint8_t elemPosX
, uint8_t elemPosY
, uint16_t symbol
, const char *label
, bool valid
, int16_t temperature
, int16_t alarm_min
, int16_t alarm_max
)
646 char buff
[TEMPERATURE_LABEL_LEN
+ 2 < 6 ? 6 : TEMPERATURE_LABEL_LEN
+ 2];
647 textAttributes_t elemAttr
= valid
? TEXT_ATTRIBUTES_NONE
: _TEXT_ATTRIBUTES_BLINK_BIT
;
648 uint8_t valueXOffset
= 0;
653 displayWriteWithAttr(osdDisplayPort
, elemPosX
, elemPosY
, buff
, elemAttr
);
656 #ifdef USE_TEMPERATURE_SENSOR
657 else if (label
[0] != '\0') {
658 uint8_t label_len
= strnlen(label
, TEMPERATURE_LABEL_LEN
);
659 memcpy(buff
, label
, label_len
);
660 memset(buff
+ label_len
, ' ', TEMPERATURE_LABEL_LEN
+ 1 - label_len
);
662 displayWriteWithAttr(osdDisplayPort
, elemPosX
, elemPosY
, buff
, elemAttr
);
663 valueXOffset
= osdConfig()->temp_label_align
== OSD_ALIGN_LEFT
? 5 : label_len
+ 1;
671 if ((temperature
<= alarm_min
) || (temperature
>= alarm_max
)) TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
672 if (osdConfig()->units
== OSD_UNIT_IMPERIAL
) temperature
= temperature
* 9 / 5.0f
+ 320;
673 tfp_sprintf(buff
, "%3d", temperature
/ 10);
678 buff
[3] = osdConfig()->units
== OSD_UNIT_IMPERIAL
? SYM_TEMP_F
: SYM_TEMP_C
;
681 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ valueXOffset
, elemPosY
, buff
, elemAttr
);
684 #ifdef USE_TEMPERATURE_SENSOR
685 static void osdDisplayTemperatureSensor(uint8_t elemPosX
, uint8_t elemPosY
, uint8_t sensorIndex
)
688 const bool valid
= getSensorTemperature(sensorIndex
, &temperature
);
689 const tempSensorConfig_t
*sensorConfig
= tempSensorConfig(sensorIndex
);
690 uint16_t symbol
= sensorConfig
->osdSymbol
? SYM_TEMP_SENSOR_FIRST
+ sensorConfig
->osdSymbol
- 1 : 0;
691 osdDisplayTemperature(elemPosX
, elemPosY
, symbol
, sensorConfig
->label
, valid
, temperature
, sensorConfig
->alarm_min
, sensorConfig
->alarm_max
);
695 static void osdFormatCoordinate(char *buff
, char sym
, int32_t val
)
697 // up to 4 for number + 1 for the symbol + null terminator + fill the rest with decimals
698 const int coordinateLength
= osdConfig()->coordinate_digits
+ 1;
701 int32_t integerPart
= val
/ GPS_DEGREES_DIVIDER
;
702 // Latitude maximum integer width is 3 (-90) while
703 // longitude maximum integer width is 4 (-180).
704 int integerDigits
= tfp_sprintf(buff
+ 1, (integerPart
== 0 && val
< 0) ? "-%d" : "%d", (int)integerPart
);
705 // We can show up to 7 digits in decimalPart.
706 int32_t decimalPart
= abs(val
% GPS_DEGREES_DIVIDER
);
707 STATIC_ASSERT(GPS_DEGREES_DIVIDER
== 1e7
, adjust_max_decimal_digits
);
708 int decimalDigits
= tfp_sprintf(buff
+ 1 + integerDigits
, "%07d", (int)decimalPart
);
709 // Embbed the decimal separator
710 buff
[1 + integerDigits
- 1] += SYM_ZERO_HALF_TRAILING_DOT
- '0';
711 buff
[1 + integerDigits
] += SYM_ZERO_HALF_LEADING_DOT
- '0';
712 // Fill up to coordinateLength with zeros
713 int total
= 1 + integerDigits
+ decimalDigits
;
714 while(total
< coordinateLength
) {
718 buff
[coordinateLength
] = '\0';
721 static void osdFormatCraftName(char *buff
)
723 if (strlen(systemConfig()->name
) == 0)
724 strcpy(buff
, "CRAFT_NAME");
726 for (int i
= 0; i
< MAX_NAME_LENGTH
; i
++) {
727 buff
[i
] = sl_toupper((unsigned char)systemConfig()->name
[i
]);
728 if (systemConfig()->name
[i
] == 0)
734 static const char * osdArmingDisabledReasonMessage(void)
736 const char *message
= NULL
;
737 char messageBuf
[MAX(SETTING_MAX_NAME_LENGTH
, OSD_MESSAGE_LENGTH
+1)];
739 switch (isArmingDisabledReason()) {
740 case ARMING_DISABLED_FAILSAFE_SYSTEM
:
741 // See handling of FAILSAFE_RX_LOSS_MONITORING in failsafe.c
742 if (failsafePhase() == FAILSAFE_RX_LOSS_MONITORING
) {
743 if (failsafeIsReceivingRxData()) {
744 // If we're not using sticks, it means the ARM switch
745 // hasn't been off since entering FAILSAFE_RX_LOSS_MONITORING
747 return OSD_MESSAGE_STR(OSD_MSG_TURN_ARM_SW_OFF
);
749 // Not receiving RX data
750 return OSD_MESSAGE_STR(OSD_MSG_RC_RX_LINK_LOST
);
752 return OSD_MESSAGE_STR(OSD_MSG_DISABLED_BY_FS
);
753 case ARMING_DISABLED_NOT_LEVEL
:
754 return OSD_MESSAGE_STR(OSD_MSG_AIRCRAFT_UNLEVEL
);
755 case ARMING_DISABLED_SENSORS_CALIBRATING
:
756 return OSD_MESSAGE_STR(OSD_MSG_SENSORS_CAL
);
757 case ARMING_DISABLED_SYSTEM_OVERLOADED
:
758 return OSD_MESSAGE_STR(OSD_MSG_SYS_OVERLOADED
);
759 case ARMING_DISABLED_NAVIGATION_UNSAFE
:
760 // Check the exact reason
761 switch (navigationIsBlockingArming(NULL
)) {
763 case NAV_ARMING_BLOCKER_NONE
:
765 case NAV_ARMING_BLOCKER_MISSING_GPS_FIX
:
766 return OSD_MESSAGE_STR(OSD_MSG_WAITING_GPS_FIX
);
767 case NAV_ARMING_BLOCKER_NAV_IS_ALREADY_ACTIVE
:
768 return OSD_MESSAGE_STR(OSD_MSG_DISABLE_NAV_FIRST
);
769 case NAV_ARMING_BLOCKER_FIRST_WAYPOINT_TOO_FAR
:
770 osdFormatDistanceSymbol(buf
, distanceToFirstWP(), 0);
771 tfp_sprintf(messageBuf
, "FIRST WP TOO FAR (%s)", buf
);
772 return message
= messageBuf
;
773 case NAV_ARMING_BLOCKER_JUMP_WAYPOINT_ERROR
:
774 return OSD_MESSAGE_STR(OSD_MSG_JUMP_WP_MISCONFIG
);
777 case ARMING_DISABLED_COMPASS_NOT_CALIBRATED
:
778 return OSD_MESSAGE_STR(OSD_MSG_MAG_NOT_CAL
);
779 case ARMING_DISABLED_ACCELEROMETER_NOT_CALIBRATED
:
780 return OSD_MESSAGE_STR(OSD_MSG_ACC_NOT_CAL
);
781 case ARMING_DISABLED_ARM_SWITCH
:
782 return OSD_MESSAGE_STR(OSD_MSG_DISARM_1ST
);
783 case ARMING_DISABLED_HARDWARE_FAILURE
:
785 if (!HW_SENSOR_IS_HEALTHY(getHwGyroStatus())) {
786 return OSD_MESSAGE_STR(OSD_MSG_GYRO_FAILURE
);
788 if (!HW_SENSOR_IS_HEALTHY(getHwAccelerometerStatus())) {
789 return OSD_MESSAGE_STR(OSD_MSG_ACC_FAIL
);
791 if (!HW_SENSOR_IS_HEALTHY(getHwCompassStatus())) {
792 return OSD_MESSAGE_STR(OSD_MSG_MAG_FAIL
);
794 if (!HW_SENSOR_IS_HEALTHY(getHwBarometerStatus())) {
795 return OSD_MESSAGE_STR(OSD_MSG_BARO_FAIL
);
797 if (!HW_SENSOR_IS_HEALTHY(getHwGPSStatus())) {
798 return OSD_MESSAGE_STR(OSD_MSG_GPS_FAIL
);
800 if (!HW_SENSOR_IS_HEALTHY(getHwRangefinderStatus())) {
801 return OSD_MESSAGE_STR(OSD_MSG_RANGEFINDER_FAIL
);
803 if (!HW_SENSOR_IS_HEALTHY(getHwPitotmeterStatus())) {
804 return OSD_MESSAGE_STR(OSD_MSG_PITOT_FAIL
);
807 return OSD_MESSAGE_STR(OSD_MSG_HW_FAIL
);
808 case ARMING_DISABLED_BOXFAILSAFE
:
809 return OSD_MESSAGE_STR(OSD_MSG_FS_EN
);
810 case ARMING_DISABLED_BOXKILLSWITCH
:
811 return OSD_MESSAGE_STR(OSD_MSG_KILL_SW_EN
);
812 case ARMING_DISABLED_RC_LINK
:
813 return OSD_MESSAGE_STR(OSD_MSG_NO_RC_LINK
);
814 case ARMING_DISABLED_THROTTLE
:
815 return OSD_MESSAGE_STR(OSD_MSG_THROTTLE_NOT_LOW
);
816 case ARMING_DISABLED_ROLLPITCH_NOT_CENTERED
:
817 return OSD_MESSAGE_STR(OSD_MSG_ROLLPITCH_OFFCENTER
);
818 case ARMING_DISABLED_SERVO_AUTOTRIM
:
819 return OSD_MESSAGE_STR(OSD_MSG_AUTOTRIM_ACTIVE
);
820 case ARMING_DISABLED_OOM
:
821 return OSD_MESSAGE_STR(OSD_MSG_NOT_ENOUGH_MEMORY
);
822 case ARMING_DISABLED_INVALID_SETTING
:
823 return OSD_MESSAGE_STR(OSD_MSG_INVALID_SETTING
);
824 case ARMING_DISABLED_CLI
:
825 return OSD_MESSAGE_STR(OSD_MSG_CLI_ACTIVE
);
826 case ARMING_DISABLED_PWM_OUTPUT_ERROR
:
827 return OSD_MESSAGE_STR(OSD_MSG_PWM_INIT_ERROR
);
828 case ARMING_DISABLED_NO_PREARM
:
829 return OSD_MESSAGE_STR(OSD_MSG_NO_PREARM
);
830 case ARMING_DISABLED_DSHOT_BEEPER
:
831 return OSD_MESSAGE_STR(OSD_MSG_DSHOT_BEEPER
);
832 // Cases without message
833 case ARMING_DISABLED_CMS_MENU
:
835 case ARMING_DISABLED_OSD_MENU
:
837 case ARMING_DISABLED_ALL_FLAGS
:
847 static const char * osdFailsafePhaseMessage(void)
849 // See failsafe.h for each phase explanation
850 switch (failsafePhase()) {
851 case FAILSAFE_RETURN_TO_HOME
:
852 // XXX: Keep this in sync with OSD_FLYMODE.
853 return OSD_MESSAGE_STR(OSD_MSG_RTH_FS
);
854 case FAILSAFE_LANDING
:
855 // This should be considered an emergengy landing
856 return OSD_MESSAGE_STR(OSD_MSG_EMERG_LANDING_FS
);
857 case FAILSAFE_RX_LOSS_MONITORING
:
858 // Only reachable from FAILSAFE_LANDED, which performs
859 // a disarm. Since aircraft has been disarmed, we no
860 // longer show failsafe details.
862 case FAILSAFE_LANDED
:
863 // Very brief, disarms and transitions into
864 // FAILSAFE_RX_LOSS_MONITORING. Note that it prevents
865 // further rearming via ARMING_DISABLED_FAILSAFE_SYSTEM,
866 // so we'll show the user how to re-arm in when
867 // that flag is the reason to prevent arming.
869 case FAILSAFE_RX_LOSS_IDLE
:
870 // This only happens when user has chosen NONE as FS
871 // procedure. The recovery messages should be enough.
874 // Failsafe not active
876 case FAILSAFE_RX_LOSS_DETECTED
:
877 // Very brief, changes to FAILSAFE_RX_LOSS_RECOVERED
878 // or the FS procedure immediately.
880 case FAILSAFE_RX_LOSS_RECOVERED
:
887 static const char * osdFailsafeInfoMessage(void)
889 if (failsafeIsReceivingRxData()) {
890 // User must move sticks to exit FS mode
891 return OSD_MESSAGE_STR(OSD_MSG_MOVE_EXIT_FS
);
893 return OSD_MESSAGE_STR(OSD_MSG_RC_RX_LINK_LOST
);
895 #if defined(USE_SAFE_HOME)
896 static const char * divertingToSafehomeMessage(void)
898 if (NAV_Status
.state
!= MW_NAV_STATE_HOVER_ABOVE_HOME
&& safehome_applied
) {
899 return OSD_MESSAGE_STR(OSD_MSG_DIVERT_SAFEHOME
);
905 static const char * navigationStateMessage(void)
907 switch (NAV_Status
.state
) {
908 case MW_NAV_STATE_NONE
:
910 case MW_NAV_STATE_RTH_START
:
911 return OSD_MESSAGE_STR(OSD_MSG_STARTING_RTH
);
912 case MW_NAV_STATE_RTH_CLIMB
:
913 return OSD_MESSAGE_STR(OSD_MSG_RTH_CLIMB
);
914 case MW_NAV_STATE_RTH_ENROUTE
:
915 return OSD_MESSAGE_STR(OSD_MSG_HEADING_HOME
);
916 case MW_NAV_STATE_HOLD_INFINIT
:
917 // Used by HOLD flight modes. No information to add.
919 case MW_NAV_STATE_HOLD_TIMED
:
920 // "HOLDING WP FOR xx S" Countdown added in osdGetSystemMessage
922 case MW_NAV_STATE_WP_ENROUTE
:
923 // "TO WP" + WP countdown added in osdGetSystemMessage
925 case MW_NAV_STATE_PROCESS_NEXT
:
926 return OSD_MESSAGE_STR(OSD_MSG_PREPARE_NEXT_WP
);
927 case MW_NAV_STATE_DO_JUMP
:
930 case MW_NAV_STATE_LAND_START
:
933 case MW_NAV_STATE_EMERGENCY_LANDING
:
934 return OSD_MESSAGE_STR(OSD_MSG_EMERG_LANDING
);
935 case MW_NAV_STATE_LAND_IN_PROGRESS
:
936 return OSD_MESSAGE_STR(OSD_MSG_LANDING
);
937 case MW_NAV_STATE_HOVER_ABOVE_HOME
:
938 if (STATE(FIXED_WING_LEGACY
)) {
939 #if defined(USE_SAFE_HOME)
940 if (safehome_applied
) {
941 return OSD_MESSAGE_STR(OSD_MSG_LOITERING_SAFEHOME
);
944 return OSD_MESSAGE_STR(OSD_MSG_LOITERING_HOME
);
946 return OSD_MESSAGE_STR(OSD_MSG_HOVERING
);
947 case MW_NAV_STATE_LANDED
:
948 return OSD_MESSAGE_STR(OSD_MSG_LANDED
);
949 case MW_NAV_STATE_LAND_SETTLE
:
950 return OSD_MESSAGE_STR(OSD_MSG_PREPARING_LAND
);
951 case MW_NAV_STATE_LAND_START_DESCENT
:
958 static void osdFormatMessage(char *buff
, size_t size
, const char *message
, bool isCenteredText
)
960 // String is always filled with Blanks
961 memset(buff
, SYM_BLANK
, size
);
963 size_t messageLength
= strlen(message
);
964 int rem
= isCenteredText
? MAX(0, (int)size
- (int)messageLength
) : 0;
965 strncpy(buff
+ rem
/ 2, message
, MIN((int)size
- rem
/ 2, (int)messageLength
));
967 // Ensure buff is zero terminated
968 buff
[size
- 1] = '\0';
972 * Draws the battery symbol filled in accordingly to the
973 * battery voltage to buff[0].
975 static void osdFormatBatteryChargeSymbol(char *buff
)
977 uint8_t p
= calculateBatteryPercentage();
978 p
= (100 - p
) / 16.6;
979 buff
[0] = SYM_BATT_FULL
+ p
;
982 static void osdUpdateBatteryCapacityOrVoltageTextAttributes(textAttributes_t
*attr
)
984 if ((getBatteryState() != BATTERY_NOT_PRESENT
) && ((batteryUsesCapacityThresholds() && (getBatteryRemainingCapacity() <= currentBatteryProfile
->capacity
.warning
- currentBatteryProfile
->capacity
.critical
)) || ((!batteryUsesCapacityThresholds()) && (getBatteryVoltage() <= getBatteryWarningVoltage()))))
985 TEXT_ATTRIBUTES_ADD_BLINK(*attr
);
988 void osdCrosshairPosition(uint8_t *x
, uint8_t *y
)
990 *x
= osdDisplayPort
->cols
/ 2;
991 *y
= osdDisplayPort
->rows
/ 2;
992 *y
+= osdConfig()->horizon_offset
;
996 * Formats throttle position prefixed by its symbol.
997 * Shows output to motor, not stick position
999 static void osdFormatThrottlePosition(char *buff
, bool autoThr
, textAttributes_t
*elemAttr
)
1001 buff
[0] = SYM_BLANK
;
1003 if (autoThr
&& navigationIsControllingThrottle()) {
1004 buff
[0] = SYM_AUTO_THR0
;
1005 buff
[1] = SYM_AUTO_THR1
;
1006 if (isFixedWingAutoThrottleManuallyIncreased()) {
1007 TEXT_ATTRIBUTES_ADD_BLINK(*elemAttr
);
1010 #ifdef USE_POWER_LIMITS
1011 if (powerLimiterIsLimiting()) {
1012 TEXT_ATTRIBUTES_ADD_BLINK(*elemAttr
);
1015 tfp_sprintf(buff
+ 2, "%3d", getThrottlePercent());
1019 * Formats gvars prefixed by its number (0-indexed). If autoThr
1021 static void osdFormatGVar(char *buff
, uint8_t index
)
1024 buff
[1] = '0'+index
;
1026 #ifdef USE_PROGRAMMING_FRAMEWORK
1027 osdFormatCentiNumber(buff
+ 3, (int32_t)gvGet(index
)*(int32_t)100, 1, 0, 0, 5);
1031 #if defined(USE_ESC_SENSOR)
1032 static void osdFormatRpm(char *buff
, uint32_t rpm
)
1036 if ( digitCount(rpm
) > osdConfig()->esc_rpm_precision
) {
1037 uint8_t rpmMaxDecimals
= (osdConfig()->esc_rpm_precision
- 3);
1038 osdFormatCentiNumber(buff
+ 1, rpm
/ 10, 0, rpmMaxDecimals
, rpmMaxDecimals
, osdConfig()->esc_rpm_precision
-1);
1039 buff
[osdConfig()->esc_rpm_precision
] = 'K';
1040 buff
[osdConfig()->esc_rpm_precision
+1] = '\0';
1043 switch(osdConfig()->esc_rpm_precision
) {
1045 tfp_sprintf(buff
+ 1, "%6lu", rpm
);
1048 tfp_sprintf(buff
+ 1, "%5lu", rpm
);
1051 tfp_sprintf(buff
+ 1, "%4lu", rpm
);
1055 tfp_sprintf(buff
+ 1, "%3lu", rpm
);
1063 uint8_t buffPos
= 1;
1064 while (buffPos
<=( osdConfig()->esc_rpm_precision
)) {
1065 strcpy(buff
+ buffPos
++, "-");
1071 int32_t osdGetAltitude(void)
1073 return getEstimatedActualPosition(Z
);
1076 static inline int32_t osdGetAltitudeMsl(void)
1078 return getEstimatedActualPosition(Z
)+GPS_home
.alt
;
1081 static bool osdIsHeadingValid(void)
1083 #ifdef USE_SECONDARY_IMU
1084 if (secondaryImuState
.active
&& secondaryImuConfig()->useForOsdHeading
) {
1087 return isImuHeadingValid();
1090 return isImuHeadingValid();
1094 int16_t osdGetHeading(void)
1096 #ifdef USE_SECONDARY_IMU
1097 if (secondaryImuState
.active
&& secondaryImuConfig()->useForOsdHeading
) {
1098 return secondaryImuState
.eulerAngles
.values
.yaw
;
1100 return attitude
.values
.yaw
;
1103 return attitude
.values
.yaw
;
1107 int16_t osdPanServoHomeDirectionOffset(void)
1109 int8_t servoIndex
= osdConfig()->pan_servo_index
;
1110 int16_t servoPosition
= servo
[servoIndex
];
1111 int16_t servoMiddle
= servoParams(servoIndex
)->middle
;
1112 return (int16_t)CENTIDEGREES_TO_DEGREES((servoPosition
- servoMiddle
) * osdConfig()->pan_servo_pwm2centideg
);
1115 // Returns a heading angle in degrees normalized to [0, 360).
1116 int osdGetHeadingAngle(int angle
)
1121 while (angle
>= 360) {
1127 #if defined(USE_GPS)
1129 /* Draws a map with the given symbol in the center and given point of interest
1130 * defined by its distance in meters and direction in degrees.
1131 * referenceHeading indicates the up direction in the map, in degrees, while
1132 * referenceSym (if non-zero) is drawn at the upper right corner below a small
1133 * arrow to indicate the map reference to the user. The drawn argument is an
1134 * in-out used to store the last position where the craft was drawn to avoid
1135 * erasing all screen on each redraw.
1137 static void osdDrawMap(int referenceHeading
, uint16_t referenceSym
, uint16_t centerSym
,
1138 uint32_t poiDistance
, int16_t poiDirection
, uint16_t poiSymbol
,
1139 uint16_t *drawn
, uint32_t *usedScale
)
1141 // TODO: These need to be tested with several setups. We might
1142 // need to make them configurable.
1143 const int hMargin
= 5;
1144 const int vMargin
= 3;
1146 // TODO: Get this from the display driver?
1147 const int charWidth
= 12;
1148 const int charHeight
= 18;
1150 uint8_t minX
= hMargin
;
1151 uint8_t maxX
= osdDisplayPort
->cols
- 1 - hMargin
;
1152 uint8_t minY
= vMargin
;
1153 uint8_t maxY
= osdDisplayPort
->rows
- 1 - vMargin
;
1154 uint8_t midX
= osdDisplayPort
->cols
/ 2;
1155 uint8_t midY
= osdDisplayPort
->rows
/ 2;
1158 displayWriteChar(osdDisplayPort
, midX
, midY
, centerSym
);
1160 // First, erase the previous drawing.
1161 if (OSD_VISIBLE(*drawn
)) {
1162 displayWriteChar(osdDisplayPort
, OSD_X(*drawn
), OSD_Y(*drawn
), SYM_BLANK
);
1166 uint32_t initialScale
;
1167 const unsigned scaleMultiplier
= 2;
1168 // We try to reduce the scale when the POI will be around half the distance
1169 // between the center and the closers map edge, to avoid too much jumping
1170 const int scaleReductionMultiplier
= MIN(midX
- hMargin
, midY
- vMargin
) / 2;
1172 switch (osdConfig()->units
) {
1175 case OSD_UNIT_IMPERIAL
:
1176 initialScale
= 16; // 16m ~= 0.01miles
1179 initialScale
= 18; // 18m ~= 0.01 nautical miles
1182 case OSD_UNIT_METRIC_MPH
:
1184 case OSD_UNIT_METRIC
:
1185 initialScale
= 10; // 10m as initial scale
1189 // Try to keep the same scale when getting closer until we draw over the center point
1190 uint32_t scale
= initialScale
;
1193 if (scale
> initialScale
&& poiDistance
< *usedScale
* scaleReductionMultiplier
) {
1194 scale
/= scaleMultiplier
;
1198 if (STATE(GPS_FIX
)) {
1200 int directionToPoi
= osdGetHeadingAngle(poiDirection
- referenceHeading
);
1201 float poiAngle
= DEGREES_TO_RADIANS(directionToPoi
);
1202 float poiSin
= sin_approx(poiAngle
);
1203 float poiCos
= cos_approx(poiAngle
);
1205 // Now start looking for a valid scale that lets us draw everything
1207 for (ii
= 0; ii
< 50; ii
++) {
1208 // Calculate location of the aircraft in map
1209 int points
= poiDistance
/ ((float)scale
/ charHeight
);
1211 float pointsX
= points
* poiSin
;
1212 int poiX
= midX
- roundf(pointsX
/ charWidth
);
1213 if (poiX
< minX
|| poiX
> maxX
) {
1214 scale
*= scaleMultiplier
;
1218 float pointsY
= points
* poiCos
;
1219 int poiY
= midY
+ roundf(pointsY
/ charHeight
);
1220 if (poiY
< minY
|| poiY
> maxY
) {
1221 scale
*= scaleMultiplier
;
1225 if (poiX
== midX
&& poiY
== midY
) {
1226 // We're over the map center symbol, so we would be drawing
1227 // over it even if we increased the scale. Alternate between
1228 // drawing the center symbol or drawing the POI.
1229 if (centerSym
!= SYM_BLANK
&& OSD_ALTERNATING_CHOICES(1000, 2) == 0) {
1235 if (displayReadCharWithAttr(osdDisplayPort
, poiX
, poiY
, &c
, NULL
) && c
!= SYM_BLANK
) {
1236 // Something else written here, increase scale. If the display doesn't support reading
1237 // back characters, we assume there's nothing.
1239 // If we're close to the center, decrease scale. Otherwise increase it.
1240 uint8_t centerDeltaX
= (maxX
- minX
) / (scaleMultiplier
* 2);
1241 uint8_t centerDeltaY
= (maxY
- minY
) / (scaleMultiplier
* 2);
1242 if (poiX
>= midX
- centerDeltaX
&& poiX
<= midX
+ centerDeltaX
&&
1243 poiY
>= midY
- centerDeltaY
&& poiY
<= midY
+ centerDeltaY
&&
1244 scale
> scaleMultiplier
) {
1246 scale
/= scaleMultiplier
;
1248 scale
*= scaleMultiplier
;
1254 // Draw the point on the map
1255 if (poiSymbol
== SYM_ARROW_UP
) {
1256 // Drawing aircraft, rotate
1257 int mapHeading
= osdGetHeadingAngle(DECIDEGREES_TO_DEGREES(osdGetHeading()) - referenceHeading
);
1258 poiSymbol
+= mapHeading
* 2 / 45;
1260 displayWriteChar(osdDisplayPort
, poiX
, poiY
, poiSymbol
);
1262 // Update saved location
1263 *drawn
= OSD_POS(poiX
, poiY
) | OSD_VISIBLE_FLAG
;
1270 // Update global map data for scale and reference
1271 osdMapData
.scale
= scale
;
1272 osdMapData
.referenceSymbol
= referenceSym
;
1275 /* Draws a map with the home in the center and the craft moving around.
1276 * See osdDrawMap() for reference.
1278 static void osdDrawHomeMap(int referenceHeading
, uint8_t referenceSym
, uint16_t *drawn
, uint32_t *usedScale
)
1280 osdDrawMap(referenceHeading
, referenceSym
, SYM_HOME
, GPS_distanceToHome
, GPS_directionToHome
, SYM_ARROW_UP
, drawn
, usedScale
);
1283 /* Draws a map with the aircraft in the center and the home moving around.
1284 * See osdDrawMap() for reference.
1286 static void osdDrawRadar(uint16_t *drawn
, uint32_t *usedScale
)
1288 int16_t reference
= DECIDEGREES_TO_DEGREES(osdGetHeading());
1289 int16_t poiDirection
= osdGetHeadingAngle(GPS_directionToHome
+ 180);
1290 osdDrawMap(reference
, 0, SYM_ARROW_UP
, GPS_distanceToHome
, poiDirection
, SYM_HOME
, drawn
, usedScale
);
1293 static uint16_t crc_accumulate(uint8_t data
, uint16_t crcAccum
)
1296 tmp
= data
^ (uint8_t)(crcAccum
& 0xff);
1298 crcAccum
= (crcAccum
>> 8) ^ (tmp
<< 8) ^ (tmp
<< 3) ^ (tmp
>> 4);
1303 static void osdDisplayTelemetry(void)
1306 uint16_t trk_crc
= 0;
1307 char trk_buffer
[31];
1308 static int16_t trk_elevation
= 127;
1309 static uint16_t trk_bearing
= 0;
1311 if (ARMING_FLAG(ARMED
)) {
1312 if (STATE(GPS_FIX
)){
1313 if (GPS_distanceToHome
> 5) {
1314 trk_bearing
= GPS_directionToHome
;
1315 trk_bearing
+= 360 + 180;
1317 int32_t alt
= CENTIMETERS_TO_METERS(osdGetAltitude());
1318 float at
= atan2(alt
, GPS_distanceToHome
);
1319 trk_elevation
= (float)at
* 57.2957795; // 57.2957795 = 1 rad
1320 trk_elevation
+= 37; // because elevation in telemetry should be from -37 to 90
1321 if (trk_elevation
< 0) {
1328 trk_elevation
= 127;
1332 trk_data
= 0; // bit 0 - packet type 0 = bearing/elevation, 1 = 2 byte data packet
1333 trk_data
= trk_data
| (uint32_t)(0x7F & trk_elevation
) << 1; // bits 1-7 - elevation angle to target. NOTE number is abused. constrained value of -37 to 90 sent as 0 to 127.
1334 trk_data
= trk_data
| (uint32_t)trk_bearing
<< 8; // bits 8-17 - bearing angle to target. 0 = true north. 0 to 360
1335 trk_crc
= crc_accumulate(0xFF & trk_data
, trk_crc
); // CRC First Byte bits 0-7
1336 trk_crc
= crc_accumulate(0xFF & trk_bearing
, trk_crc
); // CRC Second Byte bits 8-15
1337 trk_crc
= crc_accumulate(trk_bearing
>> 8, trk_crc
); // CRC Third Byte bits 16-17
1338 trk_data
= trk_data
| (uint32_t)trk_crc
<< 17; // bits 18-29 CRC & 0x3FFFF
1340 for (uint8_t t_ctr
= 0; t_ctr
< 30; t_ctr
++) { // Prepare screen buffer and write data line.
1341 if (trk_data
& (uint32_t)1 << t_ctr
){
1342 trk_buffer
[29 - t_ctr
] = SYM_TELEMETRY_0
;
1345 trk_buffer
[29 - t_ctr
] = SYM_TELEMETRY_1
;
1349 displayWrite(osdDisplayPort
, 0, 0, trk_buffer
);
1350 if (osdConfig()->telemetry
>1){
1351 displayWrite(osdDisplayPort
, 0, 3, trk_buffer
); // Test display because normal telemetry line is not visible
1356 static void osdFormatPidControllerOutput(char *buff
, const char *label
, const pidController_t
*pidController
, uint8_t scale
, bool showDecimal
) {
1357 strcpy(buff
, label
);
1358 for (uint8_t i
= strlen(label
); i
< 5; ++i
) buff
[i
] = ' ';
1359 uint8_t decimals
= showDecimal
? 1 : 0;
1360 osdFormatCentiNumber(buff
+ 5, pidController
->proportional
* scale
, 0, decimals
, 0, 4);
1362 osdFormatCentiNumber(buff
+ 10, pidController
->integrator
* scale
, 0, decimals
, 0, 4);
1364 osdFormatCentiNumber(buff
+ 15, pidController
->derivative
* scale
, 0, decimals
, 0, 4);
1366 osdFormatCentiNumber(buff
+ 20, pidController
->output_constrained
* scale
, 0, decimals
, 0, 4);
1370 static void osdDisplayBatteryVoltage(uint8_t elemPosX
, uint8_t elemPosY
, uint16_t voltage
, uint8_t digits
, uint8_t decimals
)
1373 textAttributes_t elemAttr
= TEXT_ATTRIBUTES_NONE
;
1375 osdFormatBatteryChargeSymbol(buff
);
1377 osdUpdateBatteryCapacityOrVoltageTextAttributes(&elemAttr
);
1378 displayWriteWithAttr(osdDisplayPort
, elemPosX
, elemPosY
, buff
, elemAttr
);
1380 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1381 digits
= MIN(digits
, 4);
1382 osdFormatCentiNumber(buff
, voltage
, 0, decimals
, 0, digits
);
1383 buff
[digits
] = SYM_VOLT
;
1384 buff
[digits
+1] = '\0';
1385 if ((getBatteryState() != BATTERY_NOT_PRESENT
) && (getBatteryVoltage() <= getBatteryWarningVoltage()))
1386 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1387 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 1, elemPosY
, buff
, elemAttr
);
1390 static void osdDisplayFlightPIDValues(uint8_t elemPosX
, uint8_t elemPosY
, const char *str
, pidIndex_e pidIndex
, adjustmentFunction_e adjFuncP
, adjustmentFunction_e adjFuncI
, adjustmentFunction_e adjFuncD
, adjustmentFunction_e adjFuncFF
)
1392 textAttributes_t elemAttr
;
1395 const pid8_t
*pid
= &pidBank()->pid
[pidIndex
];
1396 pidType_e pidType
= pidIndexGetType(pidIndex
);
1398 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, str
);
1400 if (pidType
== PID_TYPE_NONE
) {
1401 // PID is not used in this configuration. Draw dashes.
1402 // XXX: Keep this in sync with the %3d format and spacing used below
1403 displayWrite(osdDisplayPort
, elemPosX
+ 6, elemPosY
, "- - - -");
1407 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1408 tfp_sprintf(buff
, "%3d", pid
->P
);
1409 if ((isAdjustmentFunctionSelected(adjFuncP
)) || (((adjFuncP
== ADJUSTMENT_ROLL_P
) || (adjFuncP
== ADJUSTMENT_PITCH_P
)) && (isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_P
))))
1410 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1411 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 4, elemPosY
, buff
, elemAttr
);
1413 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1414 tfp_sprintf(buff
, "%3d", pid
->I
);
1415 if ((isAdjustmentFunctionSelected(adjFuncI
)) || (((adjFuncI
== ADJUSTMENT_ROLL_I
) || (adjFuncI
== ADJUSTMENT_PITCH_I
)) && (isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_I
))))
1416 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1417 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 8, elemPosY
, buff
, elemAttr
);
1419 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1420 tfp_sprintf(buff
, "%3d", pid
->D
);
1421 if ((isAdjustmentFunctionSelected(adjFuncD
)) || (((adjFuncD
== ADJUSTMENT_ROLL_D
) || (adjFuncD
== ADJUSTMENT_PITCH_D
)) && (isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_D
))))
1422 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1423 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 12, elemPosY
, buff
, elemAttr
);
1425 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1426 tfp_sprintf(buff
, "%3d", pid
->FF
);
1427 if ((isAdjustmentFunctionSelected(adjFuncFF
)) || (((adjFuncFF
== ADJUSTMENT_ROLL_FF
) || (adjFuncFF
== ADJUSTMENT_PITCH_FF
)) && (isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_FF
))))
1428 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1429 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 16, elemPosY
, buff
, elemAttr
);
1432 static void osdDisplayNavPIDValues(uint8_t elemPosX
, uint8_t elemPosY
, const char *str
, pidIndex_e pidIndex
, adjustmentFunction_e adjFuncP
, adjustmentFunction_e adjFuncI
, adjustmentFunction_e adjFuncD
)
1434 textAttributes_t elemAttr
;
1437 const pid8_t
*pid
= &pidBank()->pid
[pidIndex
];
1438 pidType_e pidType
= pidIndexGetType(pidIndex
);
1440 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, str
);
1442 if (pidType
== PID_TYPE_NONE
) {
1443 // PID is not used in this configuration. Draw dashes.
1444 // XXX: Keep this in sync with the %3d format and spacing used below
1445 displayWrite(osdDisplayPort
, elemPosX
+ 6, elemPosY
, "- - -");
1449 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1450 tfp_sprintf(buff
, "%3d", pid
->P
);
1451 if ((isAdjustmentFunctionSelected(adjFuncP
)) || (((adjFuncP
== ADJUSTMENT_ROLL_P
) || (adjFuncP
== ADJUSTMENT_PITCH_P
)) && (isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_P
))))
1452 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1453 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 4, elemPosY
, buff
, elemAttr
);
1455 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1456 tfp_sprintf(buff
, "%3d", pid
->I
);
1457 if ((isAdjustmentFunctionSelected(adjFuncI
)) || (((adjFuncI
== ADJUSTMENT_ROLL_I
) || (adjFuncI
== ADJUSTMENT_PITCH_I
)) && (isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_I
))))
1458 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1459 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 8, elemPosY
, buff
, elemAttr
);
1461 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1462 tfp_sprintf(buff
, "%3d", pidType
== PID_TYPE_PIFF
? pid
->FF
: pid
->D
);
1463 if ((isAdjustmentFunctionSelected(adjFuncD
)) || (((adjFuncD
== ADJUSTMENT_ROLL_D
) || (adjFuncD
== ADJUSTMENT_PITCH_D
)) && (isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_D
))))
1464 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1465 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 12, elemPosY
, buff
, elemAttr
);
1468 static void osdDisplayAdjustableDecimalValue(uint8_t elemPosX
, uint8_t elemPosY
, const char *str
, const uint8_t valueOffset
, const float value
, const uint8_t valueLength
, const uint8_t maxDecimals
, adjustmentFunction_e adjFunc
) {
1470 textAttributes_t elemAttr
;
1471 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, str
);
1473 elemAttr
= TEXT_ATTRIBUTES_NONE
;
1474 osdFormatCentiNumber(buff
, value
* 100, 0, maxDecimals
, 0, MIN(valueLength
, 8));
1475 if (isAdjustmentFunctionSelected(adjFunc
))
1476 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1477 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ strlen(str
) + 1 + valueOffset
, elemPosY
, buff
, elemAttr
);
1480 int8_t getGeoWaypointNumber(int8_t waypointIndex
)
1482 static int8_t lastWaypointIndex
= 1;
1483 static int8_t geoWaypointIndex
;
1485 if (waypointIndex
!= lastWaypointIndex
) {
1486 lastWaypointIndex
= geoWaypointIndex
= waypointIndex
;
1487 for (uint8_t i
= 0; i
<= waypointIndex
; i
++) {
1488 if (posControl
.waypointList
[i
].action
== NAV_WP_ACTION_SET_POI
||
1489 posControl
.waypointList
[i
].action
== NAV_WP_ACTION_SET_HEAD
||
1490 posControl
.waypointList
[i
].action
== NAV_WP_ACTION_JUMP
) {
1491 geoWaypointIndex
-= 1;
1496 return geoWaypointIndex
+ 1;
1499 void osdDisplaySwitchIndicator(const char *swName
, int rcValue
, char *buff
) {
1500 int8_t charRemainder
= OSD_SWITCH_INDICATOR_NAME_LENGTH
;
1503 for (ptr
= strlen(swName
); ptr
> 0; ptr
--) {
1504 buff
[--charRemainder
] = swName
[ptr
-1];
1507 if (charRemainder
> 0) {
1508 for (ptr
= 0; ptr
< charRemainder
; ptr
++) {
1509 buff
[ptr
] = SYM_BLANK
;
1513 if ( rcValue
< 1333) {
1514 buff
[OSD_SWITCH_INDICATOR_NAME_LENGTH
] = SYM_SWITCH_INDICATOR_LOW
;
1515 } else if ( rcValue
> 1666) {
1516 buff
[OSD_SWITCH_INDICATOR_NAME_LENGTH
] = SYM_SWITCH_INDICATOR_HIGH
;
1518 buff
[OSD_SWITCH_INDICATOR_NAME_LENGTH
] = SYM_SWITCH_INDICATOR_MID
;
1521 buff
[OSD_SWITCH_INDICATOR_NAME_LENGTH
+ 1] = '\0';
1524 static bool osdDrawSingleElement(uint8_t item
)
1526 uint16_t pos
= osdLayoutsConfig()->item_pos
[currentLayout
][item
];
1527 if (!OSD_VISIBLE(pos
)) {
1530 uint8_t elemPosX
= OSD_X(pos
);
1531 uint8_t elemPosY
= OSD_Y(pos
);
1532 textAttributes_t elemAttr
= TEXT_ATTRIBUTES_NONE
;
1533 char buff
[32] = {0};
1536 case OSD_RSSI_VALUE
:
1538 uint16_t osdRssi
= osdConvertRSSI();
1540 tfp_sprintf(buff
+ 1, "%2d", osdRssi
);
1541 if (osdRssi
< osdConfig()->rssi_alarm
) {
1542 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1547 case OSD_MAIN_BATT_VOLTAGE
:
1548 osdDisplayBatteryVoltage(elemPosX
, elemPosY
, getBatteryRawVoltage(), 2 + osdConfig()->main_voltage_decimals
, osdConfig()->main_voltage_decimals
);
1551 case OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE
:
1552 osdDisplayBatteryVoltage(elemPosX
, elemPosY
, getBatterySagCompensatedVoltage(), 2 + osdConfig()->main_voltage_decimals
, osdConfig()->main_voltage_decimals
);
1555 case OSD_CURRENT_DRAW
:
1556 osdFormatCentiNumber(buff
, getAmperage(), 0, 2, 0, 3);
1560 uint8_t current_alarm
= osdConfig()->current_alarm
;
1561 if ((current_alarm
> 0) && ((getAmperage() / 100.0f
) > current_alarm
)) {
1562 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1567 tfp_sprintf(buff
, "%4d", (int)getMAhDrawn());
1570 osdUpdateBatteryCapacityOrVoltageTextAttributes(&elemAttr
);
1574 osdFormatCentiNumber(buff
, getMWhDrawn() / 10, 0, 2, 0, 3);
1575 osdUpdateBatteryCapacityOrVoltageTextAttributes(&elemAttr
);
1580 case OSD_BATTERY_REMAINING_CAPACITY
:
1582 if (currentBatteryProfile
->capacity
.value
== 0)
1583 tfp_sprintf(buff
, " NA");
1584 else if (!batteryWasFullWhenPluggedIn())
1585 tfp_sprintf(buff
, " NF");
1586 else if (currentBatteryProfile
->capacity
.unit
== BAT_CAPACITY_UNIT_MAH
)
1587 tfp_sprintf(buff
, "%4lu", getBatteryRemainingCapacity());
1588 else // currentBatteryProfile->capacity.unit == BAT_CAPACITY_UNIT_MWH
1589 osdFormatCentiNumber(buff
+ 1, getBatteryRemainingCapacity() / 10, 0, 2, 0, 3);
1591 buff
[4] = currentBatteryProfile
->capacity
.unit
== BAT_CAPACITY_UNIT_MAH
? SYM_MAH
: SYM_WH
;
1594 if ((getBatteryState() != BATTERY_NOT_PRESENT
) && batteryUsesCapacityThresholds() && (getBatteryRemainingCapacity() <= currentBatteryProfile
->capacity
.warning
- currentBatteryProfile
->capacity
.critical
))
1595 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1599 case OSD_BATTERY_REMAINING_PERCENT
:
1600 osdFormatBatteryChargeSymbol(buff
);
1601 tfp_sprintf(buff
+ 1, "%3d%%", calculateBatteryPercentage());
1602 osdUpdateBatteryCapacityOrVoltageTextAttributes(&elemAttr
);
1605 case OSD_POWER_SUPPLY_IMPEDANCE
:
1606 if (isPowerSupplyImpedanceValid())
1607 tfp_sprintf(buff
, "%3d", getPowerSupplyImpedance());
1609 strcpy(buff
, "---");
1610 buff
[3] = SYM_MILLIOHM
;
1616 buff
[0] = SYM_SAT_L
;
1617 buff
[1] = SYM_SAT_R
;
1618 tfp_sprintf(buff
+ 2, "%2d", gpsSol
.numSat
);
1619 if (!STATE(GPS_FIX
)) {
1620 if (getHwGPSStatus() == HW_SENSOR_UNAVAILABLE
|| getHwGPSStatus() == HW_SENSOR_UNHEALTHY
) {
1621 strcpy(buff
+ 2, "X!");
1623 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1628 osdFormatVelocityStr(buff
, gpsSol
.groundSpeed
, false, false);
1631 case OSD_GPS_MAX_SPEED
:
1632 osdFormatVelocityStr(buff
, stats
.max_speed
, false, true);
1636 osdFormatVelocityStr(buff
, osdGet3DSpeed(), true, false);
1639 case OSD_3D_MAX_SPEED
:
1640 osdFormatVelocityStr(buff
, stats
.max_3D_speed
, true, true);
1643 case OSD_GLIDESLOPE
:
1645 float horizontalSpeed
= gpsSol
.groundSpeed
;
1646 float sinkRate
= -getEstimatedActualVelocity(Z
);
1647 static pt1Filter_t gsFilterState
;
1648 const timeMs_t currentTimeMs
= millis();
1649 static timeMs_t gsUpdatedTimeMs
;
1650 float glideSlope
= horizontalSpeed
/ sinkRate
;
1651 glideSlope
= pt1FilterApply4(&gsFilterState
, isnormal(glideSlope
) ? glideSlope
: 200, 0.5, MS2S(currentTimeMs
- gsUpdatedTimeMs
));
1652 gsUpdatedTimeMs
= currentTimeMs
;
1654 buff
[0] = SYM_GLIDESLOPE
;
1655 if (glideSlope
> 0.0f
&& glideSlope
< 100.0f
) {
1656 osdFormatCentiNumber(buff
+ 1, glideSlope
* 100.0f
, 0, 2, 0, 3);
1658 buff
[1] = buff
[2] = buff
[3] = '-';
1665 osdFormatCoordinate(buff
, SYM_LAT
, gpsSol
.llh
.lat
);
1669 osdFormatCoordinate(buff
, SYM_LON
, gpsSol
.llh
.lon
);
1674 if (STATE(GPS_FIX
) && STATE(GPS_FIX_HOME
) && isImuHeadingValid()) {
1675 if (GPS_distanceToHome
< (navConfig()->general
.min_rth_distance
/ 100) ) {
1676 displayWriteChar(osdDisplayPort
, elemPosX
, elemPosY
, SYM_HOME_NEAR
);
1680 int16_t panHomeDirOffset
= 0;
1681 if (!(osdConfig()->pan_servo_pwm2centideg
== 0)){
1682 panHomeDirOffset
= osdPanServoHomeDirectionOffset();
1684 int homeDirection
= GPS_directionToHome
- DECIDEGREES_TO_DEGREES(osdGetHeading()) + panHomeDirOffset
;
1685 osdDrawDirArrow(osdDisplayPort
, osdGetDisplayPortCanvas(), OSD_DRAW_POINT_GRID(elemPosX
, elemPosY
), homeDirection
);
1688 // No home or no fix or unknown heading, blink.
1689 // If we're unarmed, show the arrow pointing up so users can see the arrow
1690 // while configuring the OSD. If we're armed, show a '-' indicating that
1691 // we don't know the direction to home.
1692 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1693 displayWriteCharWithAttr(osdDisplayPort
, elemPosX
, elemPosY
, ARMING_FLAG(ARMED
) ? '-' : SYM_ARROW_UP
, elemAttr
);
1698 case OSD_HOME_HEADING_ERROR
:
1701 buff
[1] = SYM_HEADING
;
1703 if (isImuHeadingValid() && navigationPositionEstimateIsHealthy()) {
1704 int16_t h
= lrintf(CENTIDEGREES_TO_DEGREES((float)wrap_18000(DEGREES_TO_CENTIDEGREES((int32_t)GPS_directionToHome
) - DECIDEGREES_TO_CENTIDEGREES((int32_t)osdGetHeading()))));
1705 tfp_sprintf(buff
+ 2, "%4d", h
);
1707 strcpy(buff
+ 2, "----");
1710 buff
[6] = SYM_DEGREES
;
1718 osdFormatDistanceSymbol(&buff
[1], GPS_distanceToHome
* 100, 0);
1719 uint16_t dist_alarm
= osdConfig()->dist_alarm
;
1720 if (dist_alarm
> 0 && GPS_distanceToHome
> dist_alarm
) {
1721 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1727 buff
[0] = SYM_TOTAL
;
1728 osdFormatDistanceSymbol(buff
+ 1, getTotalTravelDistance(), 0);
1733 buff
[0] = SYM_HEADING
;
1734 if (osdIsHeadingValid()) {
1735 int16_t h
= DECIDEGREES_TO_DEGREES(osdGetHeading());
1739 tfp_sprintf(&buff
[1], "%3d", h
);
1741 buff
[1] = buff
[2] = buff
[3] = '-';
1743 buff
[4] = SYM_DEGREES
;
1748 case OSD_COURSE_HOLD_ERROR
:
1750 if (ARMING_FLAG(ARMED
) && !FLIGHT_MODE(NAV_COURSE_HOLD_MODE
)) {
1751 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, " ");
1755 buff
[0] = SYM_HEADING
;
1757 if ((!ARMING_FLAG(ARMED
)) || (FLIGHT_MODE(NAV_COURSE_HOLD_MODE
) && isAdjustingPosition())) {
1758 buff
[1] = buff
[2] = buff
[3] = '-';
1759 } else if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE
)) {
1760 int16_t herr
= lrintf(CENTIDEGREES_TO_DEGREES((float)navigationGetHeadingError()));
1762 strcpy(buff
+ 1, ">99");
1764 tfp_sprintf(buff
+ 1, "%3d", herr
);
1767 buff
[4] = SYM_DEGREES
;
1772 case OSD_COURSE_HOLD_ADJUSTMENT
:
1774 int16_t heading_adjust
= lrintf(CENTIDEGREES_TO_DEGREES((float)getCruiseHeadingAdjustment()));
1776 if (ARMING_FLAG(ARMED
) && ((!FLIGHT_MODE(NAV_COURSE_HOLD_MODE
)) || !(isAdjustingPosition() || isAdjustingHeading() || (heading_adjust
!= 0)))) {
1777 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, " ");
1781 buff
[0] = SYM_HEADING
;
1783 if (!ARMING_FLAG(ARMED
)) {
1784 buff
[1] = buff
[2] = buff
[3] = buff
[4] = '-';
1785 } else if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE
)) {
1786 tfp_sprintf(buff
+ 1, "%4d", heading_adjust
);
1789 buff
[5] = SYM_DEGREES
;
1796 buff
[0] = SYM_HDP_L
;
1797 buff
[1] = SYM_HDP_R
;
1798 int32_t centiHDOP
= 100 * gpsSol
.hdop
/ HDOP_SCALE
;
1799 osdFormatCentiNumber(&buff
[2], centiHDOP
, 0, 1, 0, 2);
1805 static uint16_t drawn
= 0;
1806 static uint32_t scale
= 0;
1807 osdDrawHomeMap(0, 'N', &drawn
, &scale
);
1810 case OSD_MAP_TAKEOFF
:
1812 static uint16_t drawn
= 0;
1813 static uint32_t scale
= 0;
1814 osdDrawHomeMap(CENTIDEGREES_TO_DEGREES(navigationGetHomeHeading()), 'T', &drawn
, &scale
);
1819 static uint16_t drawn
= 0;
1820 static uint32_t scale
= 0;
1821 osdDrawRadar(&drawn
, &scale
);
1828 int32_t alt
= osdGetAltitude();
1829 osdFormatAltitudeSymbol(buff
, alt
);
1830 uint16_t alt_alarm
= osdConfig()->alt_alarm
;
1831 uint16_t neg_alt_alarm
= osdConfig()->neg_alt_alarm
;
1832 if ((alt_alarm
> 0 && CENTIMETERS_TO_METERS(alt
) > alt_alarm
) ||
1833 (neg_alt_alarm
> 0 && alt
< 0 && -CENTIMETERS_TO_METERS(alt
) > neg_alt_alarm
)) {
1835 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1840 case OSD_ALTITUDE_MSL
:
1842 int32_t alt
= osdGetAltitudeMsl();
1843 osdFormatAltitudeSymbol(buff
, alt
);
1847 #ifdef USE_RANGEFINDER
1848 case OSD_RANGEFINDER
:
1850 int32_t range
= rangefinderGetLatestRawAltitude();
1854 osdFormatDistanceSymbol(buff
, range
, 1);
1862 osdFormatOnTime(buff
);
1868 osdFormatFlyTime(buff
, &elemAttr
);
1872 case OSD_ONTIME_FLYTIME
:
1874 if (ARMING_FLAG(ARMED
)) {
1875 osdFormatFlyTime(buff
, &elemAttr
);
1877 osdFormatOnTime(buff
);
1882 case OSD_REMAINING_FLIGHT_TIME_BEFORE_RTH
:
1884 /*static int32_t updatedTimeSeconds = 0;*/
1885 static int32_t timeSeconds
= -1;
1886 #if defined(USE_ADC) && defined(USE_GPS)
1887 static timeUs_t updatedTimestamp
= 0;
1888 timeUs_t currentTimeUs
= micros();
1889 if (cmpTimeUs(currentTimeUs
, updatedTimestamp
) >= MS2US(1000)) {
1890 #ifdef USE_WIND_ESTIMATOR
1891 timeSeconds
= calculateRemainingFlightTimeBeforeRTH(osdConfig()->estimations_wind_compensation
);
1893 timeSeconds
= calculateRemainingFlightTimeBeforeRTH(false);
1895 updatedTimestamp
= currentTimeUs
;
1898 if ((!ARMING_FLAG(ARMED
)) || (timeSeconds
== -1)) {
1899 buff
[0] = SYM_FLY_M
;
1900 strcpy(buff
+ 1, "--:--");
1901 #if defined(USE_ADC) && defined(USE_GPS)
1902 updatedTimestamp
= 0;
1904 } else if (timeSeconds
== -2) {
1905 // Wind is too strong to come back with cruise throttle
1906 buff
[0] = SYM_FLY_M
;
1907 buff
[1] = buff
[2] = buff
[4] = buff
[5] = SYM_WIND_HORIZONTAL
;
1910 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1912 osdFormatTime(buff
, timeSeconds
, SYM_FLY_M
, SYM_FLY_H
);
1913 if (timeSeconds
== 0)
1914 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1919 case OSD_REMAINING_DISTANCE_BEFORE_RTH
:;
1920 static int32_t distanceMeters
= -1;
1921 #if defined(USE_ADC) && defined(USE_GPS)
1922 static timeUs_t updatedTimestamp
= 0;
1923 timeUs_t currentTimeUs
= micros();
1924 if (cmpTimeUs(currentTimeUs
, updatedTimestamp
) >= MS2US(1000)) {
1925 #ifdef USE_WIND_ESTIMATOR
1926 distanceMeters
= calculateRemainingDistanceBeforeRTH(osdConfig()->estimations_wind_compensation
);
1928 distanceMeters
= calculateRemainingDistanceBeforeRTH(false);
1930 updatedTimestamp
= currentTimeUs
;
1933 buff
[0] = SYM_TRIP_DIST
;
1934 if ((!ARMING_FLAG(ARMED
)) || (distanceMeters
== -1)) {
1935 buff
[4] = SYM_BLANK
;
1937 strcpy(buff
+ 1, "---");
1938 } else if (distanceMeters
== -2) {
1939 // Wind is too strong to come back with cruise throttle
1940 buff
[1] = buff
[2] = buff
[3] = SYM_WIND_HORIZONTAL
;
1941 switch ((osd_unit_e
)osdConfig()->units
){
1944 case OSD_UNIT_IMPERIAL
:
1945 buff
[4] = SYM_DIST_MI
;
1947 case OSD_UNIT_METRIC_MPH
:
1949 case OSD_UNIT_METRIC
:
1950 buff
[4] = SYM_DIST_KM
;
1953 buff
[4] = SYM_DIST_NM
;
1957 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1959 osdFormatDistanceSymbol(buff
+ 1, distanceMeters
* 100, 0);
1960 if (distanceMeters
== 0)
1961 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
1969 if (FLIGHT_MODE(FAILSAFE_MODE
))
1971 else if (FLIGHT_MODE(MANUAL_MODE
))
1973 else if (FLIGHT_MODE(TURTLE_MODE
))
1975 else if (FLIGHT_MODE(NAV_RTH_MODE
))
1976 p
= isWaypointMissionRTHActive() ? "WRTH" : "RTH ";
1977 else if (FLIGHT_MODE(NAV_POSHOLD_MODE
))
1979 else if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE
) && FLIGHT_MODE(NAV_ALTHOLD_MODE
))
1981 else if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE
))
1983 else if (FLIGHT_MODE(NAV_WP_MODE
))
1985 else if (FLIGHT_MODE(NAV_ALTHOLD_MODE
) && navigationRequiresAngleMode()) {
1986 // If navigationRequiresAngleMode() returns false when ALTHOLD is active,
1987 // it means it can be combined with ANGLE, HORIZON, ACRO, etc...
1988 // and its display is handled by OSD_MESSAGES rather than OSD_FLYMODE.
1991 else if (FLIGHT_MODE(ANGLE_MODE
))
1993 else if (FLIGHT_MODE(HORIZON_MODE
))
1996 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, p
);
2000 case OSD_CRAFT_NAME
:
2001 osdFormatCraftName(buff
);
2004 case OSD_THROTTLE_POS
:
2006 osdFormatThrottlePosition(buff
, false, &elemAttr
);
2010 case OSD_VTX_CHANNEL
:
2012 vtxDeviceOsdInfo_t osdInfo
;
2013 vtxCommonGetOsdInfo(vtxCommonDevice(), &osdInfo
);
2015 tfp_sprintf(buff
, "CH:%c%s:", osdInfo
.bandLetter
, osdInfo
.channelName
);
2016 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, buff
);
2018 tfp_sprintf(buff
, "%c", osdInfo
.powerIndexLetter
);
2019 if (isAdjustmentFunctionSelected(ADJUSTMENT_VTX_POWER_LEVEL
)) TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2020 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 6, elemPosY
, buff
, elemAttr
);
2027 vtxDeviceOsdInfo_t osdInfo
;
2028 vtxCommonGetOsdInfo(vtxCommonDevice(), &osdInfo
);
2030 tfp_sprintf(buff
, "%c", SYM_VTX_POWER
);
2031 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, buff
);
2033 tfp_sprintf(buff
, "%c", osdInfo
.powerIndexLetter
);
2034 if (isAdjustmentFunctionSelected(ADJUSTMENT_VTX_POWER_LEVEL
)) TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2035 displayWriteWithAttr(osdDisplayPort
, elemPosX
+1, elemPosY
, buff
, elemAttr
);
2039 #if defined(USE_SERIALRX_CRSF)
2040 case OSD_CRSF_RSSI_DBM
:
2042 int16_t rssi
= rxLinkStatistics
.uplinkRSSI
;
2043 buff
[0] = (rxLinkStatistics
.activeAnt
== 0) ? SYM_RSSI
: SYM_2RSS
; // Separate symbols for each antenna
2045 tfp_sprintf(buff
+ 1, "%4d%c", rssi
, SYM_DBM
);
2047 tfp_sprintf(buff
+ 1, "%3d%c%c", rssi
, SYM_DBM
, ' ');
2049 if (!failsafeIsReceivingRxData()){
2050 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2051 } else if (osdConfig()->rssi_dbm_alarm
&& rssi
< osdConfig()->rssi_dbm_alarm
) {
2052 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2059 int16_t statsLQ
= rxLinkStatistics
.uplinkLQ
;
2060 int16_t scaledLQ
= scaleRange(constrain(statsLQ
, 0, 100), 0, 100, 170, 300);
2061 switch (osdConfig()->crsf_lq_format
) {
2062 case OSD_CRSF_LQ_TYPE1
:
2063 if (!failsafeIsReceivingRxData()) {
2064 tfp_sprintf(buff
+1, "%3d", 0);
2066 tfp_sprintf(buff
+1, "%3d", rxLinkStatistics
.uplinkLQ
);
2069 case OSD_CRSF_LQ_TYPE2
:
2070 if (!failsafeIsReceivingRxData()) {
2071 tfp_sprintf(buff
+1, "%s:%3d", " ", 0);
2073 tfp_sprintf(buff
+1, "%d:%3d", rxLinkStatistics
.rfMode
, rxLinkStatistics
.uplinkLQ
);
2076 case OSD_CRSF_LQ_TYPE3
:
2077 if (!failsafeIsReceivingRxData()) {
2078 tfp_sprintf(buff
+1, "%3d", 0);
2080 tfp_sprintf(buff
+1, "%3d", rxLinkStatistics
.rfMode
>= 2 ? scaledLQ
: rxLinkStatistics
.uplinkLQ
);
2084 if (!failsafeIsReceivingRxData()) {
2085 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2086 } else if (rxLinkStatistics
.uplinkLQ
< osdConfig()->link_quality_alarm
) {
2087 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2092 case OSD_CRSF_SNR_DB
:
2094 static pt1Filter_t snrFilterState
;
2095 static timeMs_t snrUpdated
= 0;
2096 int8_t snrFiltered
= pt1FilterApply4(&snrFilterState
, rxLinkStatistics
.uplinkSNR
, 0.5f
, MS2S(millis() - snrUpdated
));
2097 snrUpdated
= millis();
2099 const char* showsnr
= "-20";
2100 const char* hidesnr
= " ";
2101 if (snrFiltered
> osdConfig()->snr_alarm
) {
2104 tfp_sprintf(buff
+ 1, "%s%c", showsnr
, SYM_DB
);
2106 buff
[0] = SYM_BLANK
;
2107 tfp_sprintf(buff
+ 1, "%s%c", hidesnr
, SYM_BLANK
);
2109 } else if (snrFiltered
<= osdConfig()->snr_alarm
) {
2111 if (snrFiltered
<= -10) {
2112 tfp_sprintf(buff
+ 1, "%3d%c", snrFiltered
, SYM_DB
);
2114 tfp_sprintf(buff
+ 1, "%2d%c%c", snrFiltered
, SYM_DB
, ' ');
2120 case OSD_CRSF_TX_POWER
:
2122 if (!failsafeIsReceivingRxData())
2123 tfp_sprintf(buff
, "%s%c", " ", SYM_BLANK
);
2125 tfp_sprintf(buff
, "%4d%c", rxLinkStatistics
.uplinkTXPower
, SYM_MW
);
2130 case OSD_CROSSHAIRS
: // Hud is a sub-element of the crosshair
2132 osdCrosshairPosition(&elemPosX
, &elemPosY
);
2133 osdHudDrawCrosshair(osdGetDisplayPortCanvas(), elemPosX
, elemPosY
);
2135 if (osdConfig()->hud_homing
&& STATE(GPS_FIX
) && STATE(GPS_FIX_HOME
) && isImuHeadingValid()) {
2136 osdHudDrawHoming(elemPosX
, elemPosY
);
2139 if (STATE(GPS_FIX
) && isImuHeadingValid()) {
2141 if (osdConfig()->hud_homepoint
|| osdConfig()->hud_radar_disp
> 0 || osdConfig()->hud_wp_disp
> 0) {
2145 // -------- POI : Home point
2147 if (osdConfig()->hud_homepoint
) { // Display the home point (H)
2148 osdHudDrawPoi(GPS_distanceToHome
, GPS_directionToHome
, -osdGetAltitude() / 100, 0, SYM_HOME
, 0 , 0);
2151 // -------- POI : Nearby aircrafts from ESP32 radar
2153 if (osdConfig()->hud_radar_disp
> 0) { // Display the POI from the radar
2154 for (uint8_t i
= 0; i
< osdConfig()->hud_radar_disp
; i
++) {
2155 if (radar_pois
[i
].gps
.lat
!= 0 && radar_pois
[i
].gps
.lon
!= 0 && radar_pois
[i
].state
< 2) { // state 2 means POI has been lost and must be skipped
2157 geoConvertGeodeticToLocal(&poi
, &posControl
.gpsOrigin
, &radar_pois
[i
].gps
, GEO_ALT_RELATIVE
);
2158 radar_pois
[i
].distance
= calculateDistanceToDestination(&poi
) / 100; // In meters
2160 if (radar_pois
[i
].distance
>= osdConfig()->hud_radar_range_min
&& radar_pois
[i
].distance
<= osdConfig()->hud_radar_range_max
) {
2161 radar_pois
[i
].direction
= calculateBearingToDestination(&poi
) / 100; // In °
2162 radar_pois
[i
].altitude
= (radar_pois
[i
].gps
.alt
- osdGetAltitudeMsl()) / 100;
2163 osdHudDrawPoi(radar_pois
[i
].distance
, osdGetHeadingAngle(radar_pois
[i
].direction
), radar_pois
[i
].altitude
, 1, 65 + i
, radar_pois
[i
].heading
, radar_pois
[i
].lq
);
2169 // -------- POI : Next waypoints from navigation
2171 if (osdConfig()->hud_wp_disp
> 0 && posControl
.waypointListValid
&& posControl
.waypointCount
> 0) { // Display the next waypoints
2175 for (int i
= osdConfig()->hud_wp_disp
- 1; i
>= 0 ; i
--) { // Display in reverse order so the next WP is always written on top
2176 j
= posControl
.activeWaypointIndex
+ i
;
2177 if (j
> posControl
.waypointCount
- 1) { // limit to max WP index for mission
2180 if (posControl
.waypointList
[j
].lat
!= 0 && posControl
.waypointList
[j
].lon
!= 0) {
2181 wp2
.lat
= posControl
.waypointList
[j
].lat
;
2182 wp2
.lon
= posControl
.waypointList
[j
].lon
;
2183 wp2
.alt
= posControl
.waypointList
[j
].alt
;
2185 geoConvertGeodeticToLocal(&poi
, &posControl
.gpsOrigin
, &wp2
, waypointMissionAltConvMode(posControl
.waypointList
[j
].p3
));
2186 int32_t altConvModeAltitude
= waypointMissionAltConvMode(posControl
.waypointList
[j
].p3
) == GEO_ALT_ABSOLUTE
? osdGetAltitudeMsl() : osdGetAltitude();
2187 j
= getGeoWaypointNumber(j
);
2188 while (j
> 9) j
-= 10; // Only the last digit displayed if WP>=10, no room for more (48 = ascii 0)
2189 osdHudDrawPoi(calculateDistanceToDestination(&poi
) / 100, osdGetHeadingAngle(calculateBearingToDestination(&poi
) / 100), (posControl
.waypointList
[j
].alt
- altConvModeAltitude
)/ 100, 2, SYM_WAYPOINT
, 48 + j
, i
);
2198 case OSD_ATTITUDE_ROLL
:
2199 buff
[0] = SYM_ROLL_LEVEL
;
2200 if (ABS(attitude
.values
.roll
) >= 1)
2201 buff
[0] += (attitude
.values
.roll
< 0 ? -1 : 1);
2202 osdFormatCentiNumber(buff
+ 1, DECIDEGREES_TO_CENTIDEGREES(ABS(attitude
.values
.roll
)), 0, 1, 0, 3);
2205 case OSD_ATTITUDE_PITCH
:
2206 if (ABS(attitude
.values
.pitch
) < 1)
2208 else if (attitude
.values
.pitch
> 0)
2209 buff
[0] = SYM_PITCH_DOWN
;
2210 else if (attitude
.values
.pitch
< 0)
2211 buff
[0] = SYM_PITCH_UP
;
2212 osdFormatCentiNumber(buff
+ 1, DECIDEGREES_TO_CENTIDEGREES(ABS(attitude
.values
.pitch
)), 0, 1, 0, 3);
2215 case OSD_ARTIFICIAL_HORIZON
:
2220 #ifdef USE_SECONDARY_IMU
2221 if (secondaryImuState
.active
&& secondaryImuConfig()->useForOsdAHI
) {
2222 rollAngle
= DECIDEGREES_TO_RADIANS(secondaryImuState
.eulerAngles
.values
.roll
);
2223 pitchAngle
= DECIDEGREES_TO_RADIANS(secondaryImuState
.eulerAngles
.values
.pitch
);
2225 rollAngle
= DECIDEGREES_TO_RADIANS(attitude
.values
.roll
);
2226 pitchAngle
= DECIDEGREES_TO_RADIANS(attitude
.values
.pitch
);
2229 rollAngle
= DECIDEGREES_TO_RADIANS(attitude
.values
.roll
);
2230 pitchAngle
= DECIDEGREES_TO_RADIANS(attitude
.values
.pitch
);
2232 pitchAngle
-= osdConfig()->ahi_camera_uptilt_comp
? DEGREES_TO_RADIANS(osdConfig()->camera_uptilt
) : 0;
2233 pitchAngle
+= DEGREES_TO_RADIANS(getFixedWingLevelTrim());
2234 if (osdConfig()->ahi_reverse_roll
) {
2235 rollAngle
= -rollAngle
;
2237 osdDrawArtificialHorizon(osdDisplayPort
, osdGetDisplayPortCanvas(),
2238 OSD_DRAW_POINT_GRID(elemPosX
, elemPosY
), rollAngle
, pitchAngle
);
2239 osdDrawSingleElement(OSD_HORIZON_SIDEBARS
);
2240 osdDrawSingleElement(OSD_CROSSHAIRS
);
2245 case OSD_HORIZON_SIDEBARS
:
2247 osdDrawSidebars(osdDisplayPort
, osdGetDisplayPortCanvas());
2251 #if defined(USE_BARO) || defined(USE_GPS)
2254 float zvel
= getEstimatedActualVelocity(Z
);
2255 osdDrawVario(osdDisplayPort
, osdGetDisplayPortCanvas(), OSD_DRAW_POINT_GRID(elemPosX
, elemPosY
), zvel
);
2261 int16_t value
= getEstimatedActualVelocity(Z
);
2263 switch ((osd_unit_e
)osdConfig()->units
) {
2266 case OSD_UNIT_IMPERIAL
:
2267 // Convert to centifeet/s
2268 value
= CENTIMETERS_TO_CENTIFEET(value
);
2272 // Convert to centi-100feet/min
2273 value
= CENTIMETERS_TO_FEET(value
* 60);
2277 case OSD_UNIT_METRIC_MPH
:
2279 case OSD_UNIT_METRIC
:
2285 osdFormatCentiNumber(buff
, value
, 0, 1, 0, 3);
2292 case OSD_SWITCH_INDICATOR_0
:
2293 osdDisplaySwitchIndicator(osdConfig()->osd_switch_indicator0_name
, rxGetChannelValue(osdConfig()->osd_switch_indicator0_channnel
- 1), buff
);
2296 case OSD_SWITCH_INDICATOR_1
:
2297 osdDisplaySwitchIndicator(osdConfig()->osd_switch_indicator1_name
, rxGetChannelValue(osdConfig()->osd_switch_indicator1_channnel
- 1), buff
);
2300 case OSD_SWITCH_INDICATOR_2
:
2301 osdDisplaySwitchIndicator(osdConfig()->osd_switch_indicator2_name
, rxGetChannelValue(osdConfig()->osd_switch_indicator2_channnel
- 1), buff
);
2304 case OSD_SWITCH_INDICATOR_3
:
2305 osdDisplaySwitchIndicator(osdConfig()->osd_switch_indicator3_name
, rxGetChannelValue(osdConfig()->osd_switch_indicator3_channnel
- 1), buff
);
2308 case OSD_ACTIVE_PROFILE
:
2309 tfp_sprintf(buff
, "%c%u", SYM_PROFILE
, (getConfigProfile() + 1));
2310 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, buff
);
2314 osdDisplayFlightPIDValues(elemPosX
, elemPosY
, "ROL", PID_ROLL
, ADJUSTMENT_ROLL_P
, ADJUSTMENT_ROLL_I
, ADJUSTMENT_ROLL_D
, ADJUSTMENT_ROLL_FF
);
2317 case OSD_PITCH_PIDS
:
2318 osdDisplayFlightPIDValues(elemPosX
, elemPosY
, "PIT", PID_PITCH
, ADJUSTMENT_PITCH_P
, ADJUSTMENT_PITCH_I
, ADJUSTMENT_PITCH_D
, ADJUSTMENT_PITCH_FF
);
2322 osdDisplayFlightPIDValues(elemPosX
, elemPosY
, "YAW", PID_YAW
, ADJUSTMENT_YAW_P
, ADJUSTMENT_YAW_I
, ADJUSTMENT_YAW_D
, ADJUSTMENT_YAW_FF
);
2325 case OSD_LEVEL_PIDS
:
2326 osdDisplayNavPIDValues(elemPosX
, elemPosY
, "LEV", PID_LEVEL
, ADJUSTMENT_LEVEL_P
, ADJUSTMENT_LEVEL_I
, ADJUSTMENT_LEVEL_D
);
2329 case OSD_POS_XY_PIDS
:
2330 osdDisplayNavPIDValues(elemPosX
, elemPosY
, "PXY", PID_POS_XY
, ADJUSTMENT_POS_XY_P
, ADJUSTMENT_POS_XY_I
, ADJUSTMENT_POS_XY_D
);
2333 case OSD_POS_Z_PIDS
:
2334 osdDisplayNavPIDValues(elemPosX
, elemPosY
, "PZ", PID_POS_Z
, ADJUSTMENT_POS_Z_P
, ADJUSTMENT_POS_Z_I
, ADJUSTMENT_POS_Z_D
);
2337 case OSD_VEL_XY_PIDS
:
2338 osdDisplayNavPIDValues(elemPosX
, elemPosY
, "VXY", PID_VEL_XY
, ADJUSTMENT_VEL_XY_P
, ADJUSTMENT_VEL_XY_I
, ADJUSTMENT_VEL_XY_D
);
2341 case OSD_VEL_Z_PIDS
:
2342 osdDisplayNavPIDValues(elemPosX
, elemPosY
, "VZ", PID_VEL_Z
, ADJUSTMENT_VEL_Z_P
, ADJUSTMENT_VEL_Z_I
, ADJUSTMENT_VEL_Z_D
);
2346 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "HP", 0, pidBank()->pid
[PID_HEADING
].P
, 3, 0, ADJUSTMENT_HEADING_P
);
2349 case OSD_BOARD_ALIGN_ROLL
:
2350 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "AR", 0, DECIDEGREES_TO_DEGREES((float)boardAlignment()->rollDeciDegrees
), 4, 1, ADJUSTMENT_ROLL_BOARD_ALIGNMENT
);
2353 case OSD_BOARD_ALIGN_PITCH
:
2354 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "AP", 0, DECIDEGREES_TO_DEGREES((float)boardAlignment()->pitchDeciDegrees
), 4, 1, ADJUSTMENT_PITCH_BOARD_ALIGNMENT
);
2358 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "EXP", 0, currentControlRateProfile
->stabilized
.rcExpo8
, 3, 0, ADJUSTMENT_RC_EXPO
);
2361 case OSD_RC_YAW_EXPO
:
2362 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "YEX", 0, currentControlRateProfile
->stabilized
.rcYawExpo8
, 3, 0, ADJUSTMENT_RC_YAW_EXPO
);
2365 case OSD_THROTTLE_EXPO
:
2366 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "TEX", 0, currentControlRateProfile
->throttle
.rcExpo8
, 3, 0, ADJUSTMENT_THROTTLE_EXPO
);
2369 case OSD_PITCH_RATE
:
2370 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, "SPR");
2372 elemAttr
= TEXT_ATTRIBUTES_NONE
;
2373 tfp_sprintf(buff
, "%3d", currentControlRateProfile
->stabilized
.rates
[FD_PITCH
]);
2374 if (isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_RATE
) || isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_RATE
))
2375 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2376 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 4, elemPosY
, buff
, elemAttr
);
2380 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, "SRR");
2382 elemAttr
= TEXT_ATTRIBUTES_NONE
;
2383 tfp_sprintf(buff
, "%3d", currentControlRateProfile
->stabilized
.rates
[FD_ROLL
]);
2384 if (isAdjustmentFunctionSelected(ADJUSTMENT_ROLL_RATE
) || isAdjustmentFunctionSelected(ADJUSTMENT_PITCH_ROLL_RATE
))
2385 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2386 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 4, elemPosY
, buff
, elemAttr
);
2390 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "SYR", 0, currentControlRateProfile
->stabilized
.rates
[FD_YAW
], 3, 0, ADJUSTMENT_YAW_RATE
);
2393 case OSD_MANUAL_RC_EXPO
:
2394 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "MEX", 0, currentControlRateProfile
->manual
.rcExpo8
, 3, 0, ADJUSTMENT_MANUAL_RC_EXPO
);
2397 case OSD_MANUAL_RC_YAW_EXPO
:
2398 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "MYX", 0, currentControlRateProfile
->manual
.rcYawExpo8
, 3, 0, ADJUSTMENT_MANUAL_RC_YAW_EXPO
);
2401 case OSD_MANUAL_PITCH_RATE
:
2402 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, "MPR");
2404 elemAttr
= TEXT_ATTRIBUTES_NONE
;
2405 tfp_sprintf(buff
, "%3d", currentControlRateProfile
->manual
.rates
[FD_PITCH
]);
2406 if (isAdjustmentFunctionSelected(ADJUSTMENT_MANUAL_PITCH_RATE
) || isAdjustmentFunctionSelected(ADJUSTMENT_MANUAL_PITCH_ROLL_RATE
))
2407 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2408 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 4, elemPosY
, buff
, elemAttr
);
2411 case OSD_MANUAL_ROLL_RATE
:
2412 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, "MRR");
2414 elemAttr
= TEXT_ATTRIBUTES_NONE
;
2415 tfp_sprintf(buff
, "%3d", currentControlRateProfile
->manual
.rates
[FD_ROLL
]);
2416 if (isAdjustmentFunctionSelected(ADJUSTMENT_MANUAL_ROLL_RATE
) || isAdjustmentFunctionSelected(ADJUSTMENT_MANUAL_PITCH_ROLL_RATE
))
2417 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2418 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 4, elemPosY
, buff
, elemAttr
);
2421 case OSD_MANUAL_YAW_RATE
:
2422 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "MYR", 0, currentControlRateProfile
->stabilized
.rates
[FD_YAW
], 3, 0, ADJUSTMENT_YAW_RATE
);
2425 case OSD_NAV_FW_CRUISE_THR
:
2426 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "CRZ", 0, currentBatteryProfile
->nav
.fw
.cruise_throttle
, 4, 0, ADJUSTMENT_NAV_FW_CRUISE_THR
);
2429 case OSD_NAV_FW_PITCH2THR
:
2430 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "P2T", 0, currentBatteryProfile
->nav
.fw
.pitch_to_throttle
, 3, 0, ADJUSTMENT_NAV_FW_PITCH2THR
);
2433 case OSD_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE
:
2434 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "0TP", 0, (float)currentBatteryProfile
->fwMinThrottleDownPitchAngle
/ 10, 3, 1, ADJUSTMENT_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE
);
2437 case OSD_FW_ALT_PID_OUTPUTS
:
2439 const navigationPIDControllers_t
*nav_pids
= getNavigationPIDControllers();
2440 osdFormatPidControllerOutput(buff
, "PZO", &nav_pids
->fw_alt
, 10, true); // display requested pitch degrees
2444 case OSD_FW_POS_PID_OUTPUTS
:
2446 const navigationPIDControllers_t
*nav_pids
= getNavigationPIDControllers(); // display requested roll degrees
2447 osdFormatPidControllerOutput(buff
, "PXYO", &nav_pids
->fw_nav
, 1, true);
2451 case OSD_MC_VEL_Z_PID_OUTPUTS
:
2453 const navigationPIDControllers_t
*nav_pids
= getNavigationPIDControllers();
2454 osdFormatPidControllerOutput(buff
, "VZO", &nav_pids
->vel
[Z
], 100, false); // display throttle adjustment µs
2458 case OSD_MC_VEL_X_PID_OUTPUTS
:
2460 const navigationPIDControllers_t
*nav_pids
= getNavigationPIDControllers();
2461 osdFormatPidControllerOutput(buff
, "VXO", &nav_pids
->vel
[X
], 100, false); // display requested acceleration cm/s^2
2465 case OSD_MC_VEL_Y_PID_OUTPUTS
:
2467 const navigationPIDControllers_t
*nav_pids
= getNavigationPIDControllers();
2468 osdFormatPidControllerOutput(buff
, "VYO", &nav_pids
->vel
[Y
], 100, false); // display requested acceleration cm/s^2
2472 case OSD_MC_POS_XYZ_P_OUTPUTS
:
2474 const navigationPIDControllers_t
*nav_pids
= getNavigationPIDControllers();
2475 strcpy(buff
, "POSO ");
2476 // display requested velocity cm/s
2477 tfp_sprintf(buff
+ 5, "%4d", (int)lrintf(nav_pids
->pos
[X
].output_constrained
* 100));
2479 tfp_sprintf(buff
+ 10, "%4d", (int)lrintf(nav_pids
->pos
[Y
].output_constrained
* 100));
2481 tfp_sprintf(buff
+ 15, "%4d", (int)lrintf(nav_pids
->pos
[Z
].output_constrained
* 100));
2488 bool kiloWatt
= osdFormatCentiNumber(buff
, getPower(), 1000, 2, 2, 3);
2489 buff
[3] = kiloWatt
? SYM_KILOWATT
: SYM_WATT
;
2492 uint8_t current_alarm
= osdConfig()->current_alarm
;
2493 if ((current_alarm
> 0) && ((getAmperage() / 100.0f
) > current_alarm
)) {
2494 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2503 osdFormatVelocityStr(buff
+ 1, pitot
.airSpeed
, false, false);
2505 if ((osdConfig()->airspeed_alarm_min
!= 0 && pitot
.airSpeed
< osdConfig()->airspeed_alarm_min
) ||
2506 (osdConfig()->airspeed_alarm_max
!= 0 && pitot
.airSpeed
> osdConfig()->airspeed_alarm_max
)) {
2507 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2515 case OSD_AIR_MAX_SPEED
:
2520 osdFormatVelocityStr(buff
+ 2, stats
.max_air_speed
, false, false);
2529 // RTC not configured will show 00:00
2530 dateTime_t dateTime
;
2531 rtcGetDateTimeLocal(&dateTime
);
2532 buff
[0] = SYM_CLOCK
;
2533 tfp_sprintf(buff
+ 1, "%02u:%02u:%02u", dateTime
.hours
, dateTime
.minutes
, dateTime
.seconds
);
2539 elemAttr
= osdGetSystemMessage(buff
, OSD_MESSAGE_LENGTH
, true);
2545 tfp_sprintf(buff
, "INAV %s", FC_VERSION_STRING
);
2546 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, buff
);
2550 case OSD_MAIN_BATT_CELL_VOLTAGE
:
2552 osdDisplayBatteryVoltage(elemPosX
, elemPosY
, getBatteryRawAverageCellVoltage(), 3, 2);
2556 case OSD_MAIN_BATT_SAG_COMPENSATED_CELL_VOLTAGE
:
2558 osdDisplayBatteryVoltage(elemPosX
, elemPosY
, getBatterySagCompensatedAverageCellVoltage(), 3, 2);
2562 case OSD_THROTTLE_POS_AUTO_THR
:
2564 osdFormatThrottlePosition(buff
, true, &elemAttr
);
2568 case OSD_HEADING_GRAPH
:
2570 if (osdIsHeadingValid()) {
2571 osdDrawHeadingGraph(osdDisplayPort
, osdGetDisplayPortCanvas(), OSD_DRAW_POINT_GRID(elemPosX
, elemPosY
), osdGetHeading());
2574 buff
[0] = buff
[2] = buff
[4] = buff
[6] = buff
[8] = SYM_HEADING_LINE
;
2575 buff
[1] = buff
[3] = buff
[5] = buff
[7] = SYM_HEADING_DIVIDED_LINE
;
2576 buff
[OSD_HEADING_GRAPH_WIDTH
] = '\0';
2581 case OSD_EFFICIENCY_MAH_PER_KM
:
2583 // amperage is in centi amps, speed is in cms/s. We want
2584 // mah/km. Only show when ground speed > 1m/s.
2585 static pt1Filter_t eFilterState
;
2586 static timeUs_t efficiencyUpdated
= 0;
2588 bool moreThanAh
= false;
2589 timeUs_t currentTimeUs
= micros();
2590 timeDelta_t efficiencyTimeDelta
= cmpTimeUs(currentTimeUs
, efficiencyUpdated
);
2591 if (STATE(GPS_FIX
) && gpsSol
.groundSpeed
> 0) {
2592 if (efficiencyTimeDelta
>= EFFICIENCY_UPDATE_INTERVAL
) {
2593 value
= pt1FilterApply4(&eFilterState
, ((float)getAmperage() / gpsSol
.groundSpeed
) / 0.0036f
,
2594 1, US2S(efficiencyTimeDelta
));
2596 efficiencyUpdated
= currentTimeUs
;
2598 value
= eFilterState
.state
;
2601 bool efficiencyValid
= (value
> 0) && (gpsSol
.groundSpeed
> 100);
2602 switch (osdConfig()->units
) {
2605 case OSD_UNIT_IMPERIAL
:
2606 moreThanAh
= osdFormatCentiNumber(buff
, value
* METERS_PER_MILE
/ 10, 1000, 0, 2, 3);
2608 tfp_sprintf(buff
, "%s%c%c", buff
, SYM_MAH_MI_0
, SYM_MAH_MI_1
);
2610 tfp_sprintf(buff
, "%s%c", buff
, SYM_AH_MI
);
2612 if (!efficiencyValid
) {
2613 buff
[0] = buff
[1] = buff
[2] = '-';
2614 buff
[3] = SYM_MAH_MI_0
;
2615 buff
[4] = SYM_MAH_MI_1
;
2620 moreThanAh
= osdFormatCentiNumber(buff
, value
* METERS_PER_NAUTICALMILE
/ 10, 1000, 0, 2, 3);
2622 tfp_sprintf(buff
, "%s%c%c", buff
, SYM_MAH_NM_0
, SYM_MAH_NM_1
);
2624 tfp_sprintf(buff
, "%s%c", buff
, SYM_AH_NM
);
2626 if (!efficiencyValid
) {
2627 buff
[0] = buff
[1] = buff
[2] = '-';
2628 buff
[3] = SYM_MAH_NM_0
;
2629 buff
[4] = SYM_MAH_NM_1
;
2633 case OSD_UNIT_METRIC_MPH
:
2635 case OSD_UNIT_METRIC
:
2636 moreThanAh
= osdFormatCentiNumber(buff
, value
* 100, 1000, 0, 2, 3);
2638 tfp_sprintf(buff
, "%s%c%c", buff
, SYM_MAH_KM_0
, SYM_MAH_KM_1
);
2640 tfp_sprintf(buff
, "%s%c", buff
, SYM_AH_KM
);
2642 if (!efficiencyValid
) {
2643 buff
[0] = buff
[1] = buff
[2] = '-';
2644 buff
[3] = SYM_MAH_KM_0
;
2645 buff
[4] = SYM_MAH_KM_1
;
2653 case OSD_EFFICIENCY_WH_PER_KM
:
2655 // amperage is in centi amps, speed is in cms/s. We want
2656 // mWh/km. Only show when ground speed > 1m/s.
2657 static pt1Filter_t eFilterState
;
2658 static timeUs_t efficiencyUpdated
= 0;
2660 timeUs_t currentTimeUs
= micros();
2661 timeDelta_t efficiencyTimeDelta
= cmpTimeUs(currentTimeUs
, efficiencyUpdated
);
2662 if (STATE(GPS_FIX
) && gpsSol
.groundSpeed
> 0) {
2663 if (efficiencyTimeDelta
>= EFFICIENCY_UPDATE_INTERVAL
) {
2664 value
= pt1FilterApply4(&eFilterState
, ((float)getPower() / gpsSol
.groundSpeed
) / 0.0036f
,
2665 1, US2S(efficiencyTimeDelta
));
2667 efficiencyUpdated
= currentTimeUs
;
2669 value
= eFilterState
.state
;
2672 bool efficiencyValid
= (value
> 0) && (gpsSol
.groundSpeed
> 100);
2673 switch (osdConfig()->units
) {
2676 case OSD_UNIT_IMPERIAL
:
2677 osdFormatCentiNumber(buff
, value
* METERS_PER_MILE
/ 10000, 0, 2, 0, 3);
2678 buff
[3] = SYM_WH_MI
;
2681 osdFormatCentiNumber(buff
, value
* METERS_PER_NAUTICALMILE
/ 10000, 0, 2, 0, 3);
2682 buff
[3] = SYM_WH_NM
;
2684 case OSD_UNIT_METRIC_MPH
:
2686 case OSD_UNIT_METRIC
:
2687 osdFormatCentiNumber(buff
, value
/ 10, 0, 2, 0, 3);
2688 buff
[3] = SYM_WH_KM
;
2692 if (!efficiencyValid
) {
2693 buff
[0] = buff
[1] = buff
[2] = '-';
2700 buff
[0] = SYM_GFORCE
;
2701 osdFormatCentiNumber(buff
+ 1, GForce
, 0, 2, 0, 3);
2702 if (GForce
> osdConfig()->gforce_alarm
* 100) {
2703 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2712 float GForceValue
= GForceAxis
[item
- OSD_GFORCE_X
];
2713 buff
[0] = SYM_GFORCE_X
+ item
- OSD_GFORCE_X
;
2714 osdFormatCentiNumber(buff
+ 1, GForceValue
, 0, 2, 0, 4);
2715 if ((GForceValue
< osdConfig()->gforce_axis_alarm_min
* 100) || (GForceValue
> osdConfig()->gforce_axis_alarm_max
* 100)) {
2716 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2723 * Longest representable string is -2147483648 does not fit in the screen.
2724 * Only 7 digits for negative and 8 digits for positive values allowed
2726 for (uint8_t bufferIndex
= 0; bufferIndex
< DEBUG32_VALUE_COUNT
; ++elemPosY
, bufferIndex
+= 2) {
2729 "[%u]=%8ld [%u]=%8ld",
2731 constrain(debug
[bufferIndex
], -9999999, 99999999),
2733 constrain(debug
[bufferIndex
+1], -9999999, 99999999)
2735 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, buff
);
2740 case OSD_IMU_TEMPERATURE
:
2742 int16_t temperature
;
2743 const bool valid
= getIMUTemperature(&temperature
);
2744 osdDisplayTemperature(elemPosX
, elemPosY
, SYM_IMU_TEMP
, NULL
, valid
, temperature
, osdConfig()->imu_temp_alarm_min
, osdConfig()->imu_temp_alarm_max
);
2748 case OSD_BARO_TEMPERATURE
:
2750 int16_t temperature
;
2751 const bool valid
= getBaroTemperature(&temperature
);
2752 osdDisplayTemperature(elemPosX
, elemPosY
, SYM_BARO_TEMP
, NULL
, valid
, temperature
, osdConfig()->imu_temp_alarm_min
, osdConfig()->imu_temp_alarm_max
);
2756 #ifdef USE_TEMPERATURE_SENSOR
2757 case OSD_TEMP_SENSOR_0_TEMPERATURE
:
2758 case OSD_TEMP_SENSOR_1_TEMPERATURE
:
2759 case OSD_TEMP_SENSOR_2_TEMPERATURE
:
2760 case OSD_TEMP_SENSOR_3_TEMPERATURE
:
2761 case OSD_TEMP_SENSOR_4_TEMPERATURE
:
2762 case OSD_TEMP_SENSOR_5_TEMPERATURE
:
2763 case OSD_TEMP_SENSOR_6_TEMPERATURE
:
2764 case OSD_TEMP_SENSOR_7_TEMPERATURE
:
2766 osdDisplayTemperatureSensor(elemPosX
, elemPosY
, item
- OSD_TEMP_SENSOR_0_TEMPERATURE
);
2769 #endif /* ifdef USE_TEMPERATURE_SENSOR */
2771 case OSD_WIND_SPEED_HORIZONTAL
:
2772 #ifdef USE_WIND_ESTIMATOR
2774 bool valid
= isEstimatedWindSpeedValid();
2775 float horizontalWindSpeed
;
2778 horizontalWindSpeed
= getEstimatedHorizontalWindSpeed(&angle
);
2779 int16_t windDirection
= osdGetHeadingAngle((int)angle
- DECIDEGREES_TO_DEGREES(attitude
.values
.yaw
));
2780 buff
[1] = SYM_DIRECTION
+ (windDirection
* 2 / 90);
2782 horizontalWindSpeed
= 0;
2783 buff
[1] = SYM_BLANK
;
2785 buff
[0] = SYM_WIND_HORIZONTAL
;
2786 osdFormatWindSpeedStr(buff
+ 2, horizontalWindSpeed
, valid
);
2793 case OSD_WIND_SPEED_VERTICAL
:
2794 #ifdef USE_WIND_ESTIMATOR
2796 buff
[0] = SYM_WIND_VERTICAL
;
2797 buff
[1] = SYM_BLANK
;
2798 bool valid
= isEstimatedWindSpeedValid();
2799 float verticalWindSpeed
;
2801 verticalWindSpeed
= getEstimatedWindSpeed(Z
);
2802 if (verticalWindSpeed
< 0) {
2803 buff
[1] = SYM_AH_DECORATION_DOWN
;
2804 verticalWindSpeed
= -verticalWindSpeed
;
2805 } else if (verticalWindSpeed
> 0) {
2806 buff
[1] = SYM_AH_DECORATION_UP
;
2809 verticalWindSpeed
= 0;
2811 osdFormatWindSpeedStr(buff
+ 2, verticalWindSpeed
, valid
);
2820 STATIC_ASSERT(GPS_DEGREES_DIVIDER
== OLC_DEG_MULTIPLIER
, invalid_olc_deg_multiplier
);
2821 int digits
= osdConfig()->plus_code_digits
;
2822 int digitsRemoved
= osdConfig()->plus_code_short
* 2;
2823 if (STATE(GPS_FIX
)) {
2824 olc_encode(gpsSol
.llh
.lat
, gpsSol
.llh
.lon
, digits
, buff
, sizeof(buff
));
2826 // +codes with > 8 digits have a + at the 9th digit
2827 // and we only support 10 and up.
2828 memset(buff
, '-', digits
+ 1);
2830 buff
[digits
+ 1] = '\0';
2832 // Optionally trim digits from the left
2833 memmove(buff
, buff
+digitsRemoved
, strlen(buff
) + digitsRemoved
);
2834 buff
[digits
+ 1 - digitsRemoved
] = '\0';
2841 buff
[0] = SYM_AZIMUTH
;
2842 if (osdIsHeadingValid()) {
2843 int16_t h
= GPS_directionToHome
;
2852 tfp_sprintf(&buff
[1], "%3d", h
);
2854 buff
[1] = buff
[2] = buff
[3] = '-';
2856 buff
[4] = SYM_DEGREES
;
2864 int scaleUnitDivisor
;
2869 switch (osdConfig()->units
) {
2872 case OSD_UNIT_IMPERIAL
:
2873 scaleToUnit
= 100 / 1609.3440f
; // scale to 0.01mi for osdFormatCentiNumber()
2874 scaleUnitDivisor
= 0;
2875 symUnscaled
= SYM_MI
;
2880 scaleToUnit
= 100 / 1852.0010f
; // scale to 0.01mi for osdFormatCentiNumber()
2881 scaleUnitDivisor
= 0;
2882 symUnscaled
= SYM_NM
;
2887 case OSD_UNIT_METRIC_MPH
:
2889 case OSD_UNIT_METRIC
:
2890 scaleToUnit
= 100; // scale to cm for osdFormatCentiNumber()
2891 scaleUnitDivisor
= 1000; // Convert to km when scale gets bigger than 999m
2892 symUnscaled
= SYM_M
;
2897 buff
[0] = SYM_SCALE
;
2898 if (osdMapData
.scale
> 0) {
2899 bool scaled
= osdFormatCentiNumber(&buff
[1], osdMapData
.scale
* scaleToUnit
, scaleUnitDivisor
, maxDecimals
, 2, 3);
2900 buff
[4] = scaled
? symScaled
: symUnscaled
;
2901 // Make sure this is cleared if the map stops being drawn
2902 osdMapData
.scale
= 0;
2904 memset(&buff
[1], '-', 4);
2909 case OSD_MAP_REFERENCE
:
2911 char referenceSymbol
;
2912 if (osdMapData
.referenceSymbol
) {
2913 referenceSymbol
= osdMapData
.referenceSymbol
;
2914 // Make sure this is cleared if the map stops being drawn
2915 osdMapData
.referenceSymbol
= 0;
2917 referenceSymbol
= '-';
2919 displayWriteChar(osdDisplayPort
, elemPosX
, elemPosY
, SYM_DIRECTION
);
2920 displayWriteChar(osdDisplayPort
, elemPosX
, elemPosY
+ 1, referenceSymbol
);
2926 osdFormatGVar(buff
, 0);
2931 osdFormatGVar(buff
, 1);
2936 osdFormatGVar(buff
, 2);
2941 osdFormatGVar(buff
, 3);
2945 #if defined(USE_RX_MSP) && defined(USE_MSP_RC_OVERRIDE)
2948 const char *source_text
= IS_RC_MODE_ACTIVE(BOXMSPRCOVERRIDE
) && !mspOverrideIsInFailsafe() ? "MSP" : "STD";
2949 if (IS_RC_MODE_ACTIVE(BOXMSPRCOVERRIDE
) && mspOverrideIsInFailsafe()) TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
2950 displayWriteWithAttr(osdDisplayPort
, elemPosX
, elemPosY
, source_text
, elemAttr
);
2955 #if defined(USE_ESC_SENSOR)
2958 escSensorData_t
* escSensor
= escSensorGetData();
2959 if (escSensor
&& escSensor
->dataAge
<= ESC_DATA_MAX_AGE
) {
2960 osdFormatRpm(buff
, escSensor
->rpm
);
2963 osdFormatRpm(buff
, 0);
2967 case OSD_ESC_TEMPERATURE
:
2969 escSensorData_t
* escSensor
= escSensorGetData();
2970 bool escTemperatureValid
= escSensor
&& escSensor
->dataAge
<= ESC_DATA_MAX_AGE
;
2971 osdDisplayTemperature(elemPosX
, elemPosY
, SYM_ESC_TEMP
, NULL
, escTemperatureValid
, (escSensor
->temperature
)*10, osdConfig()->esc_temp_alarm_min
, osdConfig()->esc_temp_alarm_max
);
2978 textAttributes_t attr
;
2980 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, "TPA");
2981 attr
= TEXT_ATTRIBUTES_NONE
;
2982 tfp_sprintf(buff
, "%3d", currentControlRateProfile
->throttle
.dynPID
);
2983 if (isAdjustmentFunctionSelected(ADJUSTMENT_TPA
)) {
2984 TEXT_ATTRIBUTES_ADD_BLINK(attr
);
2986 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 5, elemPosY
, buff
, attr
);
2988 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
+ 1, "BP");
2989 attr
= TEXT_ATTRIBUTES_NONE
;
2990 tfp_sprintf(buff
, "%4d", currentControlRateProfile
->throttle
.pa_breakpoint
);
2991 if (isAdjustmentFunctionSelected(ADJUSTMENT_TPA_BREAKPOINT
)) {
2992 TEXT_ATTRIBUTES_ADD_BLINK(attr
);
2994 displayWriteWithAttr(osdDisplayPort
, elemPosX
+ 4, elemPosY
+ 1, buff
, attr
);
2999 case OSD_NAV_FW_CONTROL_SMOOTHNESS
:
3000 osdDisplayAdjustableDecimalValue(elemPosX
, elemPosY
, "CTL S", 0, navConfig()->fw
.control_smoothness
, 1, 0, ADJUSTMENT_NAV_FW_CONTROL_SMOOTHNESS
);
3005 if (IS_RC_MODE_ACTIVE(BOXPLANWPMISSION
)) {
3007 switch (posControl
.wpMissionPlannerStatus
) {
3009 strcpy(buf
, "WAIT");
3012 strcpy(buf
, "SAVE");
3015 strcpy(buf
, " OK ");
3018 strcpy(buf
, "FULL");
3020 tfp_sprintf(buff
, "%s>%2uWP", buf
, posControl
.wpPlannerActiveWPIndex
);
3021 } else if (posControl
.wpPlannerActiveWPIndex
){
3022 tfp_sprintf(buff
, "PLAN>%2uWP", posControl
.waypointCount
); // mission planner mision active
3024 #ifdef USE_MULTI_MISSION
3026 if (ARMING_FLAG(ARMED
)){
3027 // Limit field size when Armed, only show selected mission
3028 tfp_sprintf(buff
, "M%u ", posControl
.loadedMultiMissionIndex
);
3029 } else if (posControl
.multiMissionCount
&& navConfig()->general
.waypoint_multi_mission_index
){
3030 if (navConfig()->general
.waypoint_multi_mission_index
!= posControl
.loadedMultiMissionIndex
) {
3031 tfp_sprintf(buff
, "M%u/%u>LOAD", navConfig()->general
.waypoint_multi_mission_index
, posControl
.multiMissionCount
);
3033 // wpCount source for selected mission changes after Arming (until next mission load)
3034 int8_t wpCount
= posControl
.loadedMultiMissionWPCount
? posControl
.loadedMultiMissionWPCount
: posControl
.waypointCount
;
3035 if (posControl
.waypointListValid
&& wpCount
> 0) {
3036 tfp_sprintf(buff
, "M%u/%u>%2uWP", posControl
.loadedMultiMissionIndex
, posControl
.multiMissionCount
, wpCount
);
3038 tfp_sprintf(buff
, "M0/%u> 0WP", posControl
.multiMissionCount
);
3041 } else { // multi_mission_index 0 - show active WP count
3042 tfp_sprintf(buff
, "WP CNT>%2u", posControl
.waypointCount
);
3046 displayWrite(osdDisplayPort
, elemPosX
, elemPosY
, buff
);
3050 #ifdef USE_POWER_LIMITS
3051 case OSD_PLIMIT_REMAINING_BURST_TIME
:
3052 osdFormatCentiNumber(buff
, powerLimiterGetRemainingBurstTime() * 100, 0, 1, 0, 3);
3057 case OSD_PLIMIT_ACTIVE_CURRENT_LIMIT
:
3058 if (currentBatteryProfile
->powerLimits
.continuousCurrent
) {
3059 osdFormatCentiNumber(buff
, powerLimiterGetActiveCurrentLimit(), 0, 2, 0, 3);
3063 if (powerLimiterIsLimitingCurrent()) {
3064 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
3070 case OSD_PLIMIT_ACTIVE_POWER_LIMIT
:
3072 if (currentBatteryProfile
->powerLimits
.continuousPower
) {
3073 bool kiloWatt
= osdFormatCentiNumber(buff
, powerLimiterGetActivePowerLimit(), 1000, 2, 2, 3);
3074 buff
[3] = kiloWatt
? SYM_KILOWATT
: SYM_WATT
;
3077 if (powerLimiterIsLimitingPower()) {
3078 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
3084 #endif // USE_POWER_LIMITS
3090 displayWriteWithAttr(osdDisplayPort
, elemPosX
, elemPosY
, buff
, elemAttr
);
3094 static uint8_t osdIncElementIndex(uint8_t elementIndex
)
3098 if (elementIndex
== OSD_ARTIFICIAL_HORIZON
)
3101 #ifndef USE_TEMPERATURE_SENSOR
3102 if (elementIndex
== OSD_TEMP_SENSOR_0_TEMPERATURE
)
3103 elementIndex
= OSD_ALTITUDE_MSL
;
3106 if (!sensors(SENSOR_ACC
)) {
3107 if (elementIndex
== OSD_CROSSHAIRS
) {
3108 elementIndex
= OSD_ONTIME
;
3112 if (!feature(FEATURE_VBAT
)) {
3113 if (elementIndex
== OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE
) {
3114 elementIndex
= OSD_LEVEL_PIDS
;
3118 if (!feature(FEATURE_CURRENT_METER
)) {
3119 if (elementIndex
== OSD_CURRENT_DRAW
) {
3120 elementIndex
= OSD_GPS_SPEED
;
3122 if (elementIndex
== OSD_EFFICIENCY_MAH_PER_KM
) {
3123 elementIndex
= OSD_TRIP_DIST
;
3125 if (elementIndex
== OSD_REMAINING_FLIGHT_TIME_BEFORE_RTH
) {
3126 elementIndex
= OSD_HOME_HEADING_ERROR
;
3128 if (elementIndex
== OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE
) {
3129 elementIndex
= OSD_LEVEL_PIDS
;
3133 if (!feature(FEATURE_GPS
)) {
3134 if (elementIndex
== OSD_GPS_SPEED
) {
3135 elementIndex
= OSD_ALTITUDE
;
3137 if (elementIndex
== OSD_GPS_LON
) {
3138 elementIndex
= OSD_VARIO
;
3140 if (elementIndex
== OSD_GPS_HDOP
) {
3141 elementIndex
= OSD_MAIN_BATT_CELL_VOLTAGE
;
3143 if (elementIndex
== OSD_TRIP_DIST
) {
3144 elementIndex
= OSD_ATTITUDE_PITCH
;
3146 if (elementIndex
== OSD_WIND_SPEED_HORIZONTAL
) {
3147 elementIndex
= OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE
;
3149 if (elementIndex
== OSD_3D_SPEED
) {
3154 if (!STATE(ESC_SENSOR_ENABLED
)) {
3155 if (elementIndex
== OSD_ESC_RPM
) {
3160 #ifndef USE_POWER_LIMITS
3161 if (elementIndex
== OSD_NAV_FW_CONTROL_SMOOTHNESS
) {
3162 elementIndex
= OSD_ITEM_COUNT
;
3166 if (elementIndex
== OSD_ITEM_COUNT
) {
3169 return elementIndex
;
3172 void osdDrawNextElement(void)
3174 static uint8_t elementIndex
= 0;
3175 // Prevent infinite loop when no elements are enabled
3176 uint8_t index
= elementIndex
;
3178 elementIndex
= osdIncElementIndex(elementIndex
);
3179 } while(!osdDrawSingleElement(elementIndex
) && index
!= elementIndex
);
3181 // Draw artificial horizon + tracking telemtry last
3182 osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON
);
3183 if (osdConfig()->telemetry
>0){
3184 osdDisplayTelemetry();
3188 PG_RESET_TEMPLATE(osdConfig_t
, osdConfig
,
3189 .rssi_alarm
= SETTING_OSD_RSSI_ALARM_DEFAULT
,
3190 .time_alarm
= SETTING_OSD_TIME_ALARM_DEFAULT
,
3191 .alt_alarm
= SETTING_OSD_ALT_ALARM_DEFAULT
,
3192 .dist_alarm
= SETTING_OSD_DIST_ALARM_DEFAULT
,
3193 .neg_alt_alarm
= SETTING_OSD_NEG_ALT_ALARM_DEFAULT
,
3194 .current_alarm
= SETTING_OSD_CURRENT_ALARM_DEFAULT
,
3195 .imu_temp_alarm_min
= SETTING_OSD_IMU_TEMP_ALARM_MIN_DEFAULT
,
3196 .imu_temp_alarm_max
= SETTING_OSD_IMU_TEMP_ALARM_MAX_DEFAULT
,
3197 .esc_temp_alarm_min
= SETTING_OSD_ESC_TEMP_ALARM_MIN_DEFAULT
,
3198 .esc_temp_alarm_max
= SETTING_OSD_ESC_TEMP_ALARM_MAX_DEFAULT
,
3199 .gforce_alarm
= SETTING_OSD_GFORCE_ALARM_DEFAULT
,
3200 .gforce_axis_alarm_min
= SETTING_OSD_GFORCE_AXIS_ALARM_MIN_DEFAULT
,
3201 .gforce_axis_alarm_max
= SETTING_OSD_GFORCE_AXIS_ALARM_MAX_DEFAULT
,
3203 .baro_temp_alarm_min
= SETTING_OSD_BARO_TEMP_ALARM_MIN_DEFAULT
,
3204 .baro_temp_alarm_max
= SETTING_OSD_BARO_TEMP_ALARM_MAX_DEFAULT
,
3206 #ifdef USE_SERIALRX_CRSF
3207 .snr_alarm
= SETTING_OSD_SNR_ALARM_DEFAULT
,
3208 .crsf_lq_format
= SETTING_OSD_CRSF_LQ_FORMAT_DEFAULT
,
3209 .link_quality_alarm
= SETTING_OSD_LINK_QUALITY_ALARM_DEFAULT
,
3210 .rssi_dbm_alarm
= SETTING_OSD_RSSI_DBM_ALARM_DEFAULT
,
3211 .rssi_dbm_max
= SETTING_OSD_RSSI_DBM_MAX_DEFAULT
,
3212 .rssi_dbm_min
= SETTING_OSD_RSSI_DBM_MIN_DEFAULT
,
3214 #ifdef USE_TEMPERATURE_SENSOR
3215 .temp_label_align
= SETTING_OSD_TEMP_LABEL_ALIGN_DEFAULT
,
3218 .airspeed_alarm_min
= SETTING_OSD_AIRSPEED_ALARM_MIN_DEFAULT
,
3219 .airspeed_alarm_max
= SETTING_OSD_AIRSPEED_ALARM_MAX_DEFAULT
,
3222 .video_system
= SETTING_OSD_VIDEO_SYSTEM_DEFAULT
,
3223 .row_shiftdown
= SETTING_OSD_ROW_SHIFTDOWN_DEFAULT
,
3225 .ahi_reverse_roll
= SETTING_OSD_AHI_REVERSE_ROLL_DEFAULT
,
3226 .ahi_max_pitch
= SETTING_OSD_AHI_MAX_PITCH_DEFAULT
,
3227 .crosshairs_style
= SETTING_OSD_CROSSHAIRS_STYLE_DEFAULT
,
3228 .horizon_offset
= SETTING_OSD_HORIZON_OFFSET_DEFAULT
,
3229 .camera_uptilt
= SETTING_OSD_CAMERA_UPTILT_DEFAULT
,
3230 .ahi_camera_uptilt_comp
= SETTING_OSD_AHI_CAMERA_UPTILT_COMP_DEFAULT
,
3231 .camera_fov_h
= SETTING_OSD_CAMERA_FOV_H_DEFAULT
,
3232 .camera_fov_v
= SETTING_OSD_CAMERA_FOV_V_DEFAULT
,
3233 .hud_margin_h
= SETTING_OSD_HUD_MARGIN_H_DEFAULT
,
3234 .hud_margin_v
= SETTING_OSD_HUD_MARGIN_V_DEFAULT
,
3235 .hud_homing
= SETTING_OSD_HUD_HOMING_DEFAULT
,
3236 .hud_homepoint
= SETTING_OSD_HUD_HOMEPOINT_DEFAULT
,
3237 .hud_radar_disp
= SETTING_OSD_HUD_RADAR_DISP_DEFAULT
,
3238 .hud_radar_range_min
= SETTING_OSD_HUD_RADAR_RANGE_MIN_DEFAULT
,
3239 .hud_radar_range_max
= SETTING_OSD_HUD_RADAR_RANGE_MAX_DEFAULT
,
3240 .hud_wp_disp
= SETTING_OSD_HUD_WP_DISP_DEFAULT
,
3241 .left_sidebar_scroll
= SETTING_OSD_LEFT_SIDEBAR_SCROLL_DEFAULT
,
3242 .right_sidebar_scroll
= SETTING_OSD_RIGHT_SIDEBAR_SCROLL_DEFAULT
,
3243 .sidebar_scroll_arrows
= SETTING_OSD_SIDEBAR_SCROLL_ARROWS_DEFAULT
,
3244 .sidebar_horizontal_offset
= SETTING_OSD_SIDEBAR_HORIZONTAL_OFFSET_DEFAULT
,
3245 .left_sidebar_scroll_step
= SETTING_OSD_LEFT_SIDEBAR_SCROLL_STEP_DEFAULT
,
3246 .right_sidebar_scroll_step
= SETTING_OSD_RIGHT_SIDEBAR_SCROLL_STEP_DEFAULT
,
3247 .sidebar_height
= SETTING_OSD_SIDEBAR_HEIGHT_DEFAULT
,
3248 .osd_home_position_arm_screen
= SETTING_OSD_HOME_POSITION_ARM_SCREEN_DEFAULT
,
3249 .pan_servo_index
= SETTING_OSD_PAN_SERVO_INDEX_DEFAULT
,
3250 .pan_servo_pwm2centideg
= SETTING_OSD_PAN_SERVO_PWM2CENTIDEG_DEFAULT
,
3251 .esc_rpm_precision
= SETTING_OSD_ESC_RPM_PRECISION_DEFAULT
,
3252 .osd_switch_indicator0_name
= SETTING_OSD_SWITCH_INDICATOR_ZERO_NAME_DEFAULT
,
3253 .osd_switch_indicator0_channnel
= SETTING_OSD_SWITCH_INDICATOR_ZERO_CHANNNEL_DEFAULT
,
3254 .osd_switch_indicator1_name
= SETTING_OSD_SWITCH_INDICATOR_ONE_NAME_DEFAULT
,
3255 .osd_switch_indicator1_channnel
= SETTING_OSD_SWITCH_INDICATOR_ONE_CHANNNEL_DEFAULT
,
3256 .osd_switch_indicator2_name
= SETTING_OSD_SWITCH_INDICATOR_TWO_NAME_DEFAULT
,
3257 .osd_switch_indicator2_channnel
= SETTING_OSD_SWITCH_INDICATOR_TWO_CHANNNEL_DEFAULT
,
3258 .osd_switch_indicator3_name
= SETTING_OSD_SWITCH_INDICATOR_THREE_NAME_DEFAULT
,
3259 .osd_switch_indicator3_channnel
= SETTING_OSD_SWITCH_INDICATOR_THREE_CHANNNEL_DEFAULT
,
3261 .units
= SETTING_OSD_UNITS_DEFAULT
,
3262 .main_voltage_decimals
= SETTING_OSD_MAIN_VOLTAGE_DECIMALS_DEFAULT
,
3264 #ifdef USE_WIND_ESTIMATOR
3265 .estimations_wind_compensation
= SETTING_OSD_ESTIMATIONS_WIND_COMPENSATION_DEFAULT
,
3268 .coordinate_digits
= SETTING_OSD_COORDINATE_DIGITS_DEFAULT
,
3270 .osd_failsafe_switch_layout
= SETTING_OSD_FAILSAFE_SWITCH_LAYOUT_DEFAULT
,
3272 .plus_code_digits
= SETTING_OSD_PLUS_CODE_DIGITS_DEFAULT
,
3273 .plus_code_short
= SETTING_OSD_PLUS_CODE_SHORT_DEFAULT
,
3275 .ahi_width
= SETTING_OSD_AHI_WIDTH_DEFAULT
,
3276 .ahi_height
= SETTING_OSD_AHI_HEIGHT_DEFAULT
,
3277 .ahi_vertical_offset
= SETTING_OSD_AHI_VERTICAL_OFFSET_DEFAULT
,
3278 .ahi_bordered
= SETTING_OSD_AHI_BORDERED_DEFAULT
,
3279 .ahi_style
= SETTING_OSD_AHI_STYLE_DEFAULT
,
3281 .force_grid
= SETTING_OSD_FORCE_GRID_DEFAULT
,
3283 .stats_energy_unit
= SETTING_OSD_STATS_ENERGY_UNIT_DEFAULT
,
3284 .stats_min_voltage_unit
= SETTING_OSD_STATS_MIN_VOLTAGE_UNIT_DEFAULT
,
3285 .stats_page_auto_swap_time
= SETTING_OSD_STATS_PAGE_AUTO_SWAP_TIME_DEFAULT
3288 void pgResetFn_osdLayoutsConfig(osdLayoutsConfig_t
*osdLayoutsConfig
)
3290 osdLayoutsConfig
->item_pos
[0][OSD_ALTITUDE
] = OSD_POS(1, 0) | OSD_VISIBLE_FLAG
;
3291 osdLayoutsConfig
->item_pos
[0][OSD_MAIN_BATT_VOLTAGE
] = OSD_POS(12, 0) | OSD_VISIBLE_FLAG
;
3292 osdLayoutsConfig
->item_pos
[0][OSD_SAG_COMPENSATED_MAIN_BATT_VOLTAGE
] = OSD_POS(12, 1);
3294 osdLayoutsConfig
->item_pos
[0][OSD_RSSI_VALUE
] = OSD_POS(23, 0) | OSD_VISIBLE_FLAG
;
3296 osdLayoutsConfig
->item_pos
[0][OSD_HOME_DIST
] = OSD_POS(1, 1);
3297 osdLayoutsConfig
->item_pos
[0][OSD_TRIP_DIST
] = OSD_POS(1, 2);
3298 osdLayoutsConfig
->item_pos
[0][OSD_MAIN_BATT_CELL_VOLTAGE
] = OSD_POS(12, 1);
3299 osdLayoutsConfig
->item_pos
[0][OSD_MAIN_BATT_SAG_COMPENSATED_CELL_VOLTAGE
] = OSD_POS(12, 1);
3300 osdLayoutsConfig
->item_pos
[0][OSD_GPS_SPEED
] = OSD_POS(23, 1);
3301 osdLayoutsConfig
->item_pos
[0][OSD_3D_SPEED
] = OSD_POS(23, 1);
3302 osdLayoutsConfig
->item_pos
[0][OSD_GLIDESLOPE
] = OSD_POS(23, 2);
3304 osdLayoutsConfig
->item_pos
[0][OSD_THROTTLE_POS
] = OSD_POS(1, 2) | OSD_VISIBLE_FLAG
;
3305 osdLayoutsConfig
->item_pos
[0][OSD_THROTTLE_POS_AUTO_THR
] = OSD_POS(6, 2);
3306 osdLayoutsConfig
->item_pos
[0][OSD_HEADING
] = OSD_POS(12, 2);
3307 osdLayoutsConfig
->item_pos
[0][OSD_COURSE_HOLD_ERROR
] = OSD_POS(12, 2);
3308 osdLayoutsConfig
->item_pos
[0][OSD_COURSE_HOLD_ADJUSTMENT
] = OSD_POS(12, 2);
3309 osdLayoutsConfig
->item_pos
[0][OSD_HEADING_GRAPH
] = OSD_POS(18, 2);
3310 osdLayoutsConfig
->item_pos
[0][OSD_CURRENT_DRAW
] = OSD_POS(2, 3) | OSD_VISIBLE_FLAG
;
3311 osdLayoutsConfig
->item_pos
[0][OSD_MAH_DRAWN
] = OSD_POS(1, 4) | OSD_VISIBLE_FLAG
;
3312 osdLayoutsConfig
->item_pos
[0][OSD_WH_DRAWN
] = OSD_POS(1, 5);
3313 osdLayoutsConfig
->item_pos
[0][OSD_BATTERY_REMAINING_CAPACITY
] = OSD_POS(1, 6);
3314 osdLayoutsConfig
->item_pos
[0][OSD_BATTERY_REMAINING_PERCENT
] = OSD_POS(1, 7);
3315 osdLayoutsConfig
->item_pos
[0][OSD_POWER_SUPPLY_IMPEDANCE
] = OSD_POS(1, 8);
3317 osdLayoutsConfig
->item_pos
[0][OSD_EFFICIENCY_MAH_PER_KM
] = OSD_POS(1, 5);
3318 osdLayoutsConfig
->item_pos
[0][OSD_EFFICIENCY_WH_PER_KM
] = OSD_POS(1, 5);
3320 osdLayoutsConfig
->item_pos
[0][OSD_ATTITUDE_ROLL
] = OSD_POS(1, 7);
3321 osdLayoutsConfig
->item_pos
[0][OSD_ATTITUDE_PITCH
] = OSD_POS(1, 8);
3323 // avoid OSD_VARIO under OSD_CROSSHAIRS
3324 osdLayoutsConfig
->item_pos
[0][OSD_VARIO
] = OSD_POS(23, 5);
3325 // OSD_VARIO_NUM at the right of OSD_VARIO
3326 osdLayoutsConfig
->item_pos
[0][OSD_VARIO_NUM
] = OSD_POS(24, 7);
3327 osdLayoutsConfig
->item_pos
[0][OSD_HOME_DIR
] = OSD_POS(14, 11);
3328 osdLayoutsConfig
->item_pos
[0][OSD_ARTIFICIAL_HORIZON
] = OSD_POS(8, 6);
3329 osdLayoutsConfig
->item_pos
[0][OSD_HORIZON_SIDEBARS
] = OSD_POS(8, 6);
3331 osdLayoutsConfig
->item_pos
[0][OSD_CRAFT_NAME
] = OSD_POS(20, 2);
3332 osdLayoutsConfig
->item_pos
[0][OSD_VTX_CHANNEL
] = OSD_POS(8, 6);
3334 #ifdef USE_SERIALRX_CRSF
3335 osdLayoutsConfig
->item_pos
[0][OSD_CRSF_RSSI_DBM
] = OSD_POS(23, 12);
3336 osdLayoutsConfig
->item_pos
[0][OSD_CRSF_LQ
] = OSD_POS(23, 11);
3337 osdLayoutsConfig
->item_pos
[0][OSD_CRSF_SNR_DB
] = OSD_POS(24, 9);
3338 osdLayoutsConfig
->item_pos
[0][OSD_CRSF_TX_POWER
] = OSD_POS(24, 10);
3341 osdLayoutsConfig
->item_pos
[0][OSD_ONTIME
] = OSD_POS(23, 8);
3342 osdLayoutsConfig
->item_pos
[0][OSD_FLYTIME
] = OSD_POS(23, 9);
3343 osdLayoutsConfig
->item_pos
[0][OSD_ONTIME_FLYTIME
] = OSD_POS(23, 11) | OSD_VISIBLE_FLAG
;
3344 osdLayoutsConfig
->item_pos
[0][OSD_RTC_TIME
] = OSD_POS(23, 12);
3345 osdLayoutsConfig
->item_pos
[0][OSD_REMAINING_FLIGHT_TIME_BEFORE_RTH
] = OSD_POS(23, 7);
3346 osdLayoutsConfig
->item_pos
[0][OSD_REMAINING_DISTANCE_BEFORE_RTH
] = OSD_POS(23, 6);
3348 osdLayoutsConfig
->item_pos
[0][OSD_MISSION
] = OSD_POS(0, 10);
3349 osdLayoutsConfig
->item_pos
[0][OSD_GPS_SATS
] = OSD_POS(0, 11) | OSD_VISIBLE_FLAG
;
3350 osdLayoutsConfig
->item_pos
[0][OSD_GPS_HDOP
] = OSD_POS(0, 10);
3352 osdLayoutsConfig
->item_pos
[0][OSD_GPS_LAT
] = OSD_POS(0, 12);
3353 // Put this on top of the latitude, since it's very unlikely
3354 // that users will want to use both at the same time.
3355 osdLayoutsConfig
->item_pos
[0][OSD_PLUS_CODE
] = OSD_POS(0, 12);
3356 osdLayoutsConfig
->item_pos
[0][OSD_FLYMODE
] = OSD_POS(13, 12) | OSD_VISIBLE_FLAG
;
3357 osdLayoutsConfig
->item_pos
[0][OSD_GPS_LON
] = OSD_POS(18, 12);
3359 osdLayoutsConfig
->item_pos
[0][OSD_AZIMUTH
] = OSD_POS(2, 12);
3361 osdLayoutsConfig
->item_pos
[0][OSD_ROLL_PIDS
] = OSD_POS(2, 10);
3362 osdLayoutsConfig
->item_pos
[0][OSD_PITCH_PIDS
] = OSD_POS(2, 11);
3363 osdLayoutsConfig
->item_pos
[0][OSD_YAW_PIDS
] = OSD_POS(2, 12);
3364 osdLayoutsConfig
->item_pos
[0][OSD_LEVEL_PIDS
] = OSD_POS(2, 12);
3365 osdLayoutsConfig
->item_pos
[0][OSD_POS_XY_PIDS
] = OSD_POS(2, 12);
3366 osdLayoutsConfig
->item_pos
[0][OSD_POS_Z_PIDS
] = OSD_POS(2, 12);
3367 osdLayoutsConfig
->item_pos
[0][OSD_VEL_XY_PIDS
] = OSD_POS(2, 12);
3368 osdLayoutsConfig
->item_pos
[0][OSD_VEL_Z_PIDS
] = OSD_POS(2, 12);
3369 osdLayoutsConfig
->item_pos
[0][OSD_HEADING_P
] = OSD_POS(2, 12);
3370 osdLayoutsConfig
->item_pos
[0][OSD_BOARD_ALIGN_ROLL
] = OSD_POS(2, 10);
3371 osdLayoutsConfig
->item_pos
[0][OSD_BOARD_ALIGN_PITCH
] = OSD_POS(2, 11);
3372 osdLayoutsConfig
->item_pos
[0][OSD_RC_EXPO
] = OSD_POS(2, 12);
3373 osdLayoutsConfig
->item_pos
[0][OSD_RC_YAW_EXPO
] = OSD_POS(2, 12);
3374 osdLayoutsConfig
->item_pos
[0][OSD_THROTTLE_EXPO
] = OSD_POS(2, 12);
3375 osdLayoutsConfig
->item_pos
[0][OSD_PITCH_RATE
] = OSD_POS(2, 12);
3376 osdLayoutsConfig
->item_pos
[0][OSD_ROLL_RATE
] = OSD_POS(2, 12);
3377 osdLayoutsConfig
->item_pos
[0][OSD_YAW_RATE
] = OSD_POS(2, 12);
3378 osdLayoutsConfig
->item_pos
[0][OSD_MANUAL_RC_EXPO
] = OSD_POS(2, 12);
3379 osdLayoutsConfig
->item_pos
[0][OSD_MANUAL_RC_YAW_EXPO
] = OSD_POS(2, 12);
3380 osdLayoutsConfig
->item_pos
[0][OSD_MANUAL_PITCH_RATE
] = OSD_POS(2, 12);
3381 osdLayoutsConfig
->item_pos
[0][OSD_MANUAL_ROLL_RATE
] = OSD_POS(2, 12);
3382 osdLayoutsConfig
->item_pos
[0][OSD_MANUAL_YAW_RATE
] = OSD_POS(2, 12);
3383 osdLayoutsConfig
->item_pos
[0][OSD_NAV_FW_CRUISE_THR
] = OSD_POS(2, 12);
3384 osdLayoutsConfig
->item_pos
[0][OSD_NAV_FW_PITCH2THR
] = OSD_POS(2, 12);
3385 osdLayoutsConfig
->item_pos
[0][OSD_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE
] = OSD_POS(2, 12);
3386 osdLayoutsConfig
->item_pos
[0][OSD_FW_ALT_PID_OUTPUTS
] = OSD_POS(2, 12);
3387 osdLayoutsConfig
->item_pos
[0][OSD_FW_POS_PID_OUTPUTS
] = OSD_POS(2, 12);
3388 osdLayoutsConfig
->item_pos
[0][OSD_MC_VEL_X_PID_OUTPUTS
] = OSD_POS(2, 12);
3389 osdLayoutsConfig
->item_pos
[0][OSD_MC_VEL_Y_PID_OUTPUTS
] = OSD_POS(2, 12);
3390 osdLayoutsConfig
->item_pos
[0][OSD_MC_VEL_Z_PID_OUTPUTS
] = OSD_POS(2, 12);
3391 osdLayoutsConfig
->item_pos
[0][OSD_MC_POS_XYZ_P_OUTPUTS
] = OSD_POS(2, 12);
3393 osdLayoutsConfig
->item_pos
[0][OSD_POWER
] = OSD_POS(15, 1);
3395 osdLayoutsConfig
->item_pos
[0][OSD_IMU_TEMPERATURE
] = OSD_POS(19, 2);
3396 osdLayoutsConfig
->item_pos
[0][OSD_BARO_TEMPERATURE
] = OSD_POS(19, 3);
3397 osdLayoutsConfig
->item_pos
[0][OSD_TEMP_SENSOR_0_TEMPERATURE
] = OSD_POS(19, 4);
3398 osdLayoutsConfig
->item_pos
[0][OSD_TEMP_SENSOR_1_TEMPERATURE
] = OSD_POS(19, 5);
3399 osdLayoutsConfig
->item_pos
[0][OSD_TEMP_SENSOR_2_TEMPERATURE
] = OSD_POS(19, 6);
3400 osdLayoutsConfig
->item_pos
[0][OSD_TEMP_SENSOR_3_TEMPERATURE
] = OSD_POS(19, 7);
3401 osdLayoutsConfig
->item_pos
[0][OSD_TEMP_SENSOR_4_TEMPERATURE
] = OSD_POS(19, 8);
3402 osdLayoutsConfig
->item_pos
[0][OSD_TEMP_SENSOR_5_TEMPERATURE
] = OSD_POS(19, 9);
3403 osdLayoutsConfig
->item_pos
[0][OSD_TEMP_SENSOR_6_TEMPERATURE
] = OSD_POS(19, 10);
3404 osdLayoutsConfig
->item_pos
[0][OSD_TEMP_SENSOR_7_TEMPERATURE
] = OSD_POS(19, 11);
3406 osdLayoutsConfig
->item_pos
[0][OSD_AIR_SPEED
] = OSD_POS(3, 5);
3407 osdLayoutsConfig
->item_pos
[0][OSD_WIND_SPEED_HORIZONTAL
] = OSD_POS(3, 6);
3408 osdLayoutsConfig
->item_pos
[0][OSD_WIND_SPEED_VERTICAL
] = OSD_POS(3, 7);
3410 osdLayoutsConfig
->item_pos
[0][OSD_GFORCE
] = OSD_POS(12, 4);
3411 osdLayoutsConfig
->item_pos
[0][OSD_GFORCE_X
] = OSD_POS(12, 5);
3412 osdLayoutsConfig
->item_pos
[0][OSD_GFORCE_Y
] = OSD_POS(12, 6);
3413 osdLayoutsConfig
->item_pos
[0][OSD_GFORCE_Z
] = OSD_POS(12, 7);
3415 osdLayoutsConfig
->item_pos
[0][OSD_VTX_POWER
] = OSD_POS(3, 5);
3417 osdLayoutsConfig
->item_pos
[0][OSD_GVAR_0
] = OSD_POS(1, 1);
3418 osdLayoutsConfig
->item_pos
[0][OSD_GVAR_1
] = OSD_POS(1, 2);
3419 osdLayoutsConfig
->item_pos
[0][OSD_GVAR_2
] = OSD_POS(1, 3);
3420 osdLayoutsConfig
->item_pos
[0][OSD_GVAR_3
] = OSD_POS(1, 4);
3422 osdLayoutsConfig
->item_pos
[0][OSD_SWITCH_INDICATOR_0
] = OSD_POS(2, 7);
3423 osdLayoutsConfig
->item_pos
[0][OSD_SWITCH_INDICATOR_1
] = OSD_POS(2, 8);
3424 osdLayoutsConfig
->item_pos
[0][OSD_SWITCH_INDICATOR_2
] = OSD_POS(2, 9);
3425 osdLayoutsConfig
->item_pos
[0][OSD_SWITCH_INDICATOR_3
] = OSD_POS(2, 10);
3427 #if defined(USE_ESC_SENSOR)
3428 osdLayoutsConfig
->item_pos
[0][OSD_ESC_RPM
] = OSD_POS(1, 2);
3429 osdLayoutsConfig
->item_pos
[0][OSD_ESC_TEMPERATURE
] = OSD_POS(1, 3);
3432 #if defined(USE_RX_MSP) && defined(USE_MSP_RC_OVERRIDE)
3433 osdLayoutsConfig
->item_pos
[0][OSD_RC_SOURCE
] = OSD_POS(3, 4);
3436 #ifdef USE_POWER_LIMITS
3437 osdLayoutsConfig
->item_pos
[0][OSD_PLIMIT_REMAINING_BURST_TIME
] = OSD_POS(3, 4);
3438 osdLayoutsConfig
->item_pos
[0][OSD_PLIMIT_ACTIVE_CURRENT_LIMIT
] = OSD_POS(3, 5);
3439 osdLayoutsConfig
->item_pos
[0][OSD_PLIMIT_ACTIVE_POWER_LIMIT
] = OSD_POS(3, 6);
3442 // Under OSD_FLYMODE. TODO: Might not be visible on NTSC?
3443 osdLayoutsConfig
->item_pos
[0][OSD_MESSAGES
] = OSD_POS(1, 13) | OSD_VISIBLE_FLAG
;
3445 for (unsigned ii
= 1; ii
< OSD_LAYOUT_COUNT
; ii
++) {
3446 for (unsigned jj
= 0; jj
< ARRAYLEN(osdLayoutsConfig
->item_pos
[0]); jj
++) {
3447 osdLayoutsConfig
->item_pos
[ii
][jj
] = osdLayoutsConfig
->item_pos
[0][jj
] & ~OSD_VISIBLE_FLAG
;
3452 static void osdSetNextRefreshIn(uint32_t timeMs
) {
3453 resumeRefreshAt
= micros() + timeMs
* 1000;
3454 refreshWaitForResumeCmdRelease
= true;
3457 static void osdCompleteAsyncInitialization(void)
3459 if (!displayIsReady(osdDisplayPort
)) {
3460 // Update the display.
3461 // XXX: Rename displayDrawScreen() and associated functions
3462 // to displayUpdate()
3463 displayDrawScreen(osdDisplayPort
);
3467 osdDisplayIsReady
= true;
3469 #if defined(USE_CANVAS)
3470 if (osdConfig()->force_grid
) {
3471 osdDisplayHasCanvas
= false;
3473 osdDisplayHasCanvas
= displayGetCanvas(&osdCanvas
, osdDisplayPort
);
3477 displayBeginTransaction(osdDisplayPort
, DISPLAY_TRANSACTION_OPT_RESET_DRAWING
);
3478 displayClearScreen(osdDisplayPort
);
3481 displayFontMetadata_t metadata
;
3482 bool fontHasMetadata
= displayGetFontMetadata(&metadata
, osdDisplayPort
);
3483 LOG_D(OSD
, "Font metadata version %s: %u (%u chars)",
3484 fontHasMetadata
? "Y" : "N", metadata
.version
, metadata
.charCount
);
3486 if (fontHasMetadata
&& metadata
.charCount
> 256) {
3487 hasExtendedFont
= true;
3488 unsigned logo_c
= SYM_LOGO_START
;
3489 unsigned logo_x
= OSD_CENTER_LEN(SYM_LOGO_WIDTH
);
3490 for (unsigned ii
= 0; ii
< SYM_LOGO_HEIGHT
; ii
++) {
3491 for (unsigned jj
= 0; jj
< SYM_LOGO_WIDTH
; jj
++) {
3492 displayWriteChar(osdDisplayPort
, logo_x
+ jj
, y
, logo_c
++);
3497 } else if (!fontHasMetadata
) {
3498 const char *m
= "INVALID FONT";
3499 displayWrite(osdDisplayPort
, OSD_CENTER_S(m
), 3, m
);
3503 if (fontHasMetadata
&& metadata
.version
< OSD_MIN_FONT_VERSION
) {
3504 const char *m
= "INVALID FONT VERSION";
3505 displayWrite(osdDisplayPort
, OSD_CENTER_S(m
), y
++, m
);
3508 char string_buffer
[30];
3509 tfp_sprintf(string_buffer
, "INAV VERSION: %s", FC_VERSION_STRING
);
3510 displayWrite(osdDisplayPort
, 5, y
++, string_buffer
);
3512 displayWrite(osdDisplayPort
, 7, y
++, CMS_STARTUP_HELP_TEXT1
);
3513 displayWrite(osdDisplayPort
, 11, y
++, CMS_STARTUP_HELP_TEXT2
);
3514 displayWrite(osdDisplayPort
, 11, y
++, CMS_STARTUP_HELP_TEXT3
);
3518 #define STATS_LABEL_X_POS 4
3519 #define STATS_VALUE_X_POS 24
3520 if (statsConfig()->stats_enabled
) {
3521 displayWrite(osdDisplayPort
, STATS_LABEL_X_POS
, ++y
, "ODOMETER:");
3522 switch (osdConfig()->units
) {
3525 case OSD_UNIT_IMPERIAL
:
3526 tfp_sprintf(string_buffer
, "%5d", (int)(statsConfig()->stats_total_dist
/ METERS_PER_MILE
));
3527 string_buffer
[5] = SYM_MI
;
3531 tfp_sprintf(string_buffer
, "%5d", (int)(statsConfig()->stats_total_dist
/ METERS_PER_NAUTICALMILE
));
3532 string_buffer
[5] = SYM_NM
;
3534 case OSD_UNIT_METRIC_MPH
:
3536 case OSD_UNIT_METRIC
:
3537 tfp_sprintf(string_buffer
, "%5d", (int)(statsConfig()->stats_total_dist
/ METERS_PER_KILOMETER
));
3538 string_buffer
[5] = SYM_KM
;
3541 string_buffer
[6] = '\0';
3542 displayWrite(osdDisplayPort
, STATS_VALUE_X_POS
-5, y
, string_buffer
);
3544 displayWrite(osdDisplayPort
, STATS_LABEL_X_POS
, ++y
, "TOTAL TIME:");
3545 uint32_t tot_mins
= statsConfig()->stats_total_time
/ 60;
3546 tfp_sprintf(string_buffer
, "%2d:%02dHM", (int)(tot_mins
/ 60), (int)(tot_mins
% 60));
3547 displayWrite(osdDisplayPort
, STATS_VALUE_X_POS
-5, y
, string_buffer
);
3550 if (feature(FEATURE_VBAT
) && feature(FEATURE_CURRENT_METER
)) {
3551 displayWrite(osdDisplayPort
, STATS_LABEL_X_POS
, ++y
, "TOTAL ENERGY:");
3552 osdFormatCentiNumber(string_buffer
, statsConfig()->stats_total_energy
/ 10, 0, 2, 0, 4);
3553 strcat(string_buffer
, "\xAB"); // SYM_WH
3554 displayWrite(osdDisplayPort
, STATS_VALUE_X_POS
-4, y
, string_buffer
);
3556 displayWrite(osdDisplayPort
, STATS_LABEL_X_POS
, ++y
, "AVG EFFICIENCY:");
3557 if (statsConfig()->stats_total_dist
) {
3558 uint32_t avg_efficiency
= statsConfig()->stats_total_energy
/ (statsConfig()->stats_total_dist
/ METERS_PER_KILOMETER
); // mWh/km
3559 switch (osdConfig()->units
) {
3562 case OSD_UNIT_IMPERIAL
:
3563 osdFormatCentiNumber(string_buffer
, avg_efficiency
/ 10, 0, 2, 0, 3);
3564 string_buffer
[3] = SYM_WH_MI
;
3567 osdFormatCentiNumber(string_buffer
, avg_efficiency
/ 10, 0, 2, 0, 3);
3568 string_buffer
[3] = SYM_WH_NM
;
3571 case OSD_UNIT_METRIC_MPH
:
3573 case OSD_UNIT_METRIC
:
3574 osdFormatCentiNumber(string_buffer
, avg_efficiency
/ 10000 * METERS_PER_MILE
, 0, 2, 0, 3);
3575 string_buffer
[3] = SYM_WH_KM
;
3579 string_buffer
[0] = string_buffer
[1] = string_buffer
[2] = '-';
3581 string_buffer
[4] = '\0';
3582 displayWrite(osdDisplayPort
, STATS_VALUE_X_POS
-3, y
, string_buffer
);
3588 displayCommitTransaction(osdDisplayPort
);
3589 displayResync(osdDisplayPort
);
3590 osdSetNextRefreshIn(SPLASH_SCREEN_DISPLAY_TIME
);
3593 void osdInit(displayPort_t
*osdDisplayPortToUse
)
3595 if (!osdDisplayPortToUse
)
3598 BUILD_BUG_ON(OSD_POS_MAX
!= OSD_POS(31,31));
3600 osdDisplayPort
= osdDisplayPortToUse
;
3603 cmsDisplayPortRegister(osdDisplayPort
);
3606 armState
= ARMING_FLAG(ARMED
);
3607 osdCompleteAsyncInitialization();
3610 static void osdResetStats(void)
3612 stats
.max_current
= 0;
3613 stats
.max_power
= 0;
3614 stats
.max_speed
= 0;
3615 stats
.max_3D_speed
= 0;
3616 stats
.max_air_speed
= 0;
3617 stats
.min_voltage
= 5000;
3618 stats
.min_rssi
= 99;
3620 stats
.min_rssi_dbm
= 0;
3621 stats
.max_altitude
= 0;
3624 static void osdUpdateStats(void)
3628 if (feature(FEATURE_GPS
)) {
3629 value
= osdGet3DSpeed();
3630 if (stats
.max_3D_speed
< value
)
3631 stats
.max_3D_speed
= value
;
3633 if (stats
.max_speed
< gpsSol
.groundSpeed
)
3634 stats
.max_speed
= gpsSol
.groundSpeed
;
3636 if (stats
.max_air_speed
< pitot
.airSpeed
)
3637 stats
.max_air_speed
= pitot
.airSpeed
;
3639 if (stats
.max_distance
< GPS_distanceToHome
)
3640 stats
.max_distance
= GPS_distanceToHome
;
3643 value
= getBatteryVoltage();
3644 if (stats
.min_voltage
> value
)
3645 stats
.min_voltage
= value
;
3647 value
= abs(getAmperage());
3648 if (stats
.max_current
< value
)
3649 stats
.max_current
= value
;
3651 value
= labs(getPower());
3652 if (stats
.max_power
< value
)
3653 stats
.max_power
= value
;
3655 value
= osdConvertRSSI();
3656 if (stats
.min_rssi
> value
)
3657 stats
.min_rssi
= value
;
3659 value
= osdGetCrsfLQ();
3660 if (stats
.min_lq
> value
)
3661 stats
.min_lq
= value
;
3663 if (!failsafeIsReceivingRxData())
3666 value
= osdGetCrsfdBm();
3667 if (stats
.min_rssi_dbm
> value
)
3668 stats
.min_rssi_dbm
= value
;
3670 stats
.max_altitude
= MAX(stats
.max_altitude
, osdGetAltitude());
3673 static void osdShowStatsPage1(void)
3675 const char * disarmReasonStr
[DISARM_REASON_COUNT
] = { "UNKNOWN", "TIMEOUT", "STICKS", "SWITCH", "SWITCH", "KILLSW", "FAILSAFE", "NAV SYS" };
3676 uint8_t top
= 1; /* first fully visible line */
3677 const uint8_t statNameX
= 1;
3678 const uint8_t statValuesX
= 20;
3680 statsPagesCheck
= 1;
3682 displayBeginTransaction(osdDisplayPort
, DISPLAY_TRANSACTION_OPT_RESET_DRAWING
);
3683 displayClearScreen(osdDisplayPort
);
3685 displayWrite(osdDisplayPort
, statNameX
, top
++, "--- STATS --- 1/2 ->");
3687 if (feature(FEATURE_GPS
)) {
3688 displayWrite(osdDisplayPort
, statNameX
, top
, "MAX SPEED :");
3689 osdFormatVelocityStr(buff
, stats
.max_3D_speed
, true, false);
3690 osdLeftAlignString(buff
);
3691 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3693 displayWrite(osdDisplayPort
, statNameX
, top
, "AVG SPEED :");
3694 osdGenerateAverageVelocityStr(buff
);
3695 osdLeftAlignString(buff
);
3696 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3698 displayWrite(osdDisplayPort
, statNameX
, top
, "MAX DISTANCE :");
3699 osdFormatDistanceStr(buff
, stats
.max_distance
*100);
3700 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3702 displayWrite(osdDisplayPort
, statNameX
, top
, "TRAVELED DISTANCE:");
3703 osdFormatDistanceStr(buff
, getTotalTravelDistance());
3704 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3707 displayWrite(osdDisplayPort
, statNameX
, top
, "MAX ALTITUDE :");
3708 osdFormatAltitudeStr(buff
, stats
.max_altitude
);
3709 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3711 switch (rxConfig()->serialrx_provider
) {
3713 displayWrite(osdDisplayPort
, statNameX
, top
, "MIN RSSI % :");
3714 itoa(stats
.min_rssi
, buff
, 10);
3716 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3718 displayWrite(osdDisplayPort
, statNameX
, top
, "MIN RSSI DBM :");
3719 itoa(stats
.min_rssi_dbm
, buff
, 10);
3720 tfp_sprintf(buff
, "%s%c", buff
, SYM_DBM
);
3721 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3723 displayWrite(osdDisplayPort
, statNameX
, top
, "MIN LQ :");
3724 itoa(stats
.min_lq
, buff
, 10);
3726 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3729 displayWrite(osdDisplayPort
, statNameX
, top
, "MIN RSSI :");
3730 itoa(stats
.min_rssi
, buff
, 10);
3732 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3735 displayWrite(osdDisplayPort
, statNameX
, top
, "FLY TIME :");
3736 uint16_t flySeconds
= getFlightTime();
3737 uint16_t flyMinutes
= flySeconds
/ 60;
3739 uint16_t flyHours
= flyMinutes
/ 60;
3741 tfp_sprintf(buff
, "%02u:%02u:%02u", flyHours
, flyMinutes
, flySeconds
);
3742 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3744 displayWrite(osdDisplayPort
, statNameX
, top
, "DISARMED BY :");
3745 displayWrite(osdDisplayPort
, statValuesX
, top
++, disarmReasonStr
[getDisarmReason()]);
3746 displayCommitTransaction(osdDisplayPort
);
3749 static void osdShowStatsPage2(void)
3751 uint8_t top
= 1; /* first fully visible line */
3752 const uint8_t statNameX
= 1;
3753 const uint8_t statValuesX
= 20;
3755 statsPagesCheck
= 1;
3757 displayBeginTransaction(osdDisplayPort
, DISPLAY_TRANSACTION_OPT_RESET_DRAWING
);
3758 displayClearScreen(osdDisplayPort
);
3760 displayWrite(osdDisplayPort
, statNameX
, top
++, "--- STATS --- <- 2/2");
3762 if (osdConfig()->stats_min_voltage_unit
== OSD_STATS_MIN_VOLTAGE_UNIT_BATTERY
) {
3763 displayWrite(osdDisplayPort
, statNameX
, top
, "MIN BATTERY VOLT :");
3764 osdFormatCentiNumber(buff
, stats
.min_voltage
, 0, osdConfig()->main_voltage_decimals
, 0, osdConfig()->main_voltage_decimals
+ 2);
3766 displayWrite(osdDisplayPort
, statNameX
, top
, "MIN CELL VOLTAGE :");
3767 osdFormatCentiNumber(buff
, stats
.min_voltage
/getBatteryCellCount(), 0, 2, 0, 3);
3769 tfp_sprintf(buff
, "%s%c", buff
, SYM_VOLT
);
3770 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3772 if (feature(FEATURE_CURRENT_METER
)) {
3773 displayWrite(osdDisplayPort
, statNameX
, top
, "MAX CURRENT :");
3774 osdFormatCentiNumber(buff
, stats
.max_current
, 0, 2, 0, 3);
3775 tfp_sprintf(buff
, "%s%c", buff
, SYM_AMP
);
3776 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3778 displayWrite(osdDisplayPort
, statNameX
, top
, "MAX POWER :");
3779 bool kiloWatt
= osdFormatCentiNumber(buff
, stats
.max_power
, 1000, 2, 2, 3);
3780 buff
[3] = kiloWatt
? SYM_KILOWATT
: SYM_WATT
;
3782 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3784 displayWrite(osdDisplayPort
, statNameX
, top
, "USED CAPACITY :");
3785 if (osdConfig()->stats_energy_unit
== OSD_STATS_ENERGY_UNIT_MAH
) {
3786 tfp_sprintf(buff
, "%d%c", (int)getMAhDrawn(), SYM_MAH
);
3788 osdFormatCentiNumber(buff
, getMWhDrawn() / 10, 0, 2, 0, 3);
3789 tfp_sprintf(buff
, "%s%c", buff
, SYM_WH
);
3791 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3793 int32_t totalDistance
= getTotalTravelDistance();
3794 bool moreThanAh
= false;
3795 bool efficiencyValid
= totalDistance
>= 10000;
3796 if (feature(FEATURE_GPS
)) {
3797 displayWrite(osdDisplayPort
, statNameX
, top
, "AVG EFFICIENCY :");
3798 switch (osdConfig()->units
) {
3801 case OSD_UNIT_IMPERIAL
:
3802 if (osdConfig()->stats_energy_unit
== OSD_STATS_ENERGY_UNIT_MAH
) {
3803 moreThanAh
= osdFormatCentiNumber(buff
, (int32_t)(getMAhDrawn() * 10000.0f
* METERS_PER_MILE
/ totalDistance
), 1000, 0, 2, 3);
3805 tfp_sprintf(buff
, "%s%c%c", buff
, SYM_MAH_MI_0
, SYM_MAH_MI_1
);
3807 tfp_sprintf(buff
, "%s%c", buff
, SYM_AH_MI
);
3809 if (!efficiencyValid
) {
3810 buff
[0] = buff
[1] = buff
[2] = '-';
3811 buff
[3] = SYM_MAH_MI_0
;
3812 buff
[4] = SYM_MAH_MI_1
;
3816 osdFormatCentiNumber(buff
, (int32_t)(getMWhDrawn() * 10.0f
* METERS_PER_MILE
/ totalDistance
), 0, 2, 0, 3);
3817 tfp_sprintf(buff
, "%s%c", buff
, SYM_WH_MI
);
3818 if (!efficiencyValid
) {
3819 buff
[0] = buff
[1] = buff
[2] = '-';
3824 if (osdConfig()->stats_energy_unit
== OSD_STATS_ENERGY_UNIT_MAH
) {
3825 moreThanAh
= osdFormatCentiNumber(buff
, (int32_t)(getMAhDrawn() * 10000.0f
* METERS_PER_NAUTICALMILE
/ totalDistance
), 1000, 0, 2, 3);
3827 tfp_sprintf(buff
, "%s%c%c", buff
, SYM_MAH_NM_0
, SYM_MAH_NM_1
);
3829 tfp_sprintf(buff
, "%s%c", buff
, SYM_AH_NM
);
3831 if (!efficiencyValid
) {
3832 buff
[0] = buff
[1] = buff
[2] = '-';
3833 buff
[3] = SYM_MAH_NM_0
;
3834 buff
[4] = SYM_MAH_NM_1
;
3838 osdFormatCentiNumber(buff
, (int32_t)(getMWhDrawn() * 10.0f
* METERS_PER_NAUTICALMILE
/ totalDistance
), 0, 2, 0, 3);
3839 tfp_sprintf(buff
, "%s%c", buff
, SYM_WH_NM
);
3840 if (!efficiencyValid
) {
3841 buff
[0] = buff
[1] = buff
[2] = '-';
3845 case OSD_UNIT_METRIC_MPH
:
3847 case OSD_UNIT_METRIC
:
3848 if (osdConfig()->stats_energy_unit
== OSD_STATS_ENERGY_UNIT_MAH
) {
3849 moreThanAh
= osdFormatCentiNumber(buff
, (int32_t)(getMAhDrawn() * 10000000.0f
/ totalDistance
), 1000, 0, 2, 3);
3851 tfp_sprintf(buff
, "%s%c%c", buff
, SYM_MAH_KM_0
, SYM_MAH_KM_1
);
3853 tfp_sprintf(buff
, "%s%c", buff
, SYM_AH_KM
);
3855 if (!efficiencyValid
) {
3856 buff
[0] = buff
[1] = buff
[2] = '-';
3857 buff
[3] = SYM_MAH_KM_0
;
3858 buff
[4] = SYM_MAH_KM_1
;
3862 osdFormatCentiNumber(buff
, (int32_t)(getMWhDrawn() * 10000.0f
/ totalDistance
), 0, 2, 0, 3);
3863 tfp_sprintf(buff
, "%s%c", buff
, SYM_WH_KM
);
3864 if (!efficiencyValid
) {
3865 buff
[0] = buff
[1] = buff
[2] = '-';
3870 osdLeftAlignString(buff
);
3871 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3875 const float max_gforce
= accGetMeasuredMaxG();
3876 displayWrite(osdDisplayPort
, statNameX
, top
, "MAX G-FORCE :");
3877 osdFormatCentiNumber(buff
, max_gforce
* 100, 0, 2, 0, 3);
3878 displayWrite(osdDisplayPort
, statValuesX
, top
++, buff
);
3880 const acc_extremes_t
*acc_extremes
= accGetMeasuredExtremes();
3881 displayWrite(osdDisplayPort
, statNameX
, top
, "MIN/MAX Z G-FORCE:");
3882 osdFormatCentiNumber(buff
, acc_extremes
[Z
].min
* 100, 0, 2, 0, 4);
3884 displayWrite(osdDisplayPort
, statValuesX
- 1, top
, buff
);
3885 osdFormatCentiNumber(buff
, acc_extremes
[Z
].max
* 100, 0, 2, 0, 3);
3886 displayWrite(osdDisplayPort
, statValuesX
+ 4, top
++, buff
);
3887 displayCommitTransaction(osdDisplayPort
);
3890 // called when motors armed
3891 static void osdShowArmed(void)
3894 char buf
[MAX(32, FORMATTED_DATE_TIME_BUFSIZE
)];
3895 char craftNameBuf
[MAX_NAME_LENGTH
];
3896 char versionBuf
[30];
3899 // We need 12 visible rows, start row never < first fully visible row 1
3900 uint8_t y
= osdDisplayPort
->rows
> 13 ? (osdDisplayPort
->rows
- 12) / 2 : 1;
3902 displayClearScreen(osdDisplayPort
);
3903 displayWrite(osdDisplayPort
, 12, y
, "ARMED");
3906 if (strlen(systemConfig()->name
) > 0) {
3907 osdFormatCraftName(craftNameBuf
);
3908 displayWrite(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(systemConfig() -> name
)) / 2, y
, craftNameBuf
);
3911 if (posControl
.waypointListValid
&& posControl
.waypointCount
> 0) {
3912 #ifdef USE_MULTI_MISSION
3913 tfp_sprintf(buf
, "MISSION %u/%u (%u WP)", posControl
.loadedMultiMissionIndex
, posControl
.multiMissionCount
, posControl
.waypointCount
);
3914 displayWrite(osdDisplayPort
, 6, y
, buf
);
3916 displayWrite(osdDisplayPort
, 7, y
, "*MISSION LOADED*");
3921 #if defined(USE_GPS)
3922 if (feature(FEATURE_GPS
)) {
3923 if (STATE(GPS_FIX_HOME
)) {
3924 if (osdConfig()->osd_home_position_arm_screen
){
3925 osdFormatCoordinate(buf
, SYM_LAT
, GPS_home
.lat
);
3926 displayWrite(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(buf
)) / 2, y
, buf
);
3927 osdFormatCoordinate(buf
, SYM_LON
, GPS_home
.lon
);
3928 displayWrite(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(buf
)) / 2, y
+ 1, buf
);
3929 int digits
= osdConfig()->plus_code_digits
;
3930 olc_encode(GPS_home
.lat
, GPS_home
.lon
, digits
, buf
, sizeof(buf
));
3931 displayWrite(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(buf
)) / 2, y
+ 2, buf
);
3934 #if defined (USE_SAFE_HOME)
3935 if (safehome_distance
) { // safehome found during arming
3936 if (navConfig()->general
.flags
.safehome_usage_mode
== SAFEHOME_USAGE_OFF
) {
3937 strcpy(buf
, "SAFEHOME FOUND; MODE OFF");
3939 char buf2
[12]; // format the distance first
3940 osdFormatDistanceStr(buf2
, safehome_distance
);
3941 tfp_sprintf(buf
, "%c - %s -> SAFEHOME %u", SYM_HOME
, buf2
, safehome_index
);
3943 textAttributes_t elemAttr
= _TEXT_ATTRIBUTES_BLINK_BIT
;
3944 // write this message above the ARMED message to make it obvious
3945 displayWriteWithAttr(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(buf
)) / 2, y
- 8, buf
, elemAttr
);
3949 strcpy(buf
, "!NO HOME POSITION!");
3950 displayWrite(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(buf
)) / 2, y
, buf
);
3956 if (rtcGetDateTime(&dt
)) {
3957 dateTimeFormatLocal(buf
, &dt
);
3958 dateTimeSplitFormatted(buf
, &date
, &time
);
3960 displayWrite(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(date
)) / 2, y
, date
);
3961 displayWrite(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(time
)) / 2, y
+ 1, time
);
3965 tfp_sprintf(versionBuf
, "INAV VERSION: %s", FC_VERSION_STRING
);
3966 displayWrite(osdDisplayPort
, (osdDisplayPort
->cols
- strlen(versionBuf
)) / 2, y
, versionBuf
);
3969 static void osdFilterData(timeUs_t currentTimeUs
) {
3970 static timeUs_t lastRefresh
= 0;
3971 float refresh_dT
= US2S(cmpTimeUs(currentTimeUs
, lastRefresh
));
3973 GForce
= fast_fsqrtf(vectorNormSquared(&imuMeasuredAccelBF
)) / GRAVITY_MSS
;
3974 for (uint8_t axis
= 0; axis
< XYZ_AXIS_COUNT
; ++axis
) GForceAxis
[axis
] = imuMeasuredAccelBF
.v
[axis
] / GRAVITY_MSS
;
3977 GForce
= pt1FilterApply3(&GForceFilter
, GForce
, refresh_dT
);
3978 for (uint8_t axis
= 0; axis
< XYZ_AXIS_COUNT
; ++axis
) pt1FilterApply3(GForceFilterAxis
+ axis
, GForceAxis
[axis
], refresh_dT
);
3980 pt1FilterInitRC(&GForceFilter
, GFORCE_FILTER_TC
, 0);
3981 pt1FilterReset(&GForceFilter
, GForce
);
3983 for (uint8_t axis
= 0; axis
< XYZ_AXIS_COUNT
; ++axis
) {
3984 pt1FilterInitRC(GForceFilterAxis
+ axis
, GFORCE_FILTER_TC
, 0);
3985 pt1FilterReset(GForceFilterAxis
+ axis
, GForceAxis
[axis
]);
3989 lastRefresh
= currentTimeUs
;
3992 static void osdRefresh(timeUs_t currentTimeUs
)
3994 osdFilterData(currentTimeUs
);
3997 if (IS_RC_MODE_ACTIVE(BOXOSD
) && (!cmsInMenu
) && !(osdConfig()->osd_failsafe_switch_layout
&& FLIGHT_MODE(FAILSAFE_MODE
))) {
3999 if (IS_RC_MODE_ACTIVE(BOXOSD
) && !(osdConfig()->osd_failsafe_switch_layout
&& FLIGHT_MODE(FAILSAFE_MODE
))) {
4001 displayClearScreen(osdDisplayPort
);
4002 armState
= ARMING_FLAG(ARMED
);
4006 // detect arm/disarm
4007 static uint8_t statsPageAutoSwapCntl
= 2;
4008 if (armState
!= ARMING_FLAG(ARMED
)) {
4009 if (ARMING_FLAG(ARMED
)) {
4011 statsPageAutoSwapCntl
= 2;
4012 osdShowArmed(); // reset statistic etc
4013 uint32_t delay
= ARMED_SCREEN_DISPLAY_TIME
;
4014 statsPagesCheck
= 0;
4015 #if defined(USE_SAFE_HOME)
4016 if (safehome_distance
)
4019 osdSetNextRefreshIn(delay
);
4021 osdShowStatsPage1(); // show first page of statistics
4022 osdSetNextRefreshIn(STATS_SCREEN_DISPLAY_TIME
);
4023 statsPageAutoSwapCntl
= osdConfig()->stats_page_auto_swap_time
> 0 ? 0 : 2; // disable swapping pages when time = 0
4026 armState
= ARMING_FLAG(ARMED
);
4029 if (resumeRefreshAt
) {
4030 // If we already reached he time for the next refresh,
4031 // or THR is high or PITCH is high, resume refreshing.
4032 // Clear the screen first to erase other elements which
4033 // might have been drawn while the OSD wasn't refreshing.
4035 // auto swap stats pages when first shown
4036 // auto swap cancelled using roll stick
4037 if (statsPageAutoSwapCntl
!= 2) {
4038 if (STATS_PAGE1
|| STATS_PAGE2
) {
4039 statsPageAutoSwapCntl
= 2;
4041 if (OSD_ALTERNATING_CHOICES((osdConfig()->stats_page_auto_swap_time
* 1000), 2)) {
4042 if (statsPageAutoSwapCntl
== 0) {
4043 osdShowStatsPage1();
4044 statsPageAutoSwapCntl
= 1;
4047 if (statsPageAutoSwapCntl
== 1) {
4048 osdShowStatsPage2();
4049 statsPageAutoSwapCntl
= 0;
4055 if (!DELAYED_REFRESH_RESUME_COMMAND
)
4056 refreshWaitForResumeCmdRelease
= false;
4058 if ((currentTimeUs
> resumeRefreshAt
) || ((!refreshWaitForResumeCmdRelease
) && DELAYED_REFRESH_RESUME_COMMAND
)) {
4059 displayClearScreen(osdDisplayPort
);
4060 resumeRefreshAt
= 0;
4061 } else if ((currentTimeUs
> resumeRefreshAt
) || ((!refreshWaitForResumeCmdRelease
) && STATS_PAGE1
)) {
4062 if (statsPagesCheck
== 1) {
4063 osdShowStatsPage1();
4065 } else if ((currentTimeUs
> resumeRefreshAt
) || ((!refreshWaitForResumeCmdRelease
) && STATS_PAGE2
)) {
4066 if (statsPagesCheck
== 1) {
4067 osdShowStatsPage2();
4070 displayHeartbeat(osdDisplayPort
);
4076 if (!displayIsGrabbed(osdDisplayPort
)) {
4077 displayBeginTransaction(osdDisplayPort
, DISPLAY_TRANSACTION_OPT_RESET_DRAWING
);
4079 displayClearScreen(osdDisplayPort
);
4082 osdDrawNextElement();
4083 displayHeartbeat(osdDisplayPort
);
4084 displayCommitTransaction(osdDisplayPort
);
4085 #ifdef OSD_CALLS_CMS
4087 cmsUpdate(currentTimeUs
);
4094 * Called periodically by the scheduler
4096 void osdUpdate(timeUs_t currentTimeUs
)
4098 static uint32_t counter
= 0;
4100 // don't touch buffers if DMA transaction is in progress
4101 if (displayIsTransferInProgress(osdDisplayPort
)) {
4105 if (!osdDisplayIsReady
) {
4106 osdCompleteAsyncInitialization();
4110 #if defined(OSD_ALTERNATE_LAYOUT_COUNT) && OSD_ALTERNATE_LAYOUT_COUNT > 0
4111 // Check if the layout has changed. Higher numbered
4112 // boxes take priority.
4113 unsigned activeLayout
;
4114 if (layoutOverride
>= 0) {
4115 activeLayout
= layoutOverride
;
4116 // Check for timed override, it will go into effect on
4117 // the next OSD iteration
4118 if (layoutOverrideUntil
> 0 && millis() > layoutOverrideUntil
) {
4119 layoutOverrideUntil
= 0;
4120 layoutOverride
= -1;
4122 } else if (osdConfig()->osd_failsafe_switch_layout
&& FLIGHT_MODE(FAILSAFE_MODE
)) {
4125 #if OSD_ALTERNATE_LAYOUT_COUNT > 2
4126 if (IS_RC_MODE_ACTIVE(BOXOSDALT3
))
4130 #if OSD_ALTERNATE_LAYOUT_COUNT > 1
4131 if (IS_RC_MODE_ACTIVE(BOXOSDALT2
))
4135 if (IS_RC_MODE_ACTIVE(BOXOSDALT1
))
4138 #ifdef USE_PROGRAMMING_FRAMEWORK
4139 if (LOGIC_CONDITION_GLOBAL_FLAG(LOGIC_CONDITION_GLOBAL_FLAG_OVERRIDE_OSD_LAYOUT
))
4140 activeLayout
= constrain(logicConditionValuesByType
[LOGIC_CONDITION_SET_OSD_LAYOUT
], 0, OSD_ALTERNATE_LAYOUT_COUNT
);
4145 if (currentLayout
!= activeLayout
) {
4146 currentLayout
= activeLayout
;
4147 osdStartFullRedraw();
4151 #define DRAW_FREQ_DENOM 4
4152 #define STATS_FREQ_DENOM 50
4155 if ((counter
% STATS_FREQ_DENOM
) == 0) {
4159 if ((counter
& DRAW_FREQ_DENOM
) == 0) {
4160 // redraw values in buffer
4161 osdRefresh(currentTimeUs
);
4163 // rest of time redraw screen
4164 displayDrawScreen(osdDisplayPort
);
4168 // do not allow ARM if we are in menu
4169 if (displayIsGrabbed(osdDisplayPort
)) {
4170 ENABLE_ARMING_FLAG(ARMING_DISABLED_OSD_MENU
);
4172 DISABLE_ARMING_FLAG(ARMING_DISABLED_OSD_MENU
);
4177 void osdStartFullRedraw(void)
4182 void osdOverrideLayout(int layout
, timeMs_t duration
)
4184 layoutOverride
= constrain(layout
, -1, ARRAYLEN(osdLayoutsConfig()->item_pos
) - 1);
4185 if (layoutOverride
>= 0 && duration
> 0) {
4186 layoutOverrideUntil
= millis() + duration
;
4188 layoutOverrideUntil
= 0;
4192 int osdGetActiveLayout(bool *overridden
)
4195 *overridden
= layoutOverride
>= 0;
4197 return currentLayout
;
4200 bool osdItemIsFixed(osd_items_e item
)
4202 return item
== OSD_CROSSHAIRS
||
4203 item
== OSD_ARTIFICIAL_HORIZON
||
4204 item
== OSD_HORIZON_SIDEBARS
;
4207 displayPort_t
*osdGetDisplayPort(void)
4209 return osdDisplayPort
;
4212 displayCanvas_t
*osdGetDisplayPortCanvas(void)
4214 #if defined(USE_CANVAS)
4215 if (osdDisplayHasCanvas
) {
4222 textAttributes_t
osdGetSystemMessage(char *buff
, size_t buff_size
, bool isCenteredText
)
4224 textAttributes_t elemAttr
= TEXT_ATTRIBUTES_NONE
;
4227 const char *message
= NULL
;
4228 char messageBuf
[MAX(SETTING_MAX_NAME_LENGTH
, OSD_MESSAGE_LENGTH
+1)];
4229 // We might have up to 5 messages to show.
4230 const char *messages
[5];
4231 unsigned messageCount
= 0;
4232 const char *failsafeInfoMessage
= NULL
;
4233 const char *invertedInfoMessage
= NULL
;
4235 if (ARMING_FLAG(ARMED
)) {
4236 if (FLIGHT_MODE(FAILSAFE_MODE
) || FLIGHT_MODE(NAV_RTH_MODE
) || FLIGHT_MODE(NAV_WP_MODE
) || navigationIsExecutingAnEmergencyLanding()) {
4237 if (isWaypointMissionRTHActive()) {
4238 // if RTH activated whilst WP mode selected, remind pilot to cancel WP mode to exit RTH
4239 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_WP_RTH_CANCEL
);
4241 if (navGetCurrentStateFlags() & NAV_AUTO_WP_DONE
) {
4242 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_WP_FINISHED
);
4243 } else if (NAV_Status
.state
== MW_NAV_STATE_WP_ENROUTE
) {
4244 // Countdown display for remaining Waypoints
4246 osdFormatDistanceSymbol(buf
, posControl
.wpDistance
, 0);
4247 tfp_sprintf(messageBuf
, "TO WP %u/%u (%s)", getGeoWaypointNumber(posControl
.activeWaypointIndex
), posControl
.geoWaypointCount
, buf
);
4248 messages
[messageCount
++] = messageBuf
;
4249 } else if (NAV_Status
.state
== MW_NAV_STATE_HOLD_TIMED
) {
4250 // WP hold time countdown in seconds
4251 timeMs_t currentTime
= millis();
4252 int holdTimeRemaining
= posControl
.waypointList
[posControl
.activeWaypointIndex
].p1
- (int)((currentTime
- posControl
.wpReachedTime
)/1000);
4253 if (holdTimeRemaining
>=0) {
4254 tfp_sprintf(messageBuf
, "HOLDING WP FOR %2u S", holdTimeRemaining
);
4256 messages
[messageCount
++] = messageBuf
;
4258 const char *navStateMessage
= navigationStateMessage();
4259 if (navStateMessage
) {
4260 messages
[messageCount
++] = navStateMessage
;
4263 #if defined(USE_SAFE_HOME)
4264 const char *safehomeMessage
= divertingToSafehomeMessage();
4265 if (safehomeMessage
) {
4266 messages
[messageCount
++] = safehomeMessage
;
4269 if (FLIGHT_MODE(FAILSAFE_MODE
)) {
4270 // In FS mode while being armed too
4271 const char *failsafePhaseMessage
= osdFailsafePhaseMessage();
4272 failsafeInfoMessage
= osdFailsafeInfoMessage();
4274 if (failsafePhaseMessage
) {
4275 messages
[messageCount
++] = failsafePhaseMessage
;
4277 if (failsafeInfoMessage
) {
4278 messages
[messageCount
++] = failsafeInfoMessage
;
4281 } else { /* messages shown only when Failsafe, WP, RTH or Emergency Landing not active */
4282 if (STATE(FIXED_WING_LEGACY
) && (navGetCurrentStateFlags() & NAV_CTL_LAUNCH
)) {
4283 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_AUTOLAUNCH
);
4284 const char *launchStateMessage
= fixedWingLaunchStateMessage();
4285 if (launchStateMessage
) {
4286 messages
[messageCount
++] = launchStateMessage
;
4289 if (FLIGHT_MODE(NAV_ALTHOLD_MODE
) && !navigationRequiresAngleMode()) {
4290 // ALTHOLD might be enabled alongside ANGLE/HORIZON/ACRO
4291 // when it doesn't require ANGLE mode (required only in FW
4292 // right now). If if requires ANGLE, its display is handled
4294 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_ALTITUDE_HOLD
);
4296 if (IS_RC_MODE_ACTIVE(BOXAUTOTRIM
) && !feature(FEATURE_FW_AUTOTRIM
)) {
4297 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_AUTOTRIM
);
4299 if (IS_RC_MODE_ACTIVE(BOXAUTOTUNE
)) {
4300 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_AUTOTUNE
);
4301 if (FLIGHT_MODE(MANUAL_MODE
)) {
4302 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_AUTOTUNE_ACRO
);
4305 if (FLIGHT_MODE(HEADFREE_MODE
)) {
4306 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_HEADFREE
);
4308 if (FLIGHT_MODE(SOARING_MODE
)) {
4309 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_NAV_SOARING
);
4311 if (posControl
.flags
.wpMissionPlannerActive
) {
4312 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_MISSION_PLANNER
);
4316 } else if (ARMING_FLAG(ARMING_DISABLED_ALL_FLAGS
)) {
4317 unsigned invalidIndex
;
4319 // Check if we're unable to arm for some reason
4320 if (ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING
) && !settingsValidate(&invalidIndex
)) {
4322 const setting_t
*setting
= settingGet(invalidIndex
);
4323 settingGetName(setting
, messageBuf
);
4324 for (int ii
= 0; messageBuf
[ii
]; ii
++) {
4325 messageBuf
[ii
] = sl_toupper(messageBuf
[ii
]);
4327 invertedInfoMessage
= messageBuf
;
4328 messages
[messageCount
++] = invertedInfoMessage
;
4330 invertedInfoMessage
= OSD_MESSAGE_STR(OSD_MSG_INVALID_SETTING
);
4331 messages
[messageCount
++] = invertedInfoMessage
;
4335 invertedInfoMessage
= OSD_MESSAGE_STR(OSD_MSG_UNABLE_ARM
);
4336 messages
[messageCount
++] = invertedInfoMessage
;
4338 // Show the reason for not arming
4339 messages
[messageCount
++] = osdArmingDisabledReasonMessage();
4342 } else if (!ARMING_FLAG(ARMED
)) {
4343 if (isWaypointListValid()) {
4344 messages
[messageCount
++] = OSD_MESSAGE_STR(OSD_MSG_WP_MISSION_LOADED
);
4348 if (messageCount
> 0) {
4349 message
= messages
[OSD_ALTERNATING_CHOICES(1000, messageCount
)];
4350 if (message
== failsafeInfoMessage
) {
4351 // failsafeInfoMessage is not useful for recovering
4352 // a lost model, but might help avoiding a crash.
4353 // Blink to grab user attention.
4354 TEXT_ATTRIBUTES_ADD_BLINK(elemAttr
);
4355 } else if (message
== invertedInfoMessage
) {
4356 TEXT_ATTRIBUTES_ADD_INVERTED(elemAttr
);
4358 // We're shoing either failsafePhaseMessage or
4359 // navStateMessage. Don't BLINK here since
4360 // having this text available might be crucial
4361 // during a lost aircraft recovery and blinking
4362 // will cause it to be missing from some frames.
4365 osdFormatMessage(buff
, buff_size
, message
, isCenteredText
);