time setting

This commit is contained in:
2023-06-17 23:19:42 +02:00
parent f5d8405bdf
commit 26cbbd6f9b
8 changed files with 199 additions and 45 deletions
+59 -1
View File
@@ -36,8 +36,37 @@ void LcdBuffer_Clear(struct LcdBuffer *self)
/** Write what needs to be written to the HW, clear all dirty marks */
void LcdBuffer_Flush(struct LcdBuffer *self)
{
bool any_flush = self->full_repaint_required || self->cursor_dirty;
uint8_t flush_cgram_mask = 0;
// Check if any flushing is required
for (int i = 0; i < LCDBUF_CGRAM_CAPACITY; i++) {
if (self->cgram[i].refcount > 0 && self->cgram[i].dirty) {
any_flush = true;
flush_cgram_mask |= 1 << i;
}
}
if (!any_flush) {
// check if we have dirty areas
for (int e = 0; e < LCDBUF_DIRTY_LIST_LEN; e++) {
struct LcdBuf_DirtyExtent *ext = &self->dirty_extents[e];
if (ext->count) {
any_flush = true;
break;
}
}
}
if (!any_flush) {
// really nothing to do
return;
}
LcdBuffer_IO_SetCursorStyle(0); // hide cursor for the time of this function
for (int i = 0; i < LCDBUF_CGRAM_CAPACITY; i++) {
if (flush_cgram_mask & (1 << i)) {
LcdBuffer_IO_WriteCGRAM(i, self->custom_symbols[self->cgram[i].symbol_index].data);
self->cgram[i].dirty = false;
}
@@ -57,7 +86,7 @@ void LcdBuffer_Flush(struct LcdBuffer *self)
if (!any_nonspace) {
LcdBuffer_IO_Clear();
return;
goto done;
}
for (int r = 0; r < LINE_NUM; r++) {
@@ -74,11 +103,21 @@ void LcdBuffer_Flush(struct LcdBuffer *self)
ext->count = 0; // mark the slot as free
}
}
done:
// Restore the visible cursor
if (self->cursor_style != 0) {
LcdBuffer_IO_SetCursorPos(self->cursor_row, self->cursor_col);
LcdBuffer_IO_SetCursorStyle(self->cursor_style); // hide cursor for the time of this function
}
self->cursor_dirty = false;
}
/** Fully write everything to the display */
void LcdBuffer_FlushAll(struct LcdBuffer *self)
{
LcdBuffer_IO_SetCursorStyle(0); // hide cursor for the time of this function
for (int i = 0; i < LCDBUF_CGRAM_CAPACITY; i++) {
if (self->cgram[i].refcount > 0) {
LcdBuffer_IO_WriteCGRAM(i, self->custom_symbols[self->cgram[i].symbol_index].data);
@@ -92,6 +131,14 @@ void LcdBuffer_FlushAll(struct LcdBuffer *self)
memset(self->dirty_extents, 0, sizeof(self->dirty_extents));
self->full_repaint_required = false;
// Restore the visible cursor
if (self->cursor_style != 0) {
LcdBuffer_IO_SetCursorPos(self->cursor_row, self->cursor_col);
LcdBuffer_IO_SetCursorStyle(self->cursor_style); // hide cursor for the time of this function
}
self->cursor_dirty = false;
}
//static void show_dirty_slots(const struct LcdBuffer *self) {
@@ -289,3 +336,14 @@ void LcdBuffer_Write(struct LcdBuffer *self, lcdbuf_pos_t row, lcdbuf_pos_t col,
col++;
}
}
void LcdBuffer_SetCursor(struct LcdBuffer *self, lcdbuf_pos_t row, lcdbuf_pos_t col, uint8_t cursor_style)
{
if ((self->cursor_style != cursor_style) || (self->cursor_row != row) || (self->cursor_col != col)) {
self->cursor_style = cursor_style;
self->cursor_row = row;
self->cursor_col = col;
self->cursor_dirty = true;
}
}
+14 -1
View File
@@ -71,6 +71,12 @@ struct LcdBuffer {
/** If the dirty extents array was not sufficient to hold all changes, this flag is set,
* indicating the dirty_extents array should be disregarded. */
bool full_repaint_required;
/* Visible cursor - is restored after flushing */
uint8_t cursor_style; // two bits - blink 0b01, bar 0b10
lcdbuf_pos_t cursor_row;
lcdbuf_pos_t cursor_col;
bool cursor_dirty;
};
/** Initialize the struct */
@@ -91,6 +97,9 @@ void LcdBuffer_Set(struct LcdBuffer *self, lcdbuf_pos_t row, lcdbuf_pos_t col, s
/** Write a UTF8 string at a position */
void LcdBuffer_Write(struct LcdBuffer *self, lcdbuf_pos_t row, lcdbuf_pos_t col, char *utf_string);
/** Set visible cursor position and style. style is 2 bits: blink 0b01, bar 0b10 */
void LcdBuffer_SetCursor(struct LcdBuffer *self, lcdbuf_pos_t row, lcdbuf_pos_t col, uint8_t cursor_style);
/* Callbacks - need to be implemented by the application! */
/** Clear the entire screen (CGRAM can be left unchanged, but they will be written anew if needed) */
@@ -100,6 +109,10 @@ extern void LcdBuffer_IO_Clear();
extern void LcdBuffer_IO_WriteAt(lcdbuf_pos_t row, lcdbuf_pos_t col, const uint8_t *buf, lcdbuf_count_t len);
/** Write CGRAM data. Data is always 8 bytes long. */
extern void LcdBuffer_IO_WriteCGRAM(uint8_t position, const uint8_t* data);
extern void LcdBuffer_IO_WriteCGRAM(uint8_t position, const uint8_t *data);
/** Set cursor pos & style */
extern void LcdBuffer_IO_SetCursorPos(lcdbuf_pos_t cursor_row, lcdbuf_pos_t cursor_col);
extern void LcdBuffer_IO_SetCursorStyle(uint8_t cursor_style);
#endif //HD44780UTF_LCDBUF_H