From f267021479ab1f020c7956378d5bf23405ee3e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 28 May 2019 20:00:23 +0300 Subject: Screen: adjustments, bug fixes and abstraction. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Line drawing code no longer assumes a particular screen as long as it's interface includes OLEDDisplay. Signed-off-by: Ramūnas Mažeikis --- src/device/screen.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/device/screen.cpp') diff --git a/src/device/screen.cpp b/src/device/screen.cpp index cfabcc5..c923b99 100644 --- a/src/device/screen.cpp +++ b/src/device/screen.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include "screen.h" @@ -9,6 +9,9 @@ void draw_lines(struct display_status *status); void update_lines(struct display_status *status); void init_msg(char *msg, size_t size); +/* Effectively const. For type safety reasons. */ +static char NOTHING[] = {'\0'}; + void display_status_init(struct display_status *status, char *msg) { status->delta = 2; /* Currently default */ @@ -44,7 +47,7 @@ end: return; } -void display_update_scroll(struct display_status *status) +int display_update_scroll(struct display_status *status) { time_t crr_time = time(NULL); /* Only scroll lines once a delta, because --- duh! */ @@ -54,9 +57,14 @@ void display_update_scroll(struct display_status *status) update_lines(status); draw_lines(status); } + if (status->first_line == NOTHING && status->second_line == NOTHING) { + return END_OF_MESSAGE; + } else { + return 0; + } } -void draw_lines(SSD1306Brzo *screen, struct display_status *status) +void draw_lines(OLEDDisplay *screen, struct display_status *status) { screen->clear(); screen->drawString(0, 0, status->first_line); @@ -65,6 +73,10 @@ void draw_lines(SSD1306Brzo *screen, struct display_status *status) void update_lines(struct display_status *status) { - status->first_line = get_line(status, status->line_cursor); - status->second_line = get_line(status, status->line_cursor + 1); + status->first_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len) + ? status->message + status->line_cursor * SCREEN_MAX_CHARS + : NOTHING; + status->second_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len) + ? status->message + (status->line_cursor + 1) * SCREEN_MAX_CHARS + : NOTHING; } \ No newline at end of file -- cgit v1.2.3