WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
monotonic_clock.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <chrono>
8
9#include "wpi/hal/HAL.h"
10
11/** WPILib Hardware Abstraction Layer (HAL) namespace */
12namespace wpi::hal {
13
14/**
15 * A std::chrono compatible wrapper around the HAL monotonic timer.
16 */
18 public:
19 using rep = std::chrono::microseconds::rep;
20 using period = std::chrono::microseconds::period;
21 using duration = std::chrono::microseconds;
22 using time_point = std::chrono::time_point<monotonic_clock>;
23
24 static constexpr bool is_steady = true;
25
26 static time_point now() noexcept {
27 uint64_t currentTime = HAL_GetMonotonicTime();
28 return time_point{std::chrono::microseconds{currentTime}};
29 }
30};
31
32} // namespace wpi::hal
A std::chrono compatible wrapper around the HAL monotonic timer.
Definition monotonic_clock.hpp:17
std::chrono::microseconds::rep rep
Definition monotonic_clock.hpp:19
std::chrono::microseconds duration
Definition monotonic_clock.hpp:21
std::chrono::time_point< monotonic_clock > time_point
Definition monotonic_clock.hpp:22
static time_point now() noexcept
Definition monotonic_clock.hpp:26
static constexpr bool is_steady
Definition monotonic_clock.hpp:24
std::chrono::microseconds::period period
Definition monotonic_clock.hpp:20
uint64_t HAL_GetMonotonicTime(void)
Reads the microsecond-resolution monotonic timer.
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition Types.hpp:9