First you write a function that does whatever you want to do after the notifier delay. Say you want to activate a solenoid after the delay. The Notifier calls a function that takes a void pointer as an argument. We'll pass it a pointer to our solenoid and cast it back in the function so we can use it.
Here's the function:
Code:
void SolenoidDelayEventHandler(void* param)
{
//Cast the pointer back to the solenoid type
Solenoid* sol = (Solenoid*)param;
//Activate the solenoid
sol->Set(true);
}
Now, when we create our Notifier class, it wants two arguments: the function and what to pass to the function. We create it like so:
Code:
//As a member of your robot class,
Notifier solenoidNotifier;
//Then in the constructor of your robot class
solenoidNotifier(SolenoidDelayEventHandler, &mySolenoid)
//assuming mySolenoid is declared statically in the robot class as well
//and not with the keyword new
Now whenever you want to call your notifier function (and therefore activate the solenoid) after a delay time, just call
Code:
solenoidNotifier.StartSingle(time);
where time is the delay time in seconds. There's also a StartPeriodic(time) function in the Notifier class that calls the function continuously, where time is the delay between calls. It stops when you call Notifier::Stop().
Any questions?