forked from tinkerspy/Automaton
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtm_pulse.cpp
More file actions
executable file
·56 lines (51 loc) · 1.34 KB
/
Atm_pulse.cpp
File metadata and controls
executable file
·56 lines (51 loc) · 1.34 KB
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
#include <Automaton.h>
#include "Atm_pulse.h"
Atm_pulse & Atm_pulse::begin( int attached_pin, int minimum_duration )
{
const static state_t state_table[] PROGMEM = {
/* ON_ENTER ON_LOOP ON_EXIT EVT_TIMER EVT_HIGH EVT_LOW ELSE */
/* IDLE */ -1, -1, -1, -1, WAIT, -1, -1,
/* WAIT */ -1, -1, -1, PULSE, -1, IDLE, -1,
/* PULSE */ ACT_PULSE, -1, -1, -1, -1, IDLE, -1,
};
Machine::begin( state_table, ELSE );
pin = attached_pin;
timer.begin( this, minimum_duration );
pinMode( pin, INPUT );
return *this;
}
Atm_pulse & Atm_pulse::onPulse( Machine * machine, uint8_t msg )
{
client_machine = machine;
client_msg = msg;
return *this;
}
Atm_pulse & Atm_pulse::onPulse( pulsecb_t pulse_callback )
{
callback = pulse_callback;
return *this;
}
int Atm_pulse::event( int id )
{
switch ( id ) {
case EVT_TIMER :
return timer.expired();
case EVT_HIGH :
return digitalRead( pin );
case EVT_LOW :
return !digitalRead( pin );
}
return 0;
}
void Atm_pulse::action( int id )
{
switch ( id ) {
case ACT_PULSE :
if ( callback ) {
(*callback)();
return;
}
client_machine->msgWrite( client_msg );
return;
}
}