Copter: free allocations in case of allocation failure
[ardupilot.git] / libraries / AP_OSD / AP_OSD_SITL.h
blob1f375ad32278a2b9ee00f59a20c45868d75f3a83
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.
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.
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/>.
16 #pragma once
18 #ifdef WITH_SITL_OSD
20 #include <AP_OSD/AP_OSD_Backend.h>
22 #ifdef HAVE_SFML_GRAPHICS_H
23 #include <SFML/Graphics.h>
24 #else
25 #include <SFML/Graphics.hpp>
26 #endif
28 class AP_OSD_SITL : public AP_OSD_Backend
31 public:
32 static AP_OSD_Backend *probe(AP_OSD &osd);
34 //draw given text to framebuffer
35 void write(uint8_t x, uint8_t y, const char* text) override;
37 //initialize display port and underlying hardware
38 bool init() override;
40 //flush framebuffer to screen
41 void flush() override;
43 //clear framebuffer
44 void clear() override;
46 bool is_compatible_with_backend_type(AP_OSD::osd_types type) const override {
47 switch(type) {
48 case AP_OSD::osd_types::OSD_MAX7456:
49 case AP_OSD::osd_types::OSD_SITL:
50 return false;
51 case AP_OSD::osd_types::OSD_NONE:
52 case AP_OSD::osd_types::OSD_TXONLY:
53 case AP_OSD::osd_types::OSD_MSP:
54 case AP_OSD::osd_types::OSD_MSP_DISPLAYPORT:
55 return true;
57 return false;
60 AP_OSD::osd_types get_backend_type() const override {
61 return AP_OSD::osd_types::OSD_SITL;
63 private:
64 //constructor
65 AP_OSD_SITL(AP_OSD &osd);
67 sf::RenderWindow *w;
69 sf::Texture font[256];
70 uint8_t last_font;
72 // setup to match MAX7456 layout
73 static const uint8_t char_width = 12;
74 static const uint8_t char_height = 18;
75 uint8_t video_lines;
76 uint8_t video_cols;
77 static const uint8_t char_spacing = 0;
79 // scaling factor to make it easier to read
80 static const uint8_t char_scale = 2;
82 // get a byte from a buffer
83 uint8_t &getbuffer(uint8_t *buf, uint8_t y, uint8_t x) const {
84 return buf[y*uint32_t(video_cols) + x];
87 uint8_t *buffer;
89 void update_thread();
90 static void *update_thread_start(void *obj);
91 void load_font();
93 pthread_t thread;
94 HAL_Semaphore mutex;
95 uint32_t counter;
96 uint32_t last_counter;
99 #endif // WITH_SITL_OSD