Flipper Zero Firmware
Loading...
Searching...
No Matches
event_loop_timer.h File Reference

Software timer functionality for FuriEventLoop. More...

#include "event_loop.h"

Go to the source code of this file.

Typedefs

typedef void(* FuriEventLoopTimerCallback) (void *context)
 Timer callback type for functions to be called when a timer expires.
 
typedef struct FuriEventLoopTimer FuriEventLoopTimer
 Opaque event loop timer type.
 

Enumerations

enum  FuriEventLoopTimerType { FuriEventLoopTimerTypeOnce = 0 , FuriEventLoopTimerTypePeriodic = 1 }
 Enumeration of possible timer types. More...
 

Functions

FuriEventLoopTimerfuri_event_loop_timer_alloc (FuriEventLoop *instance, FuriEventLoopTimerCallback callback, FuriEventLoopTimerType type, void *context)
 Create a new event loop timer instance.
 
void furi_event_loop_timer_free (FuriEventLoopTimer *timer)
 Delete an event loop timer instance.
 
void furi_event_loop_timer_start (FuriEventLoopTimer *timer, uint32_t interval)
 Start a timer or restart it with a new interval.
 
void furi_event_loop_timer_restart (FuriEventLoopTimer *timer)
 Restart a timer with the previously set interval.
 
void furi_event_loop_timer_stop (FuriEventLoopTimer *timer)
 Stop a timer without firing its callback.
 
uint32_t furi_event_loop_timer_get_remaining_time (const FuriEventLoopTimer *timer)
 Get the time remaining before the timer becomes expires.
 
uint32_t furi_event_loop_timer_get_interval (const FuriEventLoopTimer *timer)
 Get the timer interval.
 
bool furi_event_loop_timer_is_running (const FuriEventLoopTimer *timer)
 Check if the timer is currently running.
 

Detailed Description

Software timer functionality for FuriEventLoop.

Typedef Documentation

◆ FuriEventLoopTimerCallback

typedef void(* FuriEventLoopTimerCallback) (void *context)

Timer callback type for functions to be called when a timer expires.

In the timer callback, it is ALLOWED:

  • To start, stop, or restart an existing timer,
  • To create new timers using furi_event_loop_timer_alloc(),
  • To delete timers using furi_event_loop_timer_free().
Parameters
[in,out]contextpointer to a user-specific object that was provided during timer creation

Enumeration Type Documentation

◆ FuriEventLoopTimerType

Enumeration of possible timer types.

Enumerator
FuriEventLoopTimerTypeOnce 

One-shot timer.

FuriEventLoopTimerTypePeriodic 

Repeating timer.

Function Documentation

◆ furi_event_loop_timer_alloc()

FuriEventLoopTimer * furi_event_loop_timer_alloc ( FuriEventLoop * instance,
FuriEventLoopTimerCallback callback,
FuriEventLoopTimerType type,
void * context )

Create a new event loop timer instance.

Parameters
[in,out]instancepointer to the current FuriEventLoop instance
[in]callbackpointer to the callback function to be executed upon timer timeout
[in]typetimer type value to determine its behavior (single-shot or periodic)
[in,out]contextpointer to a user-specific object (will be passed to the callback)
Returns
pointer to the created timer instance

◆ furi_event_loop_timer_free()

void furi_event_loop_timer_free ( FuriEventLoopTimer * timer)

Delete an event loop timer instance.

Warning
The user code MUST call furi_event_loop_timer_free() on ALL instances associated with the current event loop BEFORE calling furi_event_loop_free(). The event loop may EITHER be running OR stopped when the timers are being deleted.
Parameters
[in,out]timerpointer to the timer instance to be deleted

◆ furi_event_loop_timer_get_interval()

uint32_t furi_event_loop_timer_get_interval ( const FuriEventLoopTimer * timer)

Get the timer interval.

Parameters
[in]timerpointer to the timer to be queried
Returns
timer interval in ticks

◆ furi_event_loop_timer_get_remaining_time()

uint32_t furi_event_loop_timer_get_remaining_time ( const FuriEventLoopTimer * timer)

Get the time remaining before the timer becomes expires.

For stopped or expired timers, this function returns 0.

Parameters
[in]timerpointer to the timer to be queried
Returns
remaining time in ticks

◆ furi_event_loop_timer_is_running()

bool furi_event_loop_timer_is_running ( const FuriEventLoopTimer * timer)

Check if the timer is currently running.

A timer is considered running if it has not expired yet.

Parameters
[in]timerpointer to the timer to be queried
Returns
true if the timer is running, false otherwise

◆ furi_event_loop_timer_restart()

void furi_event_loop_timer_restart ( FuriEventLoopTimer * timer)

Restart a timer with the previously set interval.

Parameters
[in,out]timerpointer to the timer instance to be restarted

◆ furi_event_loop_timer_start()

void furi_event_loop_timer_start ( FuriEventLoopTimer * timer,
uint32_t interval )

Start a timer or restart it with a new interval.

Parameters
[in,out]timerpointer to the timer instance to be (re)started
[in]intervaltimer interval in ticks

◆ furi_event_loop_timer_stop()

void furi_event_loop_timer_stop ( FuriEventLoopTimer * timer)

Stop a timer without firing its callback.

It is safe to call this function on an already stopped timer (it will do nothing).

Parameters
[in,out]timerpointer to the timer instance to be stopped