blob: cfabcc50c6c53cb7de00167151f1881d1b295e98 (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <SSD1306Brzo.h>
#include <Wire.h>
#include "screen.h"
void draw_lines(struct display_status *status);
void update_lines(struct display_status *status);
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 and
* possible misinterpretation.
*/
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)
{
time_t crr_time = time(NULL);
/* Only scroll lines once a delta, because --- duh! */
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(SSD1306Brzo *screen, struct display_status *status)
{
screen->clear();
screen->drawString(0, 0, status->first_line);
screen->drawString(0, SCREEN_HEIGHT / 2, status->second_line);
}
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);
}
|