|
| | timer (const config &cfg, std::move_only_function< void()> callback) |
| | Creates a timer with a std::move_only_function callback.
|
| |
| | ~timer () |
| | Destroys the timer.
|
| |
| | timer (const timer &)=delete |
| |
| timer & | operator= (const timer &)=delete |
| |
| | timer (timer &&other) noexcept |
| |
| timer & | operator= (timer &&other) noexcept |
| |
| esp_timer_handle_t | idf_handle () const noexcept |
| | Returns the underlying ESP-IDF timer handle.
|
| |
| const std::string & | name () const noexcept |
| | Returns the timer name.
|
| |
| template<typename Rep , typename Period > |
| void | start_once (const std::chrono::duration< Rep, Period > &timeout) |
| | Starts the timer as a one-shot timer.
|
| |
| void | start_once (clock::time_point time) |
| | Starts the timer as a one-shot timer at an absolute time.
|
| |
| template<typename Rep , typename Period > |
| void | start_periodic (const std::chrono::duration< Rep, Period > &interval) |
| | Starts the timer as a periodic timer.
|
| |
| template<typename Rep , typename Period > |
| result< void > | try_start_once (const std::chrono::duration< Rep, Period > &timeout) |
| | Starts the timer as a one-shot timer.
|
| |
| result< void > | try_start_once (clock::time_point time) |
| | Starts the timer as a one-shot timer at an absolute time.
|
| |
| esp_err_t | try_start_once_isr (uint64_t timeout_us) |
| | Starts the timer as a one-shot timer (ISR-compatible).
|
| |
| template<typename Rep , typename Period > |
| result< void > | try_start_periodic (const std::chrono::duration< Rep, Period > &interval) |
| | Starts the timer as a periodic timer.
|
| |
| esp_err_t | try_start_periodic_isr (uint64_t interval_us) |
| | Starts the timer as a periodic timer (ISR-compatible).
|
| |
| template<typename Rep , typename Period > |
| void | restart (const std::chrono::duration< Rep, Period > &timeout) |
| | Restarts the timer with a new timeout.
|
| |
| template<typename Rep , typename Period > |
| result< void > | try_restart (const std::chrono::duration< Rep, Period > &timeout) |
| | Restarts the timer with a new timeout.
|
| |
| esp_err_t | try_restart_isr (uint64_t timeout_us) |
| | Restarts the timer with a new timeout (ISR-compatible).
|
| |
| void | stop () |
| | Stops the timer.
|
| |
| result< void > | try_stop () |
| | Stops the timer.
|
| |
| esp_err_t | try_stop_isr () |
| | Stops the timer (ISR-compatible).
|
| |
| bool | is_active () const noexcept |
| | Checks if the timer is currently running.
|
| |
| std::chrono::microseconds | period () const noexcept |
| | Returns the period of a periodic timer.
|
| |
| clock::time_point | expiry_time () const noexcept |
| | Returns the absolute expiry time for a one-shot timer.
|
| |
|
| static result< timer > | make (config cfg, std::move_only_function< void()> callback) |
| | Creates a timer with a std::move_only_function callback.
|
| |
| static result< timer > | make (config cfg, void(*callback)(void *), void *arg) |
| | Creates a timer with a raw function pointer callback.
|
| |
| template<typename Rep , typename Period > |
| static timer | start_once (config cfg, const std::chrono::duration< Rep, Period > &timeout, std::move_only_function< void()> callback) |
| | Creates and starts a one-shot timer with a std::move_only_function callback.
|
| |
| template<typename Rep , typename Period > |
| static timer | start_once (config cfg, const std::chrono::duration< Rep, Period > &timeout, void(*callback)(void *), void *arg) |
| | Creates and starts a one-shot timer with a raw function pointer callback.
|
| |
| static timer | start_once (config cfg, clock::time_point time, std::move_only_function< void()> callback) |
| | Creates and starts a one-shot timer at an absolute time with a std::move_only_function callback.
|
| |
| static timer | start_once (config cfg, clock::time_point time, void(*callback)(void *), void *arg) |
| | Creates and starts a one-shot timer at an absolute time with a raw function pointer callback.
|
| |
| template<typename Rep , typename Period > |
| static timer | start_periodic (config cfg, const std::chrono::duration< Rep, Period > &interval, std::move_only_function< void()> callback) |
| | Creates and starts a periodic timer with a std::move_only_function callback.
|
| |
| template<typename Rep , typename Period > |
| static timer | start_periodic (config cfg, const std::chrono::duration< Rep, Period > &interval, void(*callback)(void *), void *arg) |
| | Creates and starts a periodic timer with a raw function pointer callback.
|
| |
| template<typename Rep , typename Period > |
| static result< timer > | try_start_once (config cfg, const std::chrono::duration< Rep, Period > &timeout, std::move_only_function< void()> callback) |
| | Creates and starts a one-shot timer with a std::move_only_function callback.
|
| |
| template<typename Rep , typename Period > |
| static result< timer > | try_start_once (config cfg, const std::chrono::duration< Rep, Period > &timeout, void(*callback)(void *), void *arg) |
| | Creates and starts a one-shot timer with a raw function pointer callback.
|
| |
| static result< timer > | try_start_once (config cfg, clock::time_point time, std::move_only_function< void()> callback) |
| | Creates and starts a one-shot timer at an absolute time with a std::move_only_function callback.
|
| |
| static result< timer > | try_start_once (config cfg, clock::time_point time, void(*callback)(void *), void *arg) |
| | Creates and starts a one-shot timer at an absolute time with a raw function pointer callback.
|
| |
| template<typename Rep , typename Period > |
| static result< timer > | try_start_periodic (config cfg, const std::chrono::duration< Rep, Period > &interval, std::move_only_function< void()> callback) |
| | Creates and starts a periodic timer with a std::move_only_function callback.
|
| |
| template<typename Rep , typename Period > |
| static result< timer > | try_start_periodic (config cfg, const std::chrono::duration< Rep, Period > &interval, void(*callback)(void *), void *arg) |
| | Creates and starts a periodic timer with a raw function pointer callback.
|
| |
| static clock::time_point | next_alarm () |
| | Returns the time of the next scheduled timer event.
|
| |
High-resolution timer with microsecond precision.
Supports both one-shot and periodic timers with callbacks dispatched either from a dedicated timer task or directly from ISR context.
This type is non-copyable and move-only. Result-returning methods on a moved-from object return errc::invalid_state. Simple accessors return default/null values.
Definition at line 41 of file timer.hpp.
Creates and starts a one-shot timer at an absolute time with a std::move_only_function callback.
Combines timer creation and one-shot start into a single operation. The timer fires at the specified time point. If the time point is in the past, the timer fires as soon as possible.
- Warning
- This overload cannot be used with dispatch_method::isr.
- Parameters
-
| cfg | Timer configuration. |
| time | Absolute time at which the callback should be invoked. |
| callback | Function to call when timer fires. |
- Returns
- The new running timer.
- Note
- Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
- Exceptions
-
| std::system_error | on failure. |
Definition at line 212 of file timer.hpp.
References try_start_once(), and idfxx::unwrap().
Creates and starts a one-shot timer at an absolute time with a raw function pointer callback.
Combines timer creation and one-shot start into a single operation. The timer fires at the specified time point. If the time point is in the past, the timer fires as soon as possible.
- Note
- This overload is suitable for ISR dispatch.
- Parameters
-
| cfg | Timer configuration. |
| time | Absolute time at which the callback should be invoked. |
| callback | Function to call when timer fires. |
| arg | Argument passed to the callback. |
- Returns
- The new running timer.
- Note
- Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
- Exceptions
-
| std::system_error | on failure. |
Definition at line 233 of file timer.hpp.
References try_start_once(), and idfxx::unwrap().
Creates and starts a one-shot timer with a std::move_only_function callback.
Combines timer creation and one-shot start into a single operation. If creation succeeds but starting fails, the timer is automatically cleaned up via RAII.
- Warning
- This overload cannot be used with dispatch_method::isr.
using namespace std::chrono_literals;
{.name =
"my_timer"}, 100
ms,
- Template Parameters
-
| Rep | Duration representation type. |
| Period | Duration period type. |
- Parameters
-
| cfg | Timer configuration. |
| timeout | Time until the callback is invoked. |
| callback | Function to call when timer fires. |
- Returns
- The new running timer.
- Note
- Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
- Exceptions
-
| std::system_error | on failure. |
Definition at line 157 of file timer.hpp.
References idfxx::timeout, try_start_once(), and idfxx::unwrap().
Creates and starts a one-shot timer with a raw function pointer callback.
Combines timer creation and one-shot start into a single operation. If creation succeeds but starting fails, the timer is automatically cleaned up via RAII.
- Note
- This overload is suitable for ISR dispatch.
- Template Parameters
-
| Rep | Duration representation type. |
| Period | Duration period type. |
- Parameters
-
| cfg | Timer configuration. |
| timeout | Time until the callback is invoked. |
| callback | Function to call when timer fires. |
| arg | Argument passed to the callback. |
- Returns
- The new running timer.
- Note
- Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
- Exceptions
-
| std::system_error | on failure. |
Definition at line 185 of file timer.hpp.
References idfxx::timeout, try_start_once(), and idfxx::unwrap().
Creates and starts a periodic timer with a raw function pointer callback.
Combines timer creation and periodic start into a single operation. If creation succeeds but starting fails, the timer is automatically cleaned up via RAII.
- Note
- This overload is suitable for ISR dispatch.
- Template Parameters
-
| Rep | Duration representation type. |
| Period | Duration period type. |
- Parameters
-
| cfg | Timer configuration. |
| interval | Time between callback invocations. |
| callback | Function to call when timer fires. |
| arg | Argument passed to the callback. |
- Returns
- The new running timer.
- Note
- Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled.
- Exceptions
-
| std::system_error | on failure. |
Definition at line 290 of file timer.hpp.
References try_start_periodic(), and idfxx::unwrap().
Restarts the timer with a new timeout.
If the timer is running, it will be stopped and restarted. If not running, it will be started as a one-shot timer.
- Template Parameters
-
| Rep | Duration representation type. |
| Period | Duration period type. |
- Parameters
-
| timeout | Time until the callback is invoked. |
- Returns
- Success, or an error.
- Return values
-
| invalid_arg | Invalid timeout value. |
Definition at line 700 of file timer.hpp.
References idfxx::error(), idfxx::invalid_state, idfxx::timeout, and idfxx::wrap().
Referenced by restart().
Starts the timer as a one-shot timer at an absolute time.
The callback will be invoked once at the specified time point. If the time point is in the past, the timer fires as soon as possible.
- Parameters
-
| time | Absolute time at which the callback should be invoked. |
- Returns
- Success, or an error.
- Return values
-
| invalid_state | Timer is already running. |
Definition at line 605 of file timer.hpp.
References idfxx::error(), idfxx::invalid_state, idfxx::timer::clock::now(), and idfxx::wrap().
Creates and starts a one-shot timer at an absolute time with a std::move_only_function callback.
Combines timer creation and one-shot start into a single operation. The timer fires at the specified time point. If the time point is in the past, the timer fires as soon as possible.
- Warning
- This method cannot be used with dispatch_method::isr. Use the raw function pointer overload for ISR dispatch.
- Parameters
-
| cfg | Timer configuration. |
| time | Absolute time at which the callback should be invoked. |
| callback | Function to call when timer fires. |
- Returns
- The new running timer, or an error.
- Return values
-
| invalid_arg | Invalid configuration. |
| invalid_state | Timer could not be started. |
Definition at line 384 of file timer.hpp.
References idfxx::error(), and make().
Creates and starts a one-shot timer at an absolute time with a raw function pointer callback.
Combines timer creation and one-shot start into a single operation. The timer fires at the specified time point. If the time point is in the past, the timer fires as soon as possible.
- Note
- This overload is suitable for ISR dispatch.
- Parameters
-
| cfg | Timer configuration. |
| time | Absolute time at which the callback should be invoked. |
| callback | Function to call when timer fires. |
| arg | Argument passed to the callback. |
- Returns
- The new running timer, or an error.
- Return values
-
| invalid_arg | Invalid configuration. |
| invalid_state | Timer could not be started. |
Definition at line 415 of file timer.hpp.
References idfxx::error(), and make().
Creates and starts a one-shot timer with a std::move_only_function callback.
Combines timer creation and one-shot start into a single operation. If creation succeeds but starting fails, the timer is automatically cleaned up via RAII.
- Warning
- This method cannot be used with dispatch_method::isr. Use the raw function pointer overload for ISR dispatch.
- Template Parameters
-
| Rep | Duration representation type. |
| Period | Duration period type. |
- Parameters
-
| cfg | Timer configuration. |
| timeout | Time until the callback is invoked. |
| callback | Function to call when timer fires. |
- Returns
- The new running timer, or an error.
- Return values
-
| invalid_arg | Invalid configuration or timeout value. |
| invalid_state | Timer could not be started. |
Definition at line 316 of file timer.hpp.
References idfxx::error(), make(), and idfxx::timeout.
Referenced by start_once(), start_once(), start_once(), start_once(), start_once(), and start_once().
Creates and starts a one-shot timer with a raw function pointer callback.
Combines timer creation and one-shot start into a single operation. If creation succeeds but starting fails, the timer is automatically cleaned up via RAII.
- Note
- This overload is suitable for ISR dispatch.
- Template Parameters
-
| Rep | Duration representation type. |
| Period | Duration period type. |
- Parameters
-
| cfg | Timer configuration. |
| timeout | Time until the callback is invoked. |
| callback | Function to call when timer fires. |
| arg | Argument passed to the callback. |
- Returns
- The new running timer, or an error.
- Return values
-
| invalid_arg | Invalid configuration or timeout value. |
| invalid_state | Timer could not be started. |
Definition at line 353 of file timer.hpp.
References idfxx::error(), make(), and idfxx::timeout.
Creates and starts a periodic timer with a std::move_only_function callback.
Combines timer creation and periodic start into a single operation. If creation succeeds but starting fails, the timer is automatically cleaned up via RAII.
- Warning
- This method cannot be used with dispatch_method::isr. Use the raw function pointer overload for ISR dispatch.
- Template Parameters
-
| Rep | Duration representation type. |
| Period | Duration period type. |
- Parameters
-
| cfg | Timer configuration. |
| interval | Time between callback invocations. |
| callback | Function to call when timer fires. |
- Returns
- The new running timer, or an error.
- Return values
-
| invalid_arg | Invalid configuration or interval value. |
| invalid_state | Timer could not be started. |
Definition at line 447 of file timer.hpp.
References idfxx::error(), and make().
Referenced by start_periodic(), start_periodic(), and start_periodic().
Creates and starts a periodic timer with a raw function pointer callback.
Combines timer creation and periodic start into a single operation. If creation succeeds but starting fails, the timer is automatically cleaned up via RAII.
- Note
- This overload is suitable for ISR dispatch.
- Template Parameters
-
| Rep | Duration representation type. |
| Period | Duration period type. |
- Parameters
-
| cfg | Timer configuration. |
| interval | Time between callback invocations. |
| callback | Function to call when timer fires. |
| arg | Argument passed to the callback. |
- Returns
- The new running timer, or an error.
- Return values
-
| invalid_arg | Invalid configuration or interval value. |
| invalid_state | Timer could not be started. |
Definition at line 483 of file timer.hpp.
References idfxx::error(), and make().