WPILibC++ 2024.3.2
frc::Notifier Class Reference

Notifiers run a user-provided callback function on a separate thread. More...

#include <frc/Notifier.h>

Public Member Functions

 Notifier (std::function< void()> callback)
 Create a Notifier with the given callback. More...
 
template<typename Arg , typename... Args>
 Notifier (std::invocable< Arg, Args... > auto &&callback, Arg &&arg, Args &&... args)
 
 Notifier (int priority, std::function< void()> callback)
 Create a Notifier with the given callback. More...
 
template<typename Arg , typename... Args>
 Notifier (int priority, std::invocable< Arg, Args... > auto &&callback, Arg &&arg, Args &&... args)
 
 ~Notifier ()
 Free the resources for a timer event. More...
 
 Notifier (Notifier &&rhs)
 
Notifieroperator= (Notifier &&rhs)
 
void SetName (std::string_view name)
 Sets the name of the notifier. More...
 
void SetHandler (std::function< void()> callback)
 Change the callback function. More...
 
void SetCallback (std::function< void()> callback)
 Change the callback function. More...
 
void StartSingle (units::second_t delay)
 Run the callback once after the given delay. More...
 
void StartPeriodic (units::second_t period)
 Run the callback periodically with the given period. More...
 
void Stop ()
 Stop further callback invocations. More...
 

Static Public Member Functions

static bool SetHALThreadPriority (bool realTime, int32_t priority)
 Sets the HAL notifier thread priority. More...
 

Detailed Description

Notifiers run a user-provided callback function on a separate thread.

If StartSingle() is used, the callback will run once. If StartPeriodic() is used, the callback will run repeatedly with the given period until stop() is called.

Constructor & Destructor Documentation

◆ Notifier() [1/5]

frc::Notifier::Notifier ( std::function< void()>  callback)
explicit

Create a Notifier with the given callback.

Configure when the callback runs with StartSingle() or StartPeriodic().

Parameters
callbackThe callback to run.

◆ Notifier() [2/5]

template<typename Arg , typename... Args>
frc::Notifier::Notifier ( std::invocable< Arg, Args... > auto &&  callback,
Arg &&  arg,
Args &&...  args 
)
inline

◆ Notifier() [3/5]

frc::Notifier::Notifier ( int  priority,
std::function< void()>  callback 
)
explicit

Create a Notifier with the given callback.

Configure when the callback runs with StartSingle() or StartPeriodic().

This overload makes the underlying thread run with a real-time priority. This is useful for reducing scheduling jitter on processes which are sensitive to timing variance, like model-based control.

Parameters
priorityThe FIFO real-time scheduler priority ([1..99] where a higher number represents higher priority). See "man 7 sched" for more details.
callbackThe callback to run.

◆ Notifier() [4/5]

template<typename Arg , typename... Args>
frc::Notifier::Notifier ( int  priority,
std::invocable< Arg, Args... > auto &&  callback,
Arg &&  arg,
Args &&...  args 
)
inline

◆ ~Notifier()

frc::Notifier::~Notifier ( )

Free the resources for a timer event.

◆ Notifier() [5/5]

frc::Notifier::Notifier ( Notifier &&  rhs)

Member Function Documentation

◆ operator=()

Notifier & frc::Notifier::operator= ( Notifier &&  rhs)

◆ SetCallback()

void frc::Notifier::SetCallback ( std::function< void()>  callback)

Change the callback function.

Parameters
callbackThe callback function.

◆ SetHALThreadPriority()

static bool frc::Notifier::SetHALThreadPriority ( bool  realTime,
int32_t  priority 
)
static

Sets the HAL notifier thread priority.

The HAL notifier thread is responsible for managing the FPGA's notifier interrupt and waking up user's Notifiers when it's their time to run. Giving the HAL notifier thread real-time priority helps ensure the user's real-time Notifiers, if any, are notified to run in a timely manner.

Parameters
realTimeSet to true to set a real-time priority, false for standard priority.
priorityPriority to set the thread to. For real-time, this is 1-99 with 99 being highest. For non-real-time, this is forced to 0. See "man 7 sched" for more details.
Returns
True on success.

◆ SetHandler()

void frc::Notifier::SetHandler ( std::function< void()>  callback)

Change the callback function.

Parameters
callbackThe callback function.
Deprecated:
Use SetCallback() instead.

◆ SetName()

void frc::Notifier::SetName ( std::string_view  name)

Sets the name of the notifier.

Used for debugging purposes only.

Parameters
nameName

◆ StartPeriodic()

void frc::Notifier::StartPeriodic ( units::second_t  period)

Run the callback periodically with the given period.

The user-provided callback should be written so that it completes before the next time it's scheduled to run.

Parameters
periodPeriod after which to to call the callback starting one period after the call to this method.

◆ StartSingle()

void frc::Notifier::StartSingle ( units::second_t  delay)

Run the callback once after the given delay.

Parameters
delayTime to wait before the callback is called.

◆ Stop()

void frc::Notifier::Stop ( )

Stop further callback invocations.

No further periodic callbacks will occur. Single invocations will also be cancelled if they haven't yet occurred.

If a callback invocation is in progress, this function will block until the callback is complete.


The documentation for this class was generated from the following file: