AP_OSD: allow size of SITL OSD to be set with parameters

This commit is contained in:
Andrew Tridgell 2024-03-25 09:20:26 +11:00
parent feb8c3be67
commit 17a61ab14b
2 changed files with 15 additions and 5 deletions

View File

@ -27,6 +27,7 @@
#include <AP_HAL/Semaphores.h>
#include <AP_HAL/Scheduler.h>
#include <AP_ROMFS/AP_ROMFS.h>
#include <SITL/SITL.h>
#include <utility>
#include <sys/types.h>
#include <sys/stat.h>
@ -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

View File

@ -72,14 +72,19 @@ private:
// 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);