Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundled components with hardware operations can be ignored during compile #73

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Atm_analog.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef ATM_DISABLE_ANALOG

#include "Atm_analog.hpp"

Atm_analog& Atm_analog::begin( int attached_pin, int samplerate /* = 50 */ ) {
Expand Down Expand Up @@ -106,3 +108,4 @@ Atm_analog& Atm_analog::trace( Stream& stream ) {

return *this;
}
#endif // ATM_DISABLE_ANALOG
3 changes: 2 additions & 1 deletion src/Atm_analog.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#ifndef ATM_DISABLE_ANALOG
#include <Automaton.h>

class Atm_analog : public Machine {
Expand Down Expand Up @@ -35,3 +35,4 @@ class Atm_analog : public Machine {
int event( int id );
void action( int id );
};
#endif // ATM_DISABLE_ANALOG
2 changes: 2 additions & 0 deletions src/Atm_comparator.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef ATM_DISABLE_COMPARATOR
#include "Atm_comparator.hpp"

Atm_comparator& Atm_comparator::begin( int attached_pin, int samplerate /* = 50 */ ) {
Expand Down Expand Up @@ -171,3 +172,4 @@ Atm_comparator& Atm_comparator::trace( Stream& stream ) {
"IDLE\0SAMPLE\0SEND" );
return *this;
}
#endif //ATM_DISABLE_COMPARATOR
3 changes: 2 additions & 1 deletion src/Atm_comparator.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#ifndef ATM_DISABLE_COMPARATOR
#include <Automaton.h>

class Atm_comparator : public Machine {
Expand Down Expand Up @@ -41,3 +41,4 @@ class Atm_comparator : public Machine {
int event( int id );
void action( int id );
};
#endif //ATM_DISABLE_COMPARATOR
2 changes: 2 additions & 0 deletions src/Atm_fade.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef ATM_DISABLE_FADE
#include "Atm_fade.hpp"

Atm_fade& Atm_fade::begin( int attached_pin ) {
Expand Down Expand Up @@ -150,3 +151,4 @@ Atm_fade& Atm_fade::trace( Stream& stream ) {
"IDLE\0ON\0START\0STARTU\0UP\0STARTD\0DOWN\0REPEAT\0DONE\0OSTARTU\0OUP\0OSTARTD\0ODOWN" );
return *this;
}
#endif // ATM_DISABLE_FADE
3 changes: 2 additions & 1 deletion src/Atm_fade.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#ifndef ATM_DISABLE_FADE
#include <Automaton.h>

class Atm_fade : public Machine {
Expand Down Expand Up @@ -37,3 +37,4 @@ class Atm_fade : public Machine {
int event( int id );
void action( int id );
};
#endif //ATM_DISABLE_FADE
2 changes: 2 additions & 0 deletions src/Atm_led.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef ATM_DISABLE_LED
#include "Atm_led.hpp"

Atm_led& Atm_led::begin( int attached_pin, bool activeLow ) {
Expand Down Expand Up @@ -239,3 +240,4 @@ Atm_led& Atm_led::trace( Stream& stream ) {
"IDLE\0ON\0START\0BLINK_OFF\0LOOP\0DONE\0OFF\0WT_ON\0WT_START" );
return *this;
}
#endif //ATM_DISABLE_LED
3 changes: 2 additions & 1 deletion src/Atm_led.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#ifndef ATM_DISABLE_LED
#include <Automaton.h>

class Atm_led : public Machine {
Expand Down Expand Up @@ -54,3 +54,4 @@ class Atm_led : public Machine {
int event( int id );
void action( int id );
};
#endif //ATM_DISABLE_LED
2 changes: 2 additions & 0 deletions src/Atm_player.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifndef ATM_DISABLE_PLAYER
#include "Atm_player.hpp"

/* Add optional parameters for the state machine to begin()
Expand Down Expand Up @@ -240,3 +241,4 @@ Atm_player& Atm_player::trace( Stream& stream ) {
"PLAYER\0EVT_START\0EVT_STOP\0EVT_TOGGLE\0EVT_TIMER\0EVT_EOPAT\0EVT_REPEAT\0ELSE\0IDLE\0START\0SOUND\0QUIET\0NEXT\0REPEAT\0FINISH" );
return *this;
}
#endif // ATM_DISABLE_PLAYER
4 changes: 2 additions & 2 deletions src/Atm_player.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#ifndef ATM_DISABLE_PLAYER
#include <Automaton.h>

#if defined( _VARIANT_ARDUINO_DUE_X ) || defined( ARDUINO_FEATHER52 )
Expand Down Expand Up @@ -49,7 +49,7 @@ class Atm_player : public Machine {
int event( int id );
void action( int id );
};

#endif //ATM_DISABLE_PLAYER
/*
Automaton::ATML::begin - Automaton Markup Language

Expand Down
4 changes: 3 additions & 1 deletion src/Machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Machine& Machine::state( int state ) {
*
*/

Machine& Machine::trigger( int evt /* = 0 */ ) {
Machine& Machine::trigger( int evt /* = 0 */, const std::function<void(Machine&)>& transition /* = {} */ ) {
int new_state;
int max_cycle = 8;
do {
Expand All @@ -48,6 +48,8 @@ Machine& Machine::trigger( int evt /* = 0 */ ) {
new_state = read_state( state_table + ( current * state_width ) + evt + ATM_ON_EXIT + 1 );
} while ( --max_cycle && ( new_state == -1 || next_trigger != -1 ) );
if ( new_state > -1 ) {
// Event triggers transition. Call transition callback to make some state change.
if (transition) transition(*this);
next_trigger = evt;
flags &= ~ATM_SLEEP_FLAG;
cycle(); // Pick up the trigger
Expand Down
4 changes: 2 additions & 2 deletions src/Machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/

#pragma once

#include <functional>
class Machine {
public:
virtual int state( void );
virtual Machine& trigger( int evt = 0 );
virtual Machine& trigger( int evt = 0, const std::function<void(Machine&)>& transition = {} );
Machine& cycle( uint32_t time = 0 );
uint32_t state_millis;
uint8_t flags = ATM_SLEEP_FLAG;
Expand Down