Program Listing for File simple_timer.cpp

Return to documentation for file (fang-mcb-project/src/util/chrono/simple_timer.cpp)

#include "simple_timer.hpp"
#include "modm/architecture/interface/clock.hpp"
namespace fang::chrono
{
    SimpleTimer::SimpleTimer()
    {
    }

    void SimpleTimer::reset()
    {
        m_epoch = m_clock.now();
    }

    Microseconds SimpleTimer::getDuration() const
    {
        const RawDuration rawDuration{m_clock.now() - m_epoch};
        return Microseconds{rawDuration};
    }

    Microseconds SimpleTimer::getDurationAndReset()
    {
        //Store now so that the exact slice can be set as the new epoch
        //as time will pas when the duration is being calculated
        //and if now() was called again it could be different
        const TimePoint now{m_clock.now()};
        const RawDuration rawDuration{now - m_epoch};
        m_epoch = now;
        return Microseconds{rawDuration};
    }
}