From 5217945c034d5e6dab0a0ab8cf8adbd2090a87d5 Mon Sep 17 00:00:00 2001 From: dario Date: Fri, 10 Nov 2023 09:53:22 +0100 Subject: [PATCH] Added first successful test for statemachine rework --- App/Inc/sta/config.hpp | 2 +- App/Inc/tasks/toggle.hpp | 26 ++++++++++++++++++++++++++ App/Src/startup.cpp | 5 ++++- App/Src/tasks/toggle.cpp | 37 +++++++++++++++++++++++++++++++++++++ Libs/rtos2-utils | 2 +- 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 App/Inc/tasks/toggle.hpp create mode 100644 App/Src/tasks/toggle.cpp diff --git a/App/Inc/sta/config.hpp b/App/Inc/sta/config.hpp index eee17cb..ac9da2c 100644 --- a/App/Inc/sta/config.hpp +++ b/App/Inc/sta/config.hpp @@ -33,7 +33,7 @@ #define STA_TACOS_STATEMACHINE_PRIORITY osPriorityNormal // Statemachine settings. Here, we only have a single state which is also the initial state. -#define STA_TACOS_NUM_STATES 1 +#define STA_TACOS_NUM_STATES 2 #define STA_TACOS_INITIAL_STATE 0 #endif /* INC_STA_CONFIG_HPP_ */ diff --git a/App/Inc/tasks/toggle.hpp b/App/Inc/tasks/toggle.hpp new file mode 100644 index 0000000..3d14e2f --- /dev/null +++ b/App/Inc/tasks/toggle.hpp @@ -0,0 +1,26 @@ +/* + * toggle.hpp + * + * Created on: Nov 10, 2023 + * Author: Dario + */ + +#ifndef INC_STA_TOGGLE_HPP_ +#define INC_STA_TOGGLE_HPP_ + +#include + +namespace demo +{ + class Toggle : public sta::tacos::TacosThread + { + public: + Toggle(); + + void init() override; + + void func() override; + }; +} + +#endif /* INC_STA_TOGGLE_HPP_ */ diff --git a/App/Src/startup.cpp b/App/Src/startup.cpp index 9b5186a..646ca9c 100644 --- a/App/Src/startup.cpp +++ b/App/Src/startup.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -32,7 +33,9 @@ namespace sta // ###### Register different threads for different states here. ###### // The dummy task runs for state 0. - Manager::instance()->registerThread(std::make_shared("Dummy"), {0}); + Manager::instance()->registerThread(std::make_shared("State 0"), {0}); + Manager::instance()->registerThread(std::make_shared("State 1"), {1}); + Manager::instance()->registerThread(std::make_shared(), {0, 1}); } } // namespace tacos } // namespace sta diff --git a/App/Src/tasks/toggle.cpp b/App/Src/tasks/toggle.cpp new file mode 100644 index 0000000..f4efe41 --- /dev/null +++ b/App/Src/tasks/toggle.cpp @@ -0,0 +1,37 @@ +/* + * toggle.cpp + * + * Created on: Nov 10, 2023 + * Author: Dario + */ + +#include +#include +#include + +namespace demo +{ + Toggle::Toggle() + : sta::tacos::TacosThread{ "Toggle", osPriorityNormal } + { + + } + + void Toggle::init() + { + + } + + void Toggle::func() + { + osDelay(5000); + + uint16_t state = sta::tacos::Statemachine::instance()->getCurrentState(); + uint16_t next = 1 - state; + + STA_DEBUG_PRINTLN("Toggle!"); + sta::tacos::Statemachine::instance()->requestStateTransition(state, next, 0); + } +} + + diff --git a/Libs/rtos2-utils b/Libs/rtos2-utils index c609dc8..615900f 160000 --- a/Libs/rtos2-utils +++ b/Libs/rtos2-utils @@ -1 +1 @@ -Subproject commit c609dc81cc70327948aa8173c9d6ad804ae7a642 +Subproject commit 615900f16e246f3f33eebb9b022b7da3c62b7162