Skip to content

Commit

Permalink
AP_OSD: allow size of SITL OSD to be set with parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Mar 25, 2024
1 parent 62d5461 commit 9c829cb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions libraries/AP_OSD/AP_OSD_SITL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
11 changes: 8 additions & 3 deletions libraries/AP_OSD/AP_OSD_SITL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9c829cb

Please sign in to comment.