Treehopper C# API
Poller< TPollable > Class Template Reference

Polls an IPollable device at a regular rate More...

Inheritance diagram for Poller< TPollable >:

Public Member Functions

delegate void NewSensorValueEventHandler (object sender, EventArgs e)
 The signature of the callback to use with the OnNewSensorValue event More...
 
 Poller (TPollable sensor, int samplePeriod=10, bool usePrecisionTimer=false)
 Construct a new Poller for the given sensor More...
 
void Dispose ()
 Stops the sampling thread safely and closes resources More...
 

Properties

TPollable Sensor [get]
 The underlying sensor that is polled by this instance More...
 

Events

PropertyChangedEventHandler PropertyChanged
 Fires whenever the sensor value is updated More...
 
NewSensorValueEventHandler OnNewSensorValue
 Fires whenever the sensor value is updated More...
 

Detailed Description

Polls an IPollable device at a regular rate

Template Parameters
TPollableThe IPollable device to poll

While simple devices (such as temperature sensors) can simply auto-update whenever the relevant properties are read from, it is often useful to continuously update these values on a background thread so that the IPollable device can fire events. This is especially true for GPIO port expanders used as inputs in event-driven programming.

Since this class implements INotifyPropertyChanged, WPF and XAML applications can bind directly to properties of the underlying sensor in this class, and GUI controls will be automatically updated

Type Constraints
TPollable :IPollable 

Constructor & Destructor Documentation

◆ Poller()

Poller ( TPollable  sensor,
int  samplePeriod = 10,
bool  usePrecisionTimer = false 
)

Construct a new Poller for the given sensor

Parameters
sensorThe sensor to construct a Poller for
samplePeriodThe sample period, in milliseconds, to poll this sensor at
usePrecisionTimerWhether to use a (CPU-heavy) precision timer

When usePrecisionTimer is set to true, a busy-wait timer will be used. All things considered, this provides for relatively precise timing (even given USB latencies, there is often less than 100 microseconds of jitter), but this will cause dramatic increases in CPU usage. We recommend enabling this only in scenarios where you absolutely need low-jitter sampling.

Member Function Documentation

◆ NewSensorValueEventHandler()

delegate void NewSensorValueEventHandler ( object  sender,
EventArgs  e 
)

The signature of the callback to use with the OnNewSensorValue event

Parameters
senderThe Poller where this call originated from
eAn empty EventArgs

◆ Dispose()

void Dispose ( )

Stops the sampling thread safely and closes resources

Property Documentation

◆ Sensor

TPollable Sensor
get

The underlying sensor that is polled by this instance

Event Documentation

◆ PropertyChanged

PropertyChangedEventHandler PropertyChanged

Fires whenever the sensor value is updated

◆ OnNewSensorValue

NewSensorValueEventHandler OnNewSensorValue

Fires whenever the sensor value is updated


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