40 #ifndef _extendedtimer_cpp
41 #define _extendedtimer_cpp
43 #include "extendedtimer.h"
44 #include "eventmanager.h"
51 Type = Timer::Extended;
83 UpdateAsNormal(MicroSecondsElapsed);
87 UpdateAsStopWatch(MicroSecondsElapsed);
91 Callback->DoCallbackItems();
100 UpdateAsNormal(MicroSecondsElapsed);
104 Callback->DoCallbackItems();
115 void ExtendedTimer::UpdateAsNormal(
const Whole MicroSecondsElapsed)
117 CurrentTime.Microseconds+=(
Integer)MicroSecondsElapsed;
125 void ExtendedTimer::UpdateAsStopWatch(
const Whole MicroSecondsElapsed)
127 CurrentTime.Microseconds-=MicroSecondsElapsed;
128 if(CurrentTime.Microseconds < 0)
130 Whole GoesInto = CurrentTime.Microseconds * 0.001;
131 Whole Remainder = CurrentTime.Microseconds - GoesInto * 1000;
132 CurrentTime.Microseconds = Remainder;
133 CurrentTime.Milliseconds+=GoesInto;
135 if(CurrentTime.Milliseconds < 0)
137 Integer GoesInto = CurrentTime.Milliseconds * 0.001;
138 Integer Remainder = CurrentTime.Milliseconds - GoesInto * 1000;
139 CurrentTime.Milliseconds = Remainder;
140 CurrentTime.Seconds+=GoesInto;
142 if(CurrentTime.Seconds < 0)
144 Integer GoesInto = CurrentTime.Seconds / 60;
145 Integer Remainder = CurrentTime.Seconds - GoesInto * 60;
146 CurrentTime.Seconds = Remainder;
147 CurrentTime.Minutes+=GoesInto;
149 if(CurrentTime.Minutes < 0)
151 Integer GoesInto = CurrentTime.Minutes / 60;
152 Integer Remainder = CurrentTime.Minutes - GoesInto * 60;
153 CurrentTime.Minutes = Remainder;
154 CurrentTime.Hours+=GoesInto;
156 if(CurrentTime.Hours < 0)
158 Integer GoesInto = CurrentTime.Hours / 24;
159 Integer Remainder = CurrentTime.Hours - GoesInto * 24;
160 CurrentTime.Hours = Remainder;
161 CurrentTime.Days+=GoesInto;
167 if(GetStruct(Struct).Microseconds > 1000)
169 Integer GoesInto = GetStruct(Struct).Microseconds * 0.001;
170 Integer Remainder = GetStruct(Struct).Microseconds - GoesInto * 1000;
171 GetStruct(Struct).Microseconds = Remainder;
172 GetStruct(Struct).Milliseconds+=GoesInto;
174 }
else{
return false; }
179 if(GetStruct(Struct).Milliseconds > 1000)
181 Integer GoesInto = GetStruct(Struct).Milliseconds * 0.001;
182 Integer Remainder = GetStruct(Struct).Milliseconds - GoesInto * 1000;
183 GetStruct(Struct).Milliseconds = Remainder;
184 GetStruct(Struct).Seconds+=GoesInto;
186 }
else{
return false; }
191 if(GetStruct(Struct).Seconds > 60)
193 Integer GoesInto = GetStruct(Struct).Seconds / 60;
194 Integer Remainder = GetStruct(Struct).Seconds - GoesInto * 60;
195 GetStruct(Struct).Seconds = Remainder;
196 GetStruct(Struct).Minutes+=GoesInto;
198 }
else{
return false; }
203 if(GetStruct(Struct).Minutes > 60)
205 Integer GoesInto = GetStruct(Struct).Minutes / 60;
206 Integer Remainder = GetStruct(Struct).Minutes - GoesInto * 60;
207 GetStruct(Struct).Minutes = Remainder;
208 GetStruct(Struct).Hours+=GoesInto;
210 }
else{
return false; }
215 if(GetStruct(Struct).Hours > 24)
217 Integer GoesInto = GetStruct(Struct).Hours / 24;
218 Integer Remainder = GetStruct(Struct).Hours - GoesInto * 24;
219 GetStruct(Struct).Hours = Remainder;
220 GetStruct(Struct).Days+=GoesInto;
222 }
else{
return false; }
232 if(CheckMicroSeconds(Struct) || CheckMilliSeconds(Struct) || CheckSeconds(Struct)
233 || CheckMinutes(Struct) || CheckHours(Struct) || CheckDays(Struct))
236 }
else{
return false; }
239 bool ExtendedTimer::CompareCurrentAndGoal(
const Integer Current,
const Integer Goal)
250 bool ExtendedTimer::GoalReached()
252 if(CurrentTime.Days == GoalTime.Days)
254 if(CurrentTime.Hours == GoalTime.Hours)
256 if(CurrentTime.Minutes == GoalTime.Minutes)
258 if(CurrentTime.Seconds == GoalTime.Seconds)
260 if(CurrentTime.Milliseconds == GoalTime.Milliseconds)
262 if(CurrentTime.Microseconds == GoalTime.Microseconds)
266 else if (CompareCurrentAndGoal(CurrentTime.Microseconds,GoalTime.Microseconds))
267 {
return true; }
else{
return false; }
269 else if (CompareCurrentAndGoal(CurrentTime.Milliseconds,GoalTime.Milliseconds))
270 {
return true; }
else{
return false; }
272 else if (CompareCurrentAndGoal(CurrentTime.Seconds,GoalTime.Seconds))
273 {
return true; }
else{
return false; }
275 else if (CompareCurrentAndGoal(CurrentTime.Minutes,GoalTime.Minutes))
276 {
return true; }
else{
return false; }
278 else if (CompareCurrentAndGoal(CurrentTime.Hours,GoalTime.Hours))
279 {
return true; }
else{
return false; }
281 else if (CompareCurrentAndGoal(CurrentTime.Days,GoalTime.Days))
282 {
return true; }
else{
return false; }
287 CurrentTime.Milliseconds = InitialTime.Milliseconds;
288 CurrentTime.Seconds = InitialTime.Seconds;
289 CurrentTime.Minutes = InitialTime.Minutes;
290 CurrentTime.Hours = InitialTime.Hours;
291 CurrentTime.Days = InitialTime.Days;
296 ResetAtGoal = AutoReset;
302 GetStruct(Struct).Microseconds = MS;
309 GetStruct(Struct).Milliseconds = MS;
310 CheckMilliSeconds(Struct);
311 CheckSeconds(Struct);
312 CheckMinutes(Struct);
319 GetStruct(Struct).Seconds = Sec;
320 CheckSeconds(Struct);
321 CheckMinutes(Struct);
328 GetStruct(Struct).Minutes = Min;
329 CheckMinutes(Struct);
336 GetStruct(Struct).Hours = Hr;
343 GetStruct(Struct).Days = Day;
349 return GetStruct(Struct).Milliseconds;
354 return GetStruct(Struct).Seconds;
359 return GetStruct(Struct).Minutes;
364 return GetStruct(Struct).Hours;
369 return GetStruct(Struct).Days;