M5Utility 0.3.0 git rev:41a629c
Loading...
Searching...
No Matches
compatibility_feature.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UTILITY_COMPATIBILITY_FEATURE_HPP
11#define M5_UTILITY_COMPATIBILITY_FEATURE_HPP
12
13#include <type_traits>
14
15namespace m5 {
16namespace utility {
17
20
23unsigned long millis();
24
28unsigned long micros();
29
35void delay(const unsigned long ms);
36
42void delayMicroseconds(const unsigned int us);
44
47
53using elapsed_time_t = unsigned long;
54
69template <typename T>
70inline T elapsedSince(const T start_at, const T now)
71{
72 return now - start_at;
73}
74
81{
82 return elapsedSince(start_at, millis());
83}
84
102template <typename T>
103inline bool hasElapsed(const T start_at, const typename std::common_type<T>::type duration, const T now)
104{
105 return elapsedSince(start_at, now) >= duration;
106}
107
114inline bool hasElapsed(const elapsed_time_t start_at, const elapsed_time_t duration)
115{
116 return hasElapsed(start_at, duration, millis());
117}
119
120} // namespace utility
121} // namespace m5
122#endif
IRAM_ATTR unsigned long millis()
Returns the number of milliseconds passed since the Arduino board began running the current program.
Definition compatibility_feature.cpp:46
IRAM_ATTR unsigned long micros()
Returns the number of microseconds since the Arduino board began running the current program.
Definition compatibility_feature.cpp:57
void delay(const unsigned long ms)
Pauses the program for the amount of time (in milliseconds) specified as parameter.
Definition compatibility_feature.cpp:68
void delayMicroseconds(const unsigned int us)
Pauses the program for the amount of time (in microseconds) specified by the parameter.
Definition compatibility_feature.cpp:88
unsigned long elapsed_time_t
Elapsed time unit (ms)
Definition compatibility_feature.hpp:53
bool hasElapsed(const T start_at, const typename std::common_type< T >::type duration, const T now)
Has the duration passed between start_at and now?
Definition compatibility_feature.hpp:103
T elapsedSince(const T start_at, const T now)
Gets the elapsed time between start_at and now.
Definition compatibility_feature.hpp:70
Top level namespace of M5.
Definition base64.cpp:39
For utilities.