blob: ed325ddbe288f8d06f51078dc480da74a1c09267 (
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
|
component toggle2nist "toggle button to nist logic";
description
"""
Toggle2nist can be used with a momentary push button
to control a device that has separate on and off inputs
and an is-on output.
\[bu] On a rising edge on pin \\fIin\\fR when \\fIis-on\\fR is low: It sets \\fIon\\fR until \\fIis-on\\fR becomes high.
\[bu] On a rising edge on pin \\fIin\\fR when \\fIis-on\\fR is high: It sets \\fIoff\\fR until \\fIis-on\\fR becomes low.
┐ ┏─────xxxxxxxxxxxx┐ ┏─────xxxxxxxxxxxx┐
.br
in : └─────┛ xxxxxxxxxxxx└───────────┛ xxxxxxxxxxxx└─────
.br
┐ ┌───────────┐
.br
on : └─────┘ └─────────────────────────────────────────
┐ ┌───────────┐
.br
off : └───────────────────────────────────┘ └───────────
.br
┐ ┌─────────────────────────────┐
.br
is-on: └─────────────────┘ └───────────
""";
pin in bit in;
pin in bit is_on;
pin out bit on;
pin out bit off;
variable int old_in;
variable int to_state=0;
function _ nofp;
license "GPL";
author "Anders Wallin";
;;
FUNCTION(_) {
if (in!=old_in) /* a toggle has occurred */ {
if (is_on) { /* turn OFF if it's on */
on=0;
off=1;
to_state=0;
}
else if (!is_on) { /* turn ON if it's off */
on=1;
off=0;
to_state=1;
}
}
else {
/* reset pins when we see the desired state */
if (to_state==is_on) {
on=0;
off=0;
}
}
old_in=in;
}
|