summaryrefslogtreecommitdiff
path: root/deps/fff/examples/embedded_ui/src/UI.c
blob: 8ce996e66ad6107b073ae08b401dca8d1062e376 (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
#include "UI.h"
#include "DISPLAY.h"
#include "SYSTEM.h"
#include <string.h>

static unsigned int missed_irq_counter;
button_cbk_t button_cbk;


void UI_init()
{
    DISPLAY_init();
    SYSTEM_register_irq(UI_button_irq_handler, IRQ_GPIO_2);
    button_cbk = 0;
    missed_irq_counter = 0;
}

unsigned int UI_get_missed_irqs()
{
	return missed_irq_counter;
}

void UI_button_irq_handler()
{
	if(button_cbk)
	{
		button_cbk();
	}
	else
	{
		missed_irq_counter++;
	}
}

void UI_register_button_cbk(button_cbk_t cbk)
{
	button_cbk = cbk;
}

void UI_write_line(char *line)
{
	static char out[27];
	strncpy(out, line, 26);
	out[26] = '\0';
	if(DISPLAY_get_line_capacity() == DISPLAY_get_line_insert_index())
		DISPLAY_clear();
	DISPLAY_output(out);
}