View Single Post
  #3   Spotlight this post!  
Unread 16-02-2010, 23:33
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: How to write Notifier help!!

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?
__________________
Reply With Quote