From 755680ca7246b232c45e3b519e9d8a95ea97375f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Mon, 27 May 2019 15:20:01 +0300 Subject: Device: partial implementation of line scrolling logic. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ramūnas Mažeikis --- src/device/screen.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 src/device/screen.c (limited to 'src/device/screen.c') diff --git a/src/device/screen.c b/src/device/screen.c new file mode 100755 index 0000000..6ad9a87 --- /dev/null +++ b/src/device/screen.c @@ -0,0 +1,52 @@ +#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 display_update_scroll(struct display_status *status) +{ + time_t crr_time = time(NULL); + if (status->last_scroll_time - crr_time > status->delta) { + status->last_scroll_time += status->delta; + status->line_cursor++; + update_lines(status); + } + draw_lines(status); +} + +void draw_lines(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); +} + +/** + * 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 -- cgit v1.2.3