CTRE Phoenix 6 C++ 24.3.0
TimeUtil.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
9#ifdef __FRC_ROBORIO__
10#include <unistd.h>
11#else
12#include <thread>
13#endif
14
15#include <chrono>
16
17namespace ctre {
18namespace phoenix {
19namespace platform {
20
21 /**
22 * \param timeUs How long to yield current thread in microseconds (us).
23 * If platform cannot honor us resolution, round up to nearest
24 * value that platform can honor.
25 */
26 static inline void SleepUs(int timeUs)
27 {
28#ifdef __FRC_ROBORIO__
29 usleep(timeUs);
30#else
31 std::this_thread::sleep_for(std::chrono::microseconds{timeUs});
32#endif
33 }
34
35 /**
36 * Returns the monotonic time of the system, converted to the given duration.
37 * The default duration is in microseconds.
38 */
39 template <typename DURATION = std::chrono::microseconds>
40 static inline auto CurrentTime()
41 {
42 using namespace std::chrono;
43 return duration_cast<DURATION>(steady_clock::now().time_since_epoch()).count();
44 }
45
46} // namespace platform
47} // namespace phoenix
48} // namespace ctre
static auto CurrentTime()
Returns the monotonic time of the system, converted to the given duration.
Definition: TimeUtil.hpp:40
static void SleepUs(int timeUs)
Definition: TimeUtil.hpp:26
Definition: string_util.hpp:15