diff --git a/include/etl/fsm.h b/include/etl/fsm.h index eeb343b9..d350467d 100644 --- a/include/etl/fsm.h +++ b/include/etl/fsm.h @@ -31,7 +31,7 @@ SOFTWARE. #endif //*************************************************************************** -// This file has been auto generated. Do not edit this file. +// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE. //*************************************************************************** //*************************************************************************** @@ -238,8 +238,9 @@ namespace etl /// Starts the FSM. /// Can only be called once. /// Subsequent calls will do nothing. + ///\param call_on_enter_state If true will call on_enter_state() for the first state. Default = true. //******************************************* - void start() + void start(bool call_on_enter_state = true) { // Can only be started once. if (p_state == nullptr) @@ -247,7 +248,10 @@ namespace etl p_state = state_list[0]; ETL_ASSERT(p_state != nullptr, ETL_ERROR(etl::fsm_null_state_exception)); - p_state->on_enter_state(); + if (call_on_enter_state) + { + p_state->on_enter_state(); + } } } @@ -335,9 +339,15 @@ namespace etl //******************************************* /// Reset the FSM to pre-started state. + ///\param call_on_exit_state If true will call on_exit_state() for the current state. Default = false. //******************************************* - void reset() + void reset(bool call_on_exit_state = false) { + if ((p_state != nullptr) && call_on_exit_state) + { + p_state->on_exit_state(); + } + p_state = nullptr; } @@ -351,10 +361,10 @@ namespace etl //*************************************************************************** // The definition for all 16 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -412,10 +422,10 @@ namespace etl //*************************************************************************** // Specialisation for 15 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -472,10 +482,10 @@ namespace etl //*************************************************************************** // Specialisation for 14 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -531,10 +541,10 @@ namespace etl //*************************************************************************** // Specialisation for 13 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -589,9 +599,9 @@ namespace etl //*************************************************************************** // Specialisation for 12 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -645,9 +655,9 @@ namespace etl //*************************************************************************** // Specialisation for 11 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -700,9 +710,9 @@ namespace etl //*************************************************************************** // Specialisation for 10 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -754,9 +764,9 @@ namespace etl //*************************************************************************** // Specialisation for 9 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -807,8 +817,8 @@ namespace etl //*************************************************************************** // Specialisation for 8 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -858,8 +868,8 @@ namespace etl //*************************************************************************** // Specialisation for 7 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -908,8 +918,8 @@ namespace etl //*************************************************************************** // Specialisation for 6 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -957,8 +967,8 @@ namespace etl //*************************************************************************** // Specialisation for 5 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1005,7 +1015,7 @@ namespace etl //*************************************************************************** // Specialisation for 4 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1051,7 +1061,7 @@ namespace etl //*************************************************************************** // Specialisation for 3 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1096,7 +1106,7 @@ namespace etl //*************************************************************************** // Specialisation for 2 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1140,7 +1150,7 @@ namespace etl //*************************************************************************** // Specialisation for 1 message type. //*************************************************************************** - template class fsm_state : public ifsm_state { diff --git a/include/etl/fsm_generator.h b/include/etl/fsm_generator.h index 91997b63..37007900 100644 --- a/include/etl/fsm_generator.h +++ b/include/etl/fsm_generator.h @@ -250,8 +250,9 @@ namespace etl /// Starts the FSM. /// Can only be called once. /// Subsequent calls will do nothing. + ///\param call_on_enter_state If true will call on_enter_state() for the first state. Default = true. //******************************************* - void start() + void start(bool call_on_enter_state = true) { // Can only be started once. if (p_state == nullptr) @@ -259,7 +260,10 @@ namespace etl p_state = state_list[0]; ETL_ASSERT(p_state != nullptr, ETL_ERROR(etl::fsm_null_state_exception)); - p_state->on_enter_state(); + if (call_on_enter_state) + { + p_state->on_enter_state(); + } } } @@ -347,9 +351,15 @@ namespace etl //******************************************* /// Reset the FSM to pre-started state. + ///\param call_on_exit_state If true will call on_exit_state() for the current state. Default = false. //******************************************* - void reset() + void reset(bool call_on_exit_state = false) { + if ((p_state != nullptr) && call_on_exit_state) + { + p_state->on_exit_state(); + } + p_state = nullptr; } diff --git a/test/test_c_timer_framework.cpp b/test/test_c_timer_framework.cpp index ec03f140..00e98536 100644 --- a/test/test_c_timer_framework.cpp +++ b/test/test_c_timer_framework.cpp @@ -187,7 +187,7 @@ namespace // Timer should have timed out. - CHECK_EQUAL(50, *callback_list1.data()); + CHECK_EQUAL(50U, *callback_list1.data()); CHECK(ecl_timer_unregister(id1)); CHECK(!ecl_timer_unregister(id1)); diff --git a/test/test_callback_timer.cpp b/test/test_callback_timer.cpp index 5cf31bb4..d5197d3a 100644 --- a/test/test_callback_timer.cpp +++ b/test/test_callback_timer.cpp @@ -80,7 +80,7 @@ namespace etl::callback_timer<3>* p_controller; }; - + Test test; etl::function_imv member_callback; etl::function_imv member_callback2; @@ -147,7 +147,7 @@ namespace timer_controller.enable(true); ticks = 0; - + const uint32_t step = 1; while (ticks <= 100U) @@ -207,7 +207,7 @@ namespace // Timer should have timed out. - CHECK_EQUAL(50, *test.tick_list.data()); + CHECK_EQUAL(50U, *test.tick_list.data()); CHECK(timer_controller.unregister_timer(id1)); CHECK(!timer_controller.unregister_timer(id1)); @@ -346,7 +346,7 @@ namespace std::vector compare1 = { 77 }; std::vector compare2 = { 23 }; std::vector compare3 = { 11, 22, 33, 44, 55, 66, 77, 88, 99 }; - + CHECK(test.tick_list.size() != 0); CHECK(free_tick_list1.size() != 0); CHECK(free_tick_list2.size() != 0); @@ -442,7 +442,7 @@ namespace test.tick_list.clear(); free_tick_list1.clear(); free_tick_list2.clear(); - + timer_controller.start(id3); timer_controller.start(id2); @@ -455,7 +455,7 @@ namespace while (ticks <= 100U) { if (ticks == 40) - { + { timer_controller.unregister_timer(id2); id1 = timer_controller.register_timer(member_callback, 37, etl::timer::mode::REPEATING); @@ -666,11 +666,11 @@ namespace RAISE_THREAD_PRIORITY; FIX_PROCESSOR_AFFINITY; - + while (ticks <= 1000) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); - + if (controller.tick(tick)) { tick = TICK; @@ -699,11 +699,11 @@ namespace controller.start(id1); controller.start(id2); //controller.start(id3); - + controller.enable(true); std::thread t1(timer_event); - + bool restart_1 = true; while (ticks <= 1000U) diff --git a/test/test_message_timer.cpp b/test/test_message_timer.cpp index e7659d80..392cd31a 100644 --- a/test/test_message_timer.cpp +++ b/test/test_message_timer.cpp @@ -229,7 +229,7 @@ namespace // Timer should have timed out. - CHECK_EQUAL(50, *router1.message1.data()); + CHECK_EQUAL(50U, *router1.message1.data()); CHECK(timer_controller.unregister_timer(id1)); CHECK(!timer_controller.unregister_timer(id1));