Line data Source code
1 : /*
2 : * This file is free software: you can redistribute it and/or modify it
3 : * under the terms of the GNU General Public License as published by the
4 : * Free Software Foundation, either version 3 of the License, or
5 : * (at your option) any later version.
6 : *
7 : * This file is distributed in the hope that it will be useful, but
8 : * WITHOUT ANY WARRANTY; without even the implied warranty of
9 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 : * See the GNU General Public License for more details.
11 : *
12 : * You should have received a copy of the GNU General Public License along
13 : * with this program. If not, see <http://www.gnu.org/licenses/>.
14 : *
15 : */
16 :
17 : #pragma once
18 :
19 : #include <AP_HAL/HAL.h>
20 : #include <AP_OSD/AP_OSD.h>
21 : #include <AP_Filesystem/AP_Filesystem.h>
22 :
23 :
24 : class AP_OSD_Backend
25 : {
26 :
27 : public:
28 : //constructor
29 2 : AP_OSD_Backend(AP_OSD &osd): _osd(osd) {}
30 :
31 : //destructor
32 0 : virtual ~AP_OSD_Backend(void) {}
33 :
34 : //draw given text to framebuffer
35 : virtual void write(uint8_t x, uint8_t y, const char* text) = 0;
36 :
37 : //draw formatted text to framebuffer
38 : virtual void write(uint8_t x, uint8_t y, bool blink, const char *fmt, ...) FMT_PRINTF(5, 6);
39 :
40 : //initilize framebuffer and underlying hardware
41 : virtual bool init() = 0;
42 :
43 : //update screen
44 : virtual void flush() = 0;
45 :
46 : // return a correction factor used to display angles correctly
47 0 : virtual float get_aspect_ratio_correction() const {return 1;}
48 :
49 : //clear screen
50 : //should match hw blink
51 0 : virtual void clear()
52 : {
53 0 : blink_phase = (blink_phase+1)%4;
54 0 : }
55 :
56 : // copy the backend specific symbol set to the OSD lookup table
57 : virtual void init_symbol_set(uint8_t *symbols, const uint8_t size);
58 : virtual bool is_compatible_with_backend_type(AP_OSD::osd_types type) const = 0;
59 : virtual AP_OSD::osd_types get_backend_type() const = 0;
60 :
61 : // called by the OSD thread once
62 0 : virtual void osd_thread_run_once() { return; }
63 :
64 : #if OSD_ENABLED && AP_SCRIPTING_ENABLED
65 : // passthrough OSD functions for use by scripting
66 0 : bool display_disabled() const { return _osd.display_disabled(); }
67 0 : uint8_t get_screen() const { return _osd.get_screen(); }
68 0 : void draw_screen() { _osd.draw_screen(); }
69 :
70 : // get semaphore for thread-safe access from scripting
71 0 : HAL_Semaphore &get_semaphore() { return _osd.get_semaphore(); }
72 : #endif
73 :
74 548 : AP_OSD * get_osd()
75 : {
76 548 : return &_osd;
77 : }
78 :
79 : protected:
80 : AP_OSD& _osd;
81 :
82 : // get font choice
83 : uint8_t get_font_num(void) const
84 : {
85 : return (uint8_t)_osd.font_num.get();
86 : }
87 :
88 : //check option
89 18409 : bool check_option(uint32_t option) const
90 : {
91 18409 : return (_osd.options & option) != 0;
92 : }
93 :
94 : uint8_t convert_to_decimal_packed_characters(char* buff, uint8_t size);
95 : virtual uint8_t format_string_for_osd(char* dst, uint8_t size, bool decimal_packed, const char *fmt, va_list ap);
96 :
97 : // load a font from sdcard or ROMFS
98 : FileData *load_font_data(uint8_t font_num);
99 :
100 : int8_t blink_phase;
101 :
102 : enum vid_format {
103 : FORMAT_UNKNOWN = 0,
104 : FORMAT_NTSC = 1,
105 : FORMAT_PAL = 2,
106 : } _format;
107 :
108 : // default OSD symbols
109 : static const uint8_t SYM_M = 0xB9;
110 : static const uint8_t SYM_KM = 0xBA;
111 : static const uint8_t SYM_FT = 0x0F;
112 : static const uint8_t SYM_MI = 0xBB;
113 : static const uint8_t SYM_ALT_M = 0xB1;
114 : static const uint8_t SYM_ALT_FT = 0xB3;
115 : static const uint8_t SYM_BATT_FULL = 0x90;
116 : static const uint8_t SYM_RSSI = 0x01;
117 :
118 : static const uint8_t SYM_VOLT = 0x06;
119 : static const uint8_t SYM_AMP = 0x9A;
120 : static const uint8_t SYM_MAH = 0x07;
121 : static const uint8_t SYM_MS = 0x9F;
122 : static const uint8_t SYM_FS = 0x99;
123 : static const uint8_t SYM_KMH = 0xA1;
124 : static const uint8_t SYM_MPH = 0xB0;
125 : static const uint8_t SYM_DEGR = 0xA8;
126 : static const uint8_t SYM_PCNT = 0x25;
127 : static const uint8_t SYM_RPM = 0xE0;
128 : static const uint8_t SYM_ASPD = 0xE1;
129 : static const uint8_t SYM_GSPD = 0xE2;
130 : static const uint8_t SYM_WSPD = 0xE3;
131 : static const uint8_t SYM_VSPD = 0xE4;
132 : static const uint8_t SYM_WPNO = 0xE5;
133 : static const uint8_t SYM_WPDIR = 0xE6;
134 : static const uint8_t SYM_WPDST = 0xE7;
135 : static const uint8_t SYM_FTMIN = 0xE8;
136 : static const uint8_t SYM_FTSEC = 0x99;
137 :
138 : static const uint8_t SYM_SAT_L = 0x1E;
139 : static const uint8_t SYM_SAT_R = 0x1F;
140 : static const uint8_t SYM_HDOP_L = 0xBD;
141 : static const uint8_t SYM_HDOP_R = 0xBE;
142 :
143 : static const uint8_t SYM_HOME = 0xBF;
144 : static const uint8_t SYM_WIND = 0x16;
145 :
146 : static const uint8_t SYM_ARROW_START = 0x60;
147 : static const uint8_t SYM_ARROW_COUNT = 16;
148 : static const uint8_t SYM_AH_H_START = 0x80;
149 : static const uint8_t SYM_AH_H_COUNT = 9;
150 :
151 : static const uint8_t SYM_AH_V_START = 0xCA;
152 : static const uint8_t SYM_AH_V_COUNT = 6;
153 :
154 : static const uint8_t SYM_AH_CENTER_LINE_LEFT = 0x26;
155 : static const uint8_t SYM_AH_CENTER_LINE_RIGHT = 0x27;
156 : static const uint8_t SYM_AH_CENTER = 0x7E;
157 :
158 : static const uint8_t SYM_HEADING_N = 0x18;
159 : static const uint8_t SYM_HEADING_S = 0x19;
160 : static const uint8_t SYM_HEADING_E = 0x1A;
161 : static const uint8_t SYM_HEADING_W = 0x1B;
162 : static const uint8_t SYM_HEADING_DIVIDED_LINE = 0x1C;
163 : static const uint8_t SYM_HEADING_LINE = 0x1D;
164 :
165 : static const uint8_t SYM_UP_UP = 0xA2;
166 : static const uint8_t SYM_UP = 0xA3;
167 : static const uint8_t SYM_DOWN = 0xA4;
168 : static const uint8_t SYM_DOWN_DOWN = 0xA5;
169 :
170 : static const uint8_t SYM_DEGREES_C = 0x0E;
171 : static const uint8_t SYM_DEGREES_F = 0x0D;
172 : static const uint8_t SYM_GPS_LAT = 0xA6;
173 : static const uint8_t SYM_GPS_LONG = 0xA7;
174 : static const uint8_t SYM_ARMED = 0x00;
175 : static const uint8_t SYM_DISARMED = 0xE9;
176 : static const uint8_t SYM_ROLL0 = 0x2D;
177 : static const uint8_t SYM_ROLLR = 0xEA;
178 : static const uint8_t SYM_ROLLL = 0xEB;
179 : static const uint8_t SYM_PTCH0 = 0x7C;
180 : static const uint8_t SYM_PTCHUP = 0xEC;
181 : static const uint8_t SYM_PTCHDWN = 0xED;
182 : static const uint8_t SYM_XERR = 0xEE;
183 : static const uint8_t SYM_KN = 0xF0;
184 : static const uint8_t SYM_NM = 0xF1;
185 : static const uint8_t SYM_DIST = 0x22;
186 : static const uint8_t SYM_FLY = 0x9C;
187 : static const uint8_t SYM_EFF = 0xF2;
188 : static const uint8_t SYM_AH = 0xF3;
189 : static const uint8_t SYM_MW = 0xF4;
190 : static const uint8_t SYM_CLK = 0xBC;
191 : static const uint8_t SYM_KILO = 0x4B;
192 : static const uint8_t SYM_TERALT = 0xEF;
193 : static const uint8_t SYM_FENCE_ENABLED = 0xF5;
194 : static const uint8_t SYM_FENCE_DISABLED = 0xF6;
195 : static const uint8_t SYM_RNGFD = 0xF7;
196 : static const uint8_t SYM_LQ = 0xF8;
197 : static const uint8_t SYM_WATT = 0xAE;
198 : static const uint8_t SYM_WH = 0xAB;
199 : static const uint8_t SYM_DB = 0xF9;
200 : static const uint8_t SYM_DBM = 0xFA;
201 : static const uint8_t SYM_SNR = 0xFB;
202 : static const uint8_t SYM_ANT = 0xFC;
203 : static const uint8_t SYM_ARROW_RIGHT = 0xFD;
204 : static const uint8_t SYM_ARROW_LEFT = 0xFE;
205 : static const uint8_t SYM_G = 0xDF;
206 : static const uint8_t SYM_BATT_UNKNOWN = 0x97;
207 : static const uint8_t SYM_ROLL = 0xA9;
208 : static const uint8_t SYM_PITCH = 0xAF;
209 : static const uint8_t SYM_DPS = 0xAA;
210 : static const uint8_t SYM_HEADING = 0x89;
211 : static const uint8_t SYM_RADIUS = 0x7A;
212 : static const uint8_t SYM_FLAP = 0x23;
213 :
214 : static const uint8_t SYM_SIDEBAR_R_ARROW = 0x09;
215 : static const uint8_t SYM_SIDEBAR_L_ARROW = 0x0A;
216 : static const uint8_t SYM_SIDEBAR_A = 0x13;
217 : static const uint8_t SYM_SIDEBAR_B = 0x14;
218 : static const uint8_t SYM_SIDEBAR_C = 0x15;
219 : static const uint8_t SYM_SIDEBAR_D = 0xDD;
220 : static const uint8_t SYM_SIDEBAR_E = 0xDB;
221 : static const uint8_t SYM_SIDEBAR_F = 0xDC;
222 : static const uint8_t SYM_SIDEBAR_G = 0xDA;
223 : static const uint8_t SYM_SIDEBAR_H = 0xDE;
224 : static const uint8_t SYM_SIDEBAR_I = 0x11;
225 : static const uint8_t SYM_SIDEBAR_J = 0x12;
226 :
227 : static constexpr uint8_t symbols[AP_OSD_NUM_SYMBOLS] {
228 : SYM_M,
229 : SYM_KM,
230 : SYM_FT,
231 : SYM_MI,
232 : SYM_ALT_M,
233 : SYM_ALT_FT,
234 : SYM_BATT_FULL,
235 : SYM_RSSI,
236 : SYM_VOLT,
237 : SYM_AMP,
238 : SYM_MAH,
239 : SYM_MS,
240 : SYM_FS,
241 : SYM_KMH,
242 : SYM_MPH,
243 : SYM_DEGR,
244 : SYM_PCNT,
245 : SYM_RPM,
246 : SYM_ASPD,
247 : SYM_GSPD,
248 : SYM_WSPD,
249 : SYM_VSPD,
250 : SYM_WPNO,
251 : SYM_WPDIR,
252 : SYM_WPDST,
253 : SYM_FTMIN,
254 : SYM_FTSEC,
255 : SYM_SAT_L,
256 : SYM_SAT_R,
257 : SYM_HDOP_L,
258 : SYM_HDOP_R,
259 : SYM_HOME,
260 : SYM_WIND,
261 : SYM_ARROW_START,
262 : SYM_ARROW_COUNT,
263 : SYM_AH_H_START,
264 : SYM_AH_H_COUNT,
265 : SYM_AH_V_START,
266 : SYM_AH_V_COUNT,
267 : SYM_AH_CENTER_LINE_LEFT,
268 : SYM_AH_CENTER_LINE_RIGHT,
269 : SYM_AH_CENTER,
270 : SYM_HEADING_N,
271 : SYM_HEADING_S,
272 : SYM_HEADING_E,
273 : SYM_HEADING_W,
274 : SYM_HEADING_DIVIDED_LINE,
275 : SYM_HEADING_LINE,
276 : SYM_UP_UP,
277 : SYM_UP,
278 : SYM_DOWN,
279 : SYM_DOWN_DOWN,
280 : SYM_DEGREES_C,
281 : SYM_DEGREES_F,
282 : SYM_GPS_LAT,
283 : SYM_GPS_LONG,
284 : SYM_ARMED,
285 : SYM_DISARMED,
286 : SYM_ROLL0,
287 : SYM_ROLLR,
288 : SYM_ROLLL,
289 : SYM_PTCH0,
290 : SYM_PTCHUP,
291 : SYM_PTCHDWN,
292 : SYM_XERR,
293 : SYM_KN,
294 : SYM_NM,
295 : SYM_DIST,
296 : SYM_FLY,
297 : SYM_EFF,
298 : SYM_AH,
299 : SYM_MW,
300 : SYM_CLK,
301 : SYM_KILO,
302 : SYM_TERALT,
303 : SYM_FENCE_ENABLED,
304 : SYM_FENCE_DISABLED,
305 : SYM_RNGFD,
306 : SYM_LQ,
307 : SYM_SIDEBAR_R_ARROW,
308 : SYM_SIDEBAR_L_ARROW,
309 : SYM_SIDEBAR_A,
310 : SYM_SIDEBAR_B,
311 : SYM_SIDEBAR_C,
312 : SYM_SIDEBAR_D,
313 : SYM_SIDEBAR_E,
314 : SYM_SIDEBAR_F,
315 : SYM_SIDEBAR_G,
316 : SYM_SIDEBAR_H,
317 : SYM_SIDEBAR_I,
318 : SYM_SIDEBAR_J,
319 : SYM_WATT,
320 : SYM_WH,
321 : SYM_DB,
322 : SYM_DBM,
323 : SYM_SNR,
324 : SYM_ANT,
325 : SYM_ARROW_RIGHT,
326 : SYM_ARROW_LEFT,
327 : SYM_G,
328 : SYM_BATT_UNKNOWN,
329 : SYM_ROLL,
330 : SYM_PITCH,
331 : SYM_DPS,
332 : SYM_HEADING,
333 : SYM_RADIUS,
334 : SYM_FLAP,
335 : };
336 : };
|