TACOS/App/Src/startup.cpp

72 lines
2.1 KiB
C++

/*
* printable.cpp
*
* Created on: Aug 30, 2023
* Author: Dario
*/
#include <sta/tacos/startup.hpp>
#include <sta/debug/debug.hpp>
#include <sta/tacos/manager.hpp>
#include <sta/tacos/statemachine.hpp>
#include <tasks/dummy.hpp>
#include <gpio.h>
#include <sta/devices/stm32/gpio_pin.hpp>
#include <memory>
namespace sta
{
namespace tacos
{
void onStatemachineInit()
{
Statemachine::instance()->setStateFunction([](uint16_t state) -> uint16_t {
// ###### Implement your state transition function here! ######
/**
* This function should return some state within 0 and STA_TACOS_NUM_STATES (specified in the config.hpp).
* Return the same state as given as the argument for no state transition. Make sure, that this function is not
* computationally expensive.
*/
return state;
});
Statemachine::instance()->setTimerFunction([](uint16_t state, uint16_t lastState, uint32_t event) {
// ###### Set the failsafe and lockout timers here ######
/**
* This function is called after a state transition from lastState to state. Event corresponds to EventFlag enum in the Statemachine
* and encode how the state change happened.
*
* Setting a timer here is fully optional and depends on your system's specifications.
*/
uint32_t someFailsafeMillis = 42;
uint16_t someNextState = STA_TACOS_INITIAL_STATE;
uint32_t someLockoutMillis = 21;
// Start the failsafe timer to force a state transition to someNextState after someFailsafeMillis milliseconds.
Statemachine::instance()->setFailsafeTimer(someFailsafeMillis, someNextState);
// Start the lockout timer to block a state transition for the first someLockoutMillis milliseconds.
Statemachine::instance()->setLockoutTimer(someLockoutMillis);
});
}
void onManagerInit()
{
// ###### Register different threads for different states here. ######
// The dummy task runs for state 0.
Manager::instance()->registerThread(std::make_shared<demo::DummyTask>("Dummy"), {0});
}
} // namespace tacos
} // namespace sta