From a41fe12e2aa6c275c9c84dd499c9e441fa46868f Mon Sep 17 00:00:00 2001 From: wuyuanyi Date: Mon, 13 Apr 2020 05:01:47 +0800 Subject: [PATCH 1/4] conditional compile switch to stop ESP32 error --- src/Atm_analog.cpp | 3 +++ src/Atm_analog.hpp | 3 ++- src/Atm_comparator.cpp | 2 ++ src/Atm_comparator.hpp | 3 ++- src/Atm_fade.cpp | 2 ++ src/Atm_fade.hpp | 3 ++- src/Atm_player.cpp | 2 ++ src/Atm_player.hpp | 4 ++-- 8 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Atm_analog.cpp b/src/Atm_analog.cpp index cd2a632..f72c5f5 100644 --- a/src/Atm_analog.cpp +++ b/src/Atm_analog.cpp @@ -1,3 +1,5 @@ +#ifndef ATM_DISABLE_ANALOG + #include "Atm_analog.hpp" Atm_analog& Atm_analog::begin( int attached_pin, int samplerate /* = 50 */ ) { @@ -106,3 +108,4 @@ Atm_analog& Atm_analog::trace( Stream& stream ) { return *this; } +#endif // ATM_DISABLE_ANALOG diff --git a/src/Atm_analog.hpp b/src/Atm_analog.hpp index f8e818c..a81727b 100644 --- a/src/Atm_analog.hpp +++ b/src/Atm_analog.hpp @@ -1,5 +1,5 @@ #pragma once - +#ifndef ATM_DISABLE_ANALOG #include class Atm_analog : public Machine { @@ -35,3 +35,4 @@ class Atm_analog : public Machine { int event( int id ); void action( int id ); }; +#endif // ATM_DISABLE_ANALOG diff --git a/src/Atm_comparator.cpp b/src/Atm_comparator.cpp index 50f3066..aa2a4fb 100644 --- a/src/Atm_comparator.cpp +++ b/src/Atm_comparator.cpp @@ -1,3 +1,4 @@ +#ifndef ATM_DISABLE_COMPARATOR #include "Atm_comparator.hpp" Atm_comparator& Atm_comparator::begin( int attached_pin, int samplerate /* = 50 */ ) { @@ -171,3 +172,4 @@ Atm_comparator& Atm_comparator::trace( Stream& stream ) { "IDLE\0SAMPLE\0SEND" ); return *this; } +#endif //ATM_DISABLE_COMPARATOR \ No newline at end of file diff --git a/src/Atm_comparator.hpp b/src/Atm_comparator.hpp index 1357b0f..18b603b 100644 --- a/src/Atm_comparator.hpp +++ b/src/Atm_comparator.hpp @@ -1,5 +1,5 @@ #pragma once - +#ifndef ATM_DISABLE_COMPARATOR #include class Atm_comparator : public Machine { @@ -41,3 +41,4 @@ class Atm_comparator : public Machine { int event( int id ); void action( int id ); }; +#endif //ATM_DISABLE_COMPARATOR \ No newline at end of file diff --git a/src/Atm_fade.cpp b/src/Atm_fade.cpp index c94952f..178919b 100644 --- a/src/Atm_fade.cpp +++ b/src/Atm_fade.cpp @@ -1,3 +1,4 @@ +#ifndef ATM_DISABLE_FADE #include "Atm_fade.hpp" Atm_fade& Atm_fade::begin( int attached_pin ) { @@ -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 diff --git a/src/Atm_fade.hpp b/src/Atm_fade.hpp index df810a0..cea5c86 100644 --- a/src/Atm_fade.hpp +++ b/src/Atm_fade.hpp @@ -1,5 +1,5 @@ #pragma once - +#ifndef ATM_DISABLE_FADE #include class Atm_fade : public Machine { @@ -37,3 +37,4 @@ class Atm_fade : public Machine { int event( int id ); void action( int id ); }; +#endif //ATM_DISABLE_FADE \ No newline at end of file diff --git a/src/Atm_player.cpp b/src/Atm_player.cpp index 9042988..10f0882 100644 --- a/src/Atm_player.cpp +++ b/src/Atm_player.cpp @@ -1,3 +1,4 @@ +#ifndef ATM_DISABLE_PLAYER #include "Atm_player.hpp" /* Add optional parameters for the state machine to begin() @@ -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 \ No newline at end of file diff --git a/src/Atm_player.hpp b/src/Atm_player.hpp index f8624c5..71ab3fb 100644 --- a/src/Atm_player.hpp +++ b/src/Atm_player.hpp @@ -1,5 +1,5 @@ #pragma once - +#ifndef ATM_DISABLE_PLAYER #include #if defined( _VARIANT_ARDUINO_DUE_X ) || defined( ARDUINO_FEATHER52 ) @@ -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 From 8bcbfb8fdda4848f6de63a51df834d77fb57304a Mon Sep 17 00:00:00 2001 From: wuyuanyi Date: Mon, 13 Apr 2020 05:05:09 +0800 Subject: [PATCH 2/4] conditional compile switch to stop ESP32 error --- src/Atm_led.cpp | 2 ++ src/Atm_led.hpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Atm_led.cpp b/src/Atm_led.cpp index 94b5608..1374a93 100755 --- a/src/Atm_led.cpp +++ b/src/Atm_led.cpp @@ -1,3 +1,4 @@ +#ifndef ATM_DISABLE_LED #include "Atm_led.hpp" Atm_led& Atm_led::begin( int attached_pin, bool activeLow ) { @@ -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 \ No newline at end of file diff --git a/src/Atm_led.hpp b/src/Atm_led.hpp index 2584cf9..983f6e7 100644 --- a/src/Atm_led.hpp +++ b/src/Atm_led.hpp @@ -1,5 +1,5 @@ #pragma once - +#ifndef ATM_DISABLE_LED #include class Atm_led : public Machine { @@ -54,3 +54,4 @@ class Atm_led : public Machine { int event( int id ); void action( int id ); }; +#endif //ATM_DISABLE_LED \ No newline at end of file From dc5e25edb8dc49a801c63b389f7ef65025b7c73f Mon Sep 17 00:00:00 2001 From: wuyuanyi Date: Mon, 20 Apr 2020 14:36:50 +0800 Subject: [PATCH 3/4] trigger will call transition() to apply state change before entry next state. --- src/Machine.cpp | 4 +++- src/Machine.hpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Machine.cpp b/src/Machine.cpp index 0968287..abd5ef5 100644 --- a/src/Machine.cpp +++ b/src/Machine.cpp @@ -39,7 +39,7 @@ Machine& Machine::state( int state ) { * */ -Machine& Machine::trigger( int evt /* = 0 */ ) { +Machine& Machine::trigger( int evt /* = 0 */, const std::function& transition /* = {} */ ) { int new_state; int max_cycle = 8; do { @@ -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 diff --git a/src/Machine.hpp b/src/Machine.hpp index 0194ccf..369a156 100644 --- a/src/Machine.hpp +++ b/src/Machine.hpp @@ -8,7 +8,7 @@ class Machine { public: virtual int state( void ); - virtual Machine& trigger( int evt = 0 ); + virtual Machine& trigger( int evt = 0, const std::function& transition = {} ); Machine& cycle( uint32_t time = 0 ); uint32_t state_millis; uint8_t flags = ATM_SLEEP_FLAG; From 23772f1ad55ba5f2b11042ce638a86abacd5a659 Mon Sep 17 00:00:00 2001 From: wuyuanyi Date: Mon, 20 Apr 2020 16:09:53 +0800 Subject: [PATCH 4/4] Fix missing header --- src/Machine.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Machine.hpp b/src/Machine.hpp index 369a156..0c1e911 100644 --- a/src/Machine.hpp +++ b/src/Machine.hpp @@ -4,7 +4,7 @@ */ #pragma once - +#include class Machine { public: virtual int state( void );