Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   How to write Notifier help!! (http://www.chiefdelphi.com/forums/showthread.php?t=82700)

Rikard023 15-02-2010 08:34

How to write Notifier help!!
 
OK im trying to write a notifier class to cause a delay in my program where one task would be preformed after another with a specific delay.

I get to the part where i named what the notifier is but when the little box appears after i put the name then -> the box says

Notifier(TimerEventHandler handler, void *param)

Now i dont know whatvalues to put in or what any of this means

Any documentation or code any one could give me to simply write a notifier would be much appreciated

slavik262 15-02-2010 10:07

Re: How to write Notifier help!!
 
I'll post some help later tonight.

slavik262 16-02-2010 23:33

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?

gvarndell 17-02-2010 05:01

Re: How to write Notifier help!!
 
Quote:

Originally Posted by slavik262 (Post 921744)
Any questions?

Yes. :]

I just downloaded the WPILibSource20100107.zip because I am curious how they implemented the notifiers.
Is that the latest library source from WPI as far as you know?
THX!

slavik262 17-02-2010 08:40

Re: How to write Notifier help!!
 
Quote:

Originally Posted by gvarndell (Post 921874)
Yes. :]

I just downloaded the WPILibSource20100107.zip because I am curious how they implemented the notifiers.
Is that the latest library source from WPI as far as you know?
THX!

Off the top of my head, I don't know the current version number and I can't download the newest update to check since I'm at school at the moment.

As far as how notifiers work, they seem to work on an interrupt level (I'm assuming through a hardware timer run in the FPGA). This is just a guess from glancing over the header file; anyone can feel free to confirm or correct me here.

Rikard023 20-02-2010 07:56

Re: How to write Notifier help!!
 
I still need help with the notifier if anyone else has info

kinda close to ship date :eek:

Rikard023 20-02-2010 08:12

Re: How to write Notifier help!!
 
Quote:

Originally Posted by gvarndell (Post 921874)
Yes. :]

I just downloaded the WPILibSource20100107.zip because I am curious how they implemented the notifiers.
Is that the latest library source from WPI as far as you know?
THX!

And the last workbench update is WorkbenchUpdate20100217.exe
http://first.wpi.edu/Images/CMS/Firs...te20100217.exe


All times are GMT -5. The time now is 13:54.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi