From 92235fb259b0ebdfc99859c2c95fe1f8c163f411 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 8 Nov 2016 20:09:05 -0500 Subject: trying out distortos --- include/distortos/StaticSoftwareTimer.hpp | 90 +++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 include/distortos/StaticSoftwareTimer.hpp (limited to 'include/distortos/StaticSoftwareTimer.hpp') diff --git a/include/distortos/StaticSoftwareTimer.hpp b/include/distortos/StaticSoftwareTimer.hpp new file mode 100644 index 0000000..e1c27f7 --- /dev/null +++ b/include/distortos/StaticSoftwareTimer.hpp @@ -0,0 +1,90 @@ +/** + * \file + * \brief StaticSoftwareTimer class header + * + * \author Copyright (C) 2014-2015 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info + * + * \par License + * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not + * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDE_DISTORTOS_STATICSOFTWARETIMER_HPP_ +#define INCLUDE_DISTORTOS_STATICSOFTWARETIMER_HPP_ + +#include "distortos/SoftwareTimerCommon.hpp" + +#include + +namespace distortos +{ + +/// \addtogroup softwareTimers +/// \{ + +/** + * \brief StaticSoftwareTimer class is a templated interface for software timer + * + * \tparam Function is the function that will be executed + * \tparam Args are the arguments for function + */ + +template +class StaticSoftwareTimer : public SoftwareTimerCommon +{ +public: + + /** + * \brief StaticSoftwareTimer's constructor + * + * \param [in] function is a function that will be executed from interrupt context at a later time + * \param [in] args are arguments for function + */ + + StaticSoftwareTimer(Function&& function, Args&&... args) : + SoftwareTimerCommon{}, + boundFunction_{std::bind(std::forward(function), std::forward(args)...)} + { + + } + +private: + + /** + * \brief "Run" function of software timer + * + * Executes bound function object. + */ + + void run() override + { + boundFunction_(); + } + + /// bound function object + decltype(std::bind(std::declval(), std::declval()...)) boundFunction_; +}; + +/** + * \brief Helper factory function to make StaticSoftwareTimer object with deduced template arguments + * + * \tparam Function is the function that will be executed + * \tparam Args are the arguments for function + * + * \param [in] function is a function that will be executed from interrupt context at a later time + * \param [in] args are arguments for function + * + * \return StaticSoftwareTimer object with deduced template arguments + */ + +template +StaticSoftwareTimer makeStaticSoftwareTimer(Function&& function, Args&&... args) +{ + return {std::forward(function), std::forward(args)...}; +} + +/// \} + +} // namespace distortos + +#endif // INCLUDE_DISTORTOS_STATICSOFTWARETIMER_HPP_ -- cgit v1.2.3