diff --git a/libraries/AP_OSD/AP_OSD_SITL.cpp b/libraries/AP_OSD/AP_OSD_SITL.cpp index 07762fef0306a..40599025600d3 100644 --- a/libraries/AP_OSD/AP_OSD_SITL.cpp +++ b/libraries/AP_OSD/AP_OSD_SITL.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -100,7 +101,7 @@ void AP_OSD_SITL::write(uint8_t x, uint8_t y, const char* text) WITH_SEMAPHORE(mutex); while ((x < video_cols) && (*text != 0)) { - buffer[y][x] = *text; + getbuffer(buffer, y, x) = *text; ++text; ++x; } @@ -110,7 +111,7 @@ void AP_OSD_SITL::clear(void) { AP_OSD_Backend::clear(); WITH_SEMAPHORE(mutex); - memset(buffer, 0, sizeof(buffer)); + memset(buffer, 0, video_cols*video_lines); } void AP_OSD_SITL::flush(void) @@ -207,6 +208,10 @@ AP_OSD_Backend *AP_OSD_SITL::probe(AP_OSD &osd) AP_OSD_SITL::AP_OSD_SITL(AP_OSD &osd): AP_OSD_Backend(osd) { + const auto *_sitl = AP::sitl(); + video_lines = _sitl->osd_rows; + video_cols = _sitl->osd_columns; + buffer = (uint8_t *)malloc(video_lines*video_cols); } #endif // WITH_SITL_OSD diff --git a/libraries/AP_OSD/AP_OSD_SITL.h b/libraries/AP_OSD/AP_OSD_SITL.h index dd97deba2036a..1f375ad32278a 100644 --- a/libraries/AP_OSD/AP_OSD_SITL.h +++ b/libraries/AP_OSD/AP_OSD_SITL.h @@ -72,14 +72,19 @@ class AP_OSD_SITL : public AP_OSD_Backend // setup to match MAX7456 layout static const uint8_t char_width = 12; static const uint8_t char_height = 18; - static const uint8_t video_lines = 16; // PAL - static const uint8_t video_cols = 30; + uint8_t video_lines; + uint8_t video_cols; static const uint8_t char_spacing = 0; // scaling factor to make it easier to read static const uint8_t char_scale = 2; - uint8_t buffer[video_lines][video_cols]; + // get a byte from a buffer + uint8_t &getbuffer(uint8_t *buf, uint8_t y, uint8_t x) const { + return buf[y*uint32_t(video_cols) + x]; + } + + uint8_t *buffer; void update_thread(); static void *update_thread_start(void *obj);