6 #include <hal_posix/file_display.h>
15 static constexpr u8 DATA_BLANK[] = {
' '};
16 static constexpr u8 DATA_NEWLINE[] = {
'\r',
'\n'};
19 FileDisplay::FileDisplay(
const char* filename, u16 rows, u16 cols)
20 : satcat5::gui::
Display(rows, cols)
24 m_file = fopen(filename,
"wb");
28 for (u16 r = 0 ; r < rows ; ++r) {
29 for (u16 c = 0 ; c < cols ; ++c) {
30 fwrite(DATA_BLANK,
sizeof(DATA_BLANK), 1, m_file);
32 fwrite(DATA_NEWLINE,
sizeof(DATA_NEWLINE), 1, m_file);
36 FileDisplay::~FileDisplay() {
37 if (m_file) fclose(m_file);
43 if (!m_file)
return false;
49 u32 row_len = u32(
width()) +
sizeof(DATA_NEWLINE);
52 for (u16 r = 0 ; r < cmd.
height() ; ++r) {
54 u32 rr = (r + cursor.
r) % u32(
height());
55 u32 posn = row_len * rr + u32(cursor.
c);
56 fseek(m_file, posn, SEEK_SET);
58 for (u16 c = 0 ; c < cmd.
width() ; ++c) {
59 u8 pixel = cmd.
rc(r, c) ? u8(cursor.
fg) : u8(cursor.
bg);
60 fwrite(&pixel, 1, 1, m_file);
Required API for display devices.
u16 width() const
Total size of the display, in pixels.
u16 height() const
Total size of the display, in pixels.
Each "draw command" updates a rectangular region of pixels.
u16 width() const
Size of the rectangular update region.
u16 height() const
Size of the rectangular update region.
bool rc(u16 r, u16 c) const
Get the new pixel value at the designated row and column.
Implement the gui::Display API using a temporary file.
bool draw(const satcat5::gui::Cursor &cursor, const satcat5::gui::DrawCmd &cmd) override
Implement the required draw() method.
Cursor object tracks position and foreground/background colors.
u32 fg
Foreground color (format defined by display)
u16 r
Row coordinate (0 = top)
u32 bg
Background color (format defined by display)
u16 c
Column coordinate (0 = left)
Color parameters for the LogToDisplay class.