From e37b3eacefef04258a6dc6e8714da249d2ff9c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Mon, 27 May 2019 15:44:38 +0300 Subject: Screen: More implementation details. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only a single function is a stub now --- the actual drawing. Signed-off-by: Ramūnas Mažeikis --- src/device/screen.c | 62 ++++++++++++++++++++++++++++++++--------------------- src/device/screen.h | 8 +++++++ 2 files changed, 45 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/device/screen.c b/src/device/screen.c index 6ad9a87..ac42076 100755 --- a/src/device/screen.c +++ b/src/device/screen.c @@ -1,10 +1,45 @@ #include #include +#include #include "screen.h" void draw_lines(struct display_status *status); void update_lines(struct display_status *status); -char * get_line(struct display_status *status, size_t rline); +void init_msg(char *msg, size_t size); + +void display_status_init(struct display_status *status, char *msg) +{ + status->delta = 2; /* Currently default */ + init_msg(msg, strlen(msg)); + status->message = msg; + status->line_cursor = 0; + status->last_scroll_time = time(NULL); + update_lines(status); +} + +/** + * Turns all whitespace into literal spaces to save screen real-estate. + */ +void init_msg(char *msg, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) { + switch (msg[i]) { + case '\n': + case '\t': + case '\r': + msg[i] = ' '; + break; + case '\0': + goto end; + default: + break; + } + } +end: + return; +} void display_update_scroll(struct display_status *status) { @@ -19,34 +54,11 @@ void display_update_scroll(struct display_status *status) void draw_lines(struct display_status *status) { - + /* TODO */ } 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); -} - -/** - * Returns a pointer to the first charachter of requested line. If line does not - * exist --- a null is returned. - */ -char * get_line(struct display_status *status, size_t rline) -{ - size_t i; - size_t line_idx = 0; - - for (i = 0; i < status->message_len; i++) { - if (rline == line_idx) { - return status->message + i; - } - if (status->message[i] == '\0') { - line_idx++; - } - } - /* The fact that we are here means that end of the message was reached. - * In that case --- return null; - */ - return NULL; } \ No newline at end of file diff --git a/src/device/screen.h b/src/device/screen.h index ec30cd5..7763bd2 100755 --- a/src/device/screen.h +++ b/src/device/screen.h @@ -3,6 +3,10 @@ #include +#define SCREEN_WIDTH (64) +#define FONT_WIDTH (8) +#define SCREEN_MAX_CHARS (SCREEN_WIDTH / FONT_WIDTH) + /** * Struct that keeps track of the lines on the screen. */ @@ -16,7 +20,11 @@ struct display_status { size_t line_cursor; /* Index of the first line being displayed. */ }; +/** + * Displays scrolling text on the screen. + */ void display_update_scroll(struct display_status *status); + void display_status_init(struct display_status *status, char *msg); #endif /* DEVICE_SCREEN_H */ \ No newline at end of file -- cgit v1.2.3