mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 15:18:54 +08:00
drv_hrt: add user-defined integer literals for time constants
The goal is to improve the readability for expressions like: if (hrt_elapsed_time(&start_time) > 8000000) Available since C++11
This commit is contained in:
@@ -194,3 +194,33 @@ __EXPORT extern void hrt_stop_delay_delta(hrt_abstime delta);
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace time_literals
|
||||
{
|
||||
|
||||
// User-defined integer literals for different time units.
|
||||
// The base unit is hrt_abstime in microseconds
|
||||
|
||||
constexpr hrt_abstime operator "" _s(unsigned long long seconds)
|
||||
{
|
||||
return hrt_abstime(seconds * 1000000ULL);
|
||||
}
|
||||
|
||||
constexpr hrt_abstime operator "" _ms(unsigned long long seconds)
|
||||
{
|
||||
return hrt_abstime(seconds * 1000ULL);
|
||||
}
|
||||
|
||||
constexpr hrt_abstime operator "" _us(unsigned long long seconds)
|
||||
{
|
||||
return hrt_abstime(seconds);
|
||||
}
|
||||
|
||||
} /* namespace time_literals */
|
||||
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
Reference in New Issue
Block a user