-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsel_float.comp
57 lines (48 loc) · 1.43 KB
/
sel_float.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
/********************************************************************************
sel_float.comp
*********************************************************************************/
component sel_float "This component services the float selector";
pin in bit sel_up_in "bump selection up";
pin in bit sel_dn_in "bump selection down";
pin in float sel_in.# [10] "values to select from";
pin in unsigned number_sels "number of selections to cycle, total";
pin out float sel_out "output to sel";
function _;
author "Travis Farmer";
license "GPL";
;;
bool last_up = false;
bool last_dn = false;
int curr_sel = 0;
int lastCntr = 0;
void bump_up(unsigned int sels) {
curr_sel++;
if (curr_sel > sels) {
curr_sel = sels;
}
}
void bump_dn(unsigned int sels) {
curr_sel--;
if (curr_sel < 0) {
curr_sel = 0;
}
}
FUNCTION(_) {
unsigned int num_sels = (number_sels-1);
if (sel_up_in == 1 && last_up == false) {
last_up = true;
} else if (sel_up_in == 0 && last_up == true) {
last_up = false;
curr_sel++;
if (curr_sel > num_sels) {
curr_sel = 0;
bump_up(num_sels);
}
} else if (sel_dn_in == 1 && last_dn == false) {
last_dn = true;
} else if (sel_dn_in == 0 && last_dn == true) {
last_dn = false;
bump_dn(num_sels);
}
sel_out = sel_in(curr_sel);
}