{ Test / Demonstrate UMTimer.p macro commands. } {StartElapsed(elapsed timer number);} { (there are two elapsed time timers)} {This starts the specified elapsed time timer.} {secs := MeasureElapsed(1 or 2);} {This stops the specified elapsed time timer and reports} {the elapsed time in seconds to high resolution.} {StartDelay(delay timer number, time seconds);} { (there is only one delay timer so first argument is always 1)} {Starts the delay timer. Be sure to call KillDelay first unless } {you mean for the delay to start at the previous expiration.} {(Under system 6, the delay will probably start at the startDelay} {call rather than at the previous expiration even if KillDelay is not} {called, because a different version of the time manager is provided} {by the system software).} {KillDelay(1);} {Stops the delay timer without waiting for it to expire.} {Also, adjusts the timer so that the next delay will begin} {when the next StartDelay call is made, rather than when} {the previous delay expired.} {WaitDelay(1);} {Waits for the delay timer to expire, or command period.} {NOTE: delay starts at the pervious expiration, not at the} {StartDelay call, unless KillDelay was called first.} {Periodic timer calls have not been tested.} {StartPeriodic(periodic timer number, period seconds);} {(there is only one periodic timer so first argument is always 1)} {Start the periodic timer with specified period.} {Be careful, very small periods will hang the system.} {It may be possible to achieve the desired results using StartDelay} {and WaitDelay without KillDelay, and with no chance of hanging} {the system.} {KillPeriodic(1);} {stop the periodic timer without waiting.} {AdjustPeriodic(1,period,phase)} {Adjust the period and phase of periodic timer.} {if phase is negative next period will happen sooner} {if phase is positive next period will happen later} {period will change after next expiration.} {Be careful, very small periods will hang the system.} {p := WaitPeriodic(1,periodNumber);} {Wait for specified period to occur, and report how many} {periods have occurred.} var overhead: real; delayAdjust: real; macro 'measure timer overhead'; begin RequiresUser('timer',1); StartElapsed(1); overhead := MeasureElapsed(1); ShowMessage('Overhead is ',overhead:1:6,' seconds'); end; macro 'Delay 2.0 seconds'; var secs: Real; begin RequiresUser('timer',1); if delayAdjust < -0.010 then delayAdjust := -0.010; if delayAdjust > 0.010 then delayAdjust := 0.010; KillDelay(1); {interval starts at StartDelay} StartElapsed(1); StartDelay(1,2.0 + delayAdjust); WaitDelay(1); secs := MeasureElapsed(1); delayAdjust := delayAdjust + 2.0 - secs; ShowMessage('Elapsed time is ',secs:1:6,' seconds', '\DelayAdjust is ',delayAdjust:1:6,' secs'); end;