diff options
author | 2019-05-27 15:44:38 +0300 | |
---|---|---|
committer | 2019-05-27 15:44:38 +0300 | |
commit | e37b3eacefef04258a6dc6e8714da249d2ff9c1d (patch) | |
tree | 53367df66a33f88015da5926e4f15b9867681da8 | |
parent | 755680ca7246b232c45e3b519e9d8a95ea97375f (diff) | |
download | usurpation-e37b3eacefef04258a6dc6e8714da249d2ff9c1d.tar.gz usurpation-e37b3eacefef04258a6dc6e8714da249d2ff9c1d.tar.bz2 usurpation-e37b3eacefef04258a6dc6e8714da249d2ff9c1d.zip |
Screen: More implementation details.
Only a single function is a stub now --- the actual drawing.
Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
-rwxr-xr-x | src/device/screen.c | 62 | ||||
-rwxr-xr-x | src/device/screen.h | 8 |
2 files changed, 45 insertions, 25 deletions
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 <time.h> #include <stdlib.h> +#include <string.h> #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 <time.h> +#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 |