Fixes from review
[betaflight.git] / src / main / io / osd.h
blobb1fcdb0832cae0690701e04abf99f4fcf3c33edd
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "common/time.h"
24 #include "pg/pg.h"
26 #define OSD_NUM_TIMER_TYPES 3
27 extern const char * const osdTimerSourceNames[OSD_NUM_TIMER_TYPES];
29 #define OSD_ELEMENT_BUFFER_LENGTH 32
31 #define VISIBLE_FLAG 0x0800
32 #define VISIBLE(x) (x & VISIBLE_FLAG)
33 #define OSD_POS_MAX 0x3FF
34 #define OSD_POSCFG_MAX (VISIBLE_FLAG|0x3FF) // For CLI values
36 // Character coordinate
37 #define OSD_POSITION_BITS 5 // 5 bits gives a range 0-31
38 #define OSD_POSITION_XY_MASK ((1 << OSD_POSITION_BITS) - 1)
39 #define OSD_POS(x,y) ((x & OSD_POSITION_XY_MASK) | ((y & OSD_POSITION_XY_MASK) << OSD_POSITION_BITS))
40 #define OSD_X(x) (x & OSD_POSITION_XY_MASK)
41 #define OSD_Y(x) ((x >> OSD_POSITION_BITS) & OSD_POSITION_XY_MASK)
43 // Timer configuration
44 // Stored as 15[alarm:8][precision:4][source:4]0
45 #define OSD_TIMER(src, prec, alarm) ((src & 0x0F) | ((prec & 0x0F) << 4) | ((alarm & 0xFF ) << 8))
46 #define OSD_TIMER_SRC(timer) (timer & 0x0F)
47 #define OSD_TIMER_PRECISION(timer) ((timer >> 4) & 0x0F)
48 #define OSD_TIMER_ALARM(timer) ((timer >> 8) & 0xFF)
50 // NB: to ensure backwards compatibility, new enum values must be appended at the end but before the OSD_XXXX_COUNT entry.
52 // *** IMPORTANT ***
53 // If you are adding additional elements that do not require any conditional display logic,
54 // you must add the elements to the osdElementDisplayOrder[] array in src/main/io/osd.c
55 typedef enum {
56 OSD_RSSI_VALUE,
57 OSD_MAIN_BATT_VOLTAGE,
58 OSD_CROSSHAIRS,
59 OSD_ARTIFICIAL_HORIZON,
60 OSD_HORIZON_SIDEBARS,
61 OSD_ITEM_TIMER_1,
62 OSD_ITEM_TIMER_2,
63 OSD_FLYMODE,
64 OSD_CRAFT_NAME,
65 OSD_THROTTLE_POS,
66 OSD_VTX_CHANNEL,
67 OSD_CURRENT_DRAW,
68 OSD_MAH_DRAWN,
69 OSD_GPS_SPEED,
70 OSD_GPS_SATS,
71 OSD_ALTITUDE,
72 OSD_ROLL_PIDS,
73 OSD_PITCH_PIDS,
74 OSD_YAW_PIDS,
75 OSD_POWER,
76 OSD_PIDRATE_PROFILE,
77 OSD_WARNINGS,
78 OSD_AVG_CELL_VOLTAGE,
79 OSD_GPS_LON,
80 OSD_GPS_LAT,
81 OSD_DEBUG,
82 OSD_PITCH_ANGLE,
83 OSD_ROLL_ANGLE,
84 OSD_MAIN_BATT_USAGE,
85 OSD_DISARMED,
86 OSD_HOME_DIR,
87 OSD_HOME_DIST,
88 OSD_NUMERICAL_HEADING,
89 OSD_NUMERICAL_VARIO,
90 OSD_COMPASS_BAR,
91 OSD_ESC_TMP,
92 OSD_ESC_RPM,
93 OSD_REMAINING_TIME_ESTIMATE,
94 OSD_RTC_DATETIME,
95 OSD_ADJUSTMENT_RANGE,
96 OSD_CORE_TEMPERATURE,
97 OSD_ANTI_GRAVITY,
98 OSD_ITEM_COUNT // MUST BE LAST
99 } osd_items_e;
101 // *** IMPORTANT ***
102 // The order of the OSD stats enumeration *must* match the order they're displayed on-screen
103 // This is because the fields are presented in the configurator in the order of the enumeration
104 // and we want the configuration order to match the on-screen display order.
105 // Changes to the stats display order *must* be implemented in the configurator otherwise the
106 // stats selections will not be populated correctly and the settings will become corrupted.
108 // Also - if the stats are reordered then the PR version must be incremented. Otherwise there
109 // is no indication that the stored config must be reset and the bitmapped values will be incorrect.
110 typedef enum {
111 OSD_STAT_RTC_DATE_TIME,
112 OSD_STAT_TIMER_1,
113 OSD_STAT_TIMER_2,
114 OSD_STAT_MAX_SPEED,
115 OSD_STAT_MAX_DISTANCE,
116 OSD_STAT_MIN_BATTERY,
117 OSD_STAT_END_BATTERY,
118 OSD_STAT_BATTERY,
119 OSD_STAT_MIN_RSSI,
120 OSD_STAT_MAX_CURRENT,
121 OSD_STAT_USED_MAH,
122 OSD_STAT_MAX_ALTITUDE,
123 OSD_STAT_BLACKBOX,
124 OSD_STAT_BLACKBOX_NUMBER,
125 OSD_STAT_COUNT // MUST BE LAST
126 } osd_stats_e;
128 // Make sure the number of stats do not exceed the available 32bit storage
129 STATIC_ASSERT(OSD_STAT_COUNT <= 32, osdstats_overflow);
131 typedef enum {
132 OSD_UNIT_IMPERIAL,
133 OSD_UNIT_METRIC
134 } osd_unit_e;
136 typedef enum {
137 OSD_TIMER_1,
138 OSD_TIMER_2,
139 OSD_TIMER_COUNT
140 } osd_timer_e;
142 typedef enum {
143 OSD_TIMER_SRC_ON,
144 OSD_TIMER_SRC_TOTAL_ARMED,
145 OSD_TIMER_SRC_LAST_ARMED,
146 OSD_TIMER_SRC_COUNT
147 } osd_timer_source_e;
149 typedef enum {
150 OSD_TIMER_PREC_SECOND,
151 OSD_TIMER_PREC_HUNDREDTHS,
152 OSD_TIMER_PREC_COUNT
153 } osd_timer_precision_e;
155 typedef enum {
156 OSD_WARNING_ARMING_DISABLE,
157 OSD_WARNING_BATTERY_NOT_FULL,
158 OSD_WARNING_BATTERY_WARNING,
159 OSD_WARNING_BATTERY_CRITICAL,
160 OSD_WARNING_VISUAL_BEEPER,
161 OSD_WARNING_CRASH_FLIP,
162 OSD_WARNING_ESC_FAIL,
163 OSD_WARNING_CORE_TEMPERATURE,
164 OSD_WARNING_RC_SMOOTHING,
165 OSD_WARNING_COUNT // MUST BE LAST
166 } osdWarningsFlags_e;
168 // Make sure the number of warnings do not exceed the available 16bit storage
169 STATIC_ASSERT(OSD_WARNING_COUNT <= 16, osdwarnings_overflow);
171 #define ESC_RPM_ALARM_OFF -1
172 #define ESC_TEMP_ALARM_OFF INT8_MIN
173 #define ESC_CURRENT_ALARM_OFF -1
175 typedef struct osdConfig_s {
176 uint16_t item_pos[OSD_ITEM_COUNT];
178 // Alarms
179 uint16_t cap_alarm;
180 uint16_t alt_alarm;
181 uint8_t rssi_alarm;
183 osd_unit_e units;
185 uint16_t timers[OSD_TIMER_COUNT];
186 uint16_t enabledWarnings;
188 uint8_t ahMaxPitch;
189 uint8_t ahMaxRoll;
190 uint32_t enabled_stats;
191 int8_t esc_temp_alarm;
192 int16_t esc_rpm_alarm;
193 int16_t esc_current_alarm;
194 uint8_t core_temp_alarm;
195 } osdConfig_t;
197 PG_DECLARE(osdConfig_t, osdConfig);
199 extern timeUs_t resumeRefreshAt;
201 struct displayPort_s;
202 void osdInit(struct displayPort_s *osdDisplayPort);
203 void osdResetAlarms(void);
204 void osdUpdate(timeUs_t currentTimeUs);
205 void osdStatSetState(uint8_t statIndex, bool enabled);
206 bool osdStatGetState(uint8_t statIndex);
207 void osdWarnSetState(uint8_t warningIndex, bool enabled);
208 bool osdWarnGetState(uint8_t warningIndex);