summaryrefslogtreecommitdiffstats
path: root/src/device/screen.c
blob: 6ad9a87504f9fde0e4717044f41f04d4a020e6a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <time.h>
#include <stdlib.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 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;
}