2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
argos_lib::NTSubscriber Class Reference

Subscribes to Network Tables entry updates and calls a specified callback to use the new value. More...

#include <nt_subscriber.h>

Public Member Functions

 NTSubscriber (const std::string &tableName)
 Construct a new NTSubscriber object.
 
 ~NTSubscriber ()
 
void AddMonitor (const std::string &keyName, std::function< void(double)> onUpdateCallback, const double defaultValue=0.0, const bool forceUpdate=true)
 Register a new listener for the specified key and send values to callback on update.
 

Private Attributes

const std::string m_tableName
 Table containing keys to monitor.
 
std::vector< NT_Entry > m_ntEntries
 Publish/subscribe entries.
 
std::vector< NT_Listener > m_ntListeners
 Entry listeners.
 

Detailed Description

Subscribes to Network Tables entry updates and calls a specified callback to use the new value.

Constructor & Destructor Documentation

◆ NTSubscriber()

NTSubscriber::NTSubscriber ( const std::string &  tableName)
explicit

Construct a new NTSubscriber object.

Parameters
tableNameName of the table containing keys to watch

◆ ~NTSubscriber()

NTSubscriber::~NTSubscriber ( )

Member Function Documentation

◆ AddMonitor()

void NTSubscriber::AddMonitor ( const std::string &  keyName,
std::function< void(double)>  onUpdateCallback,
const double  defaultValue = 0.0,
const bool  forceUpdate = true 
)

Register a new listener for the specified key and send values to callback on update.

Parameters
keyNameKey to listen for updates. Will be at tableName/keyName (keyName can have more slashes)
onUpdateCallbackCallback to run when keyName changes
defaultValueDefault value to initialize key if it doesn't exist yet
forceUpdateWhen true, update network tables value to default even if another value is already set

Member Data Documentation

◆ m_ntEntries

std::vector<NT_Entry> argos_lib::NTSubscriber::m_ntEntries
private

Publish/subscribe entries.

◆ m_ntListeners

std::vector<NT_Listener> argos_lib::NTSubscriber::m_ntListeners
private

Entry listeners.

◆ m_tableName

const std::string argos_lib::NTSubscriber::m_tableName
private

Table containing keys to monitor.


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