summaryrefslogtreecommitdiffstats
path: root/src/device/screen.h
blob: 3efff6d0e3487fef297b4fdb67abe72676020b12 (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
/**
 * Simple API for scrolling lines. Keeps things simple by not even assuming
 * which screen is being drawn on.
 */

#ifndef DEVICE_SCREEN_H
#define DEVICE_SCREEN_H

#include <time.h>
#include <OLEDDisplay.h>
#include <Wire.h>

#define SCREEN_WIDTH		(128)
#define SCREEN_HEIGHT		(32)
#define FONT_WIDTH		(8)
#define FONT_HEIGHT		(16)
#define SCREEN_LINE_COUNT	(SCREEN_HEIGHT / FONT_HEIGHT)
#define SCREEN_LINE_CHARS	(SCREEN_WIDTH / FONT_WIDTH)
#define SCREEN_TOTAL_CHARS	(SCREEN_LINE_COUNT * SCREEN_LINE_CHARS)
#define MESSAGE_MAX		(1023)

/**
 * Struct that keeps track of the lines on the screen.
 */
struct display_status {
	OLEDDisplay *screen;
	unsigned long period;		/* milliseconds/Line */
	unsigned long last_scroll_time;
	char message[MESSAGE_MAX + 1];	/* Entire message to be shown */
	char lines[SCREEN_LINE_COUNT][SCREEN_LINE_CHARS  + 1];
	char *cursor;			/* the begining of the *next* location in the message to be shown*/
	size_t msg_len;
	size_t remaining;		/* offset of the next part of text to be shown */
};

/**
 * Displays scrolling text on the screen.
 */
int display_update_scroll(struct display_status *status);

#define END_OF_MESSAGE	(1 << 0)
/**
 * Initialises display_status structure so it can be used for
 * display_update_scroll.
 *
 * screen	- screen to draw on
 *
 * status	- structure to Initialise
 *
 * msg		- message to scroll on the screen
 *
 * size		- length of the message
 *
 * period	- time between [elder] scrolls
 */
void display_status_init(OLEDDisplay *screen, struct display_status *status, char *msg, size_t size, unsigned long int period);

#endif /* DEVICE_SCREEN_H */