57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
#pragma once
|
|
|
|
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
|
|
|
#include <concepts>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
|
|
namespace mcc
|
|
{
|
|
|
|
enum class MccMountType : uint8_t { GERMAN_TYPE, FORK_TYPE, CROSSAXIS_TYPE, ALTAZ_TYPE };
|
|
|
|
|
|
// mount state type concept
|
|
template <typename T>
|
|
concept mcc_mount_state_c = requires(T t, const T t_const) {
|
|
typename T::state_id_t;
|
|
{ t.ident() } -> std::same_as<typename T::state_id_t>;
|
|
|
|
typename T::context_t;
|
|
{ t.enter(std::declval<const typename T::context_t&>()) } -> std::same_as<void>;
|
|
{ t.exit(std::declval<const typename T::context_t&>()) } -> std::same_as<void>;
|
|
};
|
|
|
|
|
|
|
|
// implements a Finite State Machine Pattern
|
|
template <MccMountType MOUNT_TYPE>
|
|
class MccMount
|
|
{
|
|
public:
|
|
static constexpr MccMountType mountType = MOUNT_TYPE;
|
|
|
|
|
|
MccMount()
|
|
{
|
|
_exitCurrentState = []() {}; // do nothing
|
|
}
|
|
|
|
virtual ~MccMount() {}
|
|
|
|
template <mcc_mount_state_c StateT>
|
|
void setMountState(StateT& state)
|
|
{
|
|
_exitCurrentState(); // exit from current state
|
|
_exitCurrentState = [&state, this]() { state.exit(this); };
|
|
|
|
state.enter(this);
|
|
}
|
|
|
|
protected:
|
|
std::function<void()> _exitCurrentState;
|
|
};
|
|
|
|
} // namespace mcc
|