Merge pull request #6233 from leocb/add-gforce-osd
[betaflight.git] / src / main / io / osd.h
blob6addd762b2e588e349992752b3b6ee90130ba873
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_G_FORCE,
99 OSD_ITEM_COUNT // MUST BE LAST
100 } osd_items_e;
102 // *** IMPORTANT ***
103 // The order of the OSD stats enumeration *must* match the order they're displayed on-screen
104 // This is because the fields are presented in the configurator in the order of the enumeration
105 // and we want the configuration order to match the on-screen display order.
106 // Changes to the stats display order *must* be implemented in the configurator otherwise the
107 // stats selections will not be populated correctly and the settings will become corrupted.
109 // Also - if the stats are reordered then the PR version must be incremented. Otherwise there
110 // is no indication that the stored config must be reset and the bitmapped values will be incorrect.
111 typedef enum {
112 OSD_STAT_RTC_DATE_TIME,
113 OSD_STAT_TIMER_1,
114 OSD_STAT_TIMER_2,
115 OSD_STAT_MAX_SPEED,
116 OSD_STAT_MAX_DISTANCE,
117 OSD_STAT_MIN_BATTERY,
118 OSD_STAT_END_BATTERY,
119 OSD_STAT_BATTERY,
120 OSD_STAT_MIN_RSSI,
121 OSD_STAT_MAX_CURRENT,
122 OSD_STAT_USED_MAH,
123 OSD_STAT_MAX_ALTITUDE,
124 OSD_STAT_BLACKBOX,
125 OSD_STAT_BLACKBOX_NUMBER,
126 OSD_STAT_COUNT // MUST BE LAST
127 } osd_stats_e;
129 // Make sure the number of stats do not exceed the available 32bit storage
130 STATIC_ASSERT(OSD_STAT_COUNT <= 32, osdstats_overflow);
132 typedef enum {
133 OSD_UNIT_IMPERIAL,
134 OSD_UNIT_METRIC
135 } osd_unit_e;
137 typedef enum {
138 OSD_TIMER_1,
139 OSD_TIMER_2,
140 OSD_TIMER_COUNT
141 } osd_timer_e;
143 typedef enum {
144 OSD_TIMER_SRC_ON,
145 OSD_TIMER_SRC_TOTAL_ARMED,
146 OSD_TIMER_SRC_LAST_ARMED,
147 OSD_TIMER_SRC_COUNT
148 } osd_timer_source_e;
150 typedef enum {
151 OSD_TIMER_PREC_SECOND,
152 OSD_TIMER_PREC_HUNDREDTHS,
153 OSD_TIMER_PREC_COUNT
154 } osd_timer_precision_e;
156 typedef enum {
157 OSD_WARNING_ARMING_DISABLE,
158 OSD_WARNING_BATTERY_NOT_FULL,
159 OSD_WARNING_BATTERY_WARNING,
160 OSD_WARNING_BATTERY_CRITICAL,
161 OSD_WARNING_VISUAL_BEEPER,
162 OSD_WARNING_CRASH_FLIP,
163 OSD_WARNING_ESC_FAIL,
164 OSD_WARNING_CORE_TEMPERATURE,
165 OSD_WARNING_RC_SMOOTHING,
166 OSD_WARNING_COUNT // MUST BE LAST
167 } osdWarningsFlags_e;
169 // Make sure the number of warnings do not exceed the available 16bit storage
170 STATIC_ASSERT(OSD_WARNING_COUNT <= 16, osdwarnings_overflow);
172 #define ESC_RPM_ALARM_OFF -1
173 #define ESC_TEMP_ALARM_OFF INT8_MIN
174 #define ESC_CURRENT_ALARM_OFF -1
176 typedef struct osdConfig_s {
177 uint16_t item_pos[OSD_ITEM_COUNT];
179 // Alarms
180 uint16_t cap_alarm;
181 uint16_t alt_alarm;
182 uint8_t rssi_alarm;
184 osd_unit_e units;
186 uint16_t timers[OSD_TIMER_COUNT];
187 uint16_t enabledWarnings;
189 uint8_t ahMaxPitch;
190 uint8_t ahMaxRoll;
191 uint32_t enabled_stats;
192 int8_t esc_temp_alarm;
193 int16_t esc_rpm_alarm;
194 int16_t esc_current_alarm;
195 uint8_t core_temp_alarm;
196 } osdConfig_t;
198 PG_DECLARE(osdConfig_t, osdConfig);
200 extern timeUs_t resumeRefreshAt;
202 struct displayPort_s;
203 void osdInit(struct displayPort_s *osdDisplayPort);
204 void osdResetAlarms(void);
205 void osdUpdate(timeUs_t currentTimeUs);
206 void osdStatSetState(uint8_t statIndex, bool enabled);
207 bool osdStatGetState(uint8_t statIndex);
208 void osdWarnSetState(uint8_t warningIndex, bool enabled);
209 bool osdWarnGetState(uint8_t warningIndex);