-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlcd_pager.comp
64 lines (55 loc) · 1.64 KB
/
lcd_pager.comp
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
/********************************************************************************
lcd_pager.comp
*********************************************************************************/
component lcd_pager "This component services the LCD Page turner";
pin in bit page_up_in "bump page up";
pin in bit page_dn_in "bump page down";
pin in signed enc_count "Optional Encoder Input";
pin in unsigned number_pages "number of pages to turn, total";
pin out unsigned page_out "output to LCD page";
function _;
author "Travis Farmer";
license "GPL";
;;
bool last_up = false;
bool last_dn = false;
int curr_page = 0;
int lastCntr = 0;
void bump_up(unsigned int Pages) {
curr_page++;
if (curr_page > Pages) {
curr_page = 0;
}
}
void bump_dn(unsigned int Pages) {
curr_page--;
if (curr_page < 0) {
curr_page = Pages;
}
}
FUNCTION(_) {
unsigned int num_pages = (number_pages-1);
if (page_up_in == 1 && last_up == false) {
last_up = true;
} else if (page_up_in == 0 && last_up == true) {
last_up = false;
curr_page++;
if (curr_page > num_pages) {
curr_page = 0;
bump_up(num_pages);
}
} else if (page_dn_in == 1 && last_dn == false) {
last_dn = true;
} else if (page_dn_in == 0 && last_dn == true) {
last_dn = false;
bump_dn(num_pages);
}
if (enc_count > lastCntr) {
lastCntr = enc_count;
bump_up(num_pages);
} else if (enc_count < lastCntr) {
lastCntr = enc_count;
bump_dn(num_pages);
}
page_out = curr_page;
}