CMTimer Class Reference

Programing timers. More...

Public Member Functions

 CMTimer (unsigned long int usec)
 ~CMTimer ()
int check ()

Private Member Functions

void setTimerUsec ()

Private Attributes

unsigned long int usec
unsigned long int sec
struct timeval tv_end

Detailed Description

Examples:

TestDoubleEngine.cpp, TestSoftServo.cpp, and TestTimer.cpp.


Constructor & Destructor Documentation

CMTimer::CMTimer ( unsigned long int  usec  ) 

Constructor.

00033 {
00034   if ( usec >= 1000000 )
00035   {
00036     this->sec = (long int)(usec/1000000);
00037     this->usec = (long int)(fmod(usec,1000000));
00038   }
00039   else
00040   {
00041     this->sec = 0;
00042     this->usec = usec;
00043   }
00044     
00045   this->setTimerUsec();
00046 }

CMTimer::~CMTimer (  ) 

Destructor.

00049 {}


Member Function Documentation

int CMTimer::check (  ) 

The function that checks if the time has elapsed.

Returns:
1 if the time has elapsed else return 0.
Examples:
TestDoubleEngine.cpp, TestSoftServo.cpp, and TestTimer.cpp.

00067 { 
00068     struct timeval tv_now;  
00069     gettimeofday(&tv_now,NULL);  
00070 
00071     //If seconds now are bigger than seconds end or seconds now = seconds end
00072     // and useconds now bigger or equal than useconds end
00073     if( (tv_now.tv_sec > this->tv_end.tv_sec) || 
00074     ( (tv_now.tv_sec == this->tv_end.tv_sec) && (tv_now.tv_usec >= this->tv_end.tv_usec) ) )
00075     {
00076         this->setTimerUsec();
00077         return 1;
00078     }
00079     else  
00080         return 0;
00081   }

void CMTimer::setTimerUsec (  )  [private]

The function to update the tv_end with the microseconds and seconds we want to wait.

00052 {
00053   gettimeofday(&this->tv_end,NULL);
00054   if ((this->tv_end.tv_usec + this->usec) < 1000000)
00055   {
00056     this->tv_end.tv_usec += this->usec;
00057     this->tv_end.tv_sec += this->sec;
00058   }
00059   else
00060   {
00061     this->tv_end.tv_usec = (this->tv_end.tv_usec + this->usec - 1000000);
00062     this->tv_end.tv_sec += this->sec + 1;
00063   } 
00064 }


Field Documentation

unsigned long int CMTimer::sec [private]

The seconds to wait.

struct timeval CMTimer::tv_end [private]

The variable to manage the time.

unsigned long int CMTimer::usec [private]

The microseconds to wait.

 All Data Structures Functions Variables
Generated on Mon Sep 12 07:59:09 2011 for API MokArdu by  doxygen 1.6.3