| Timer.pm |
Timer
$timer_laundary = new Timer;
$v_laundary_timer = new Voice_Cmd('Laundary timer [on,off]');
if ($state = said $v_laundary_timer) {
if ($state eq ON) {
play('rooms' => 'shop', 'file' => 'cloths_started.wav');
set $timer_laundary 35*60, 'speak "rooms=all The laundary clothes done"', 4;
}
else {
speak 'rooms=shop The laundry timer has been turned off.';
unset $timer_laundary;
}
}
This example uses an anonymous subroutine
$v_test_delay = new Voice_Cmd 'Test timer with [1,5,10] seconds';
if ($state = said $v_test_delay) {
print_log "Starting $state second timer test";
my $timer = new Timer;
set $timer $state, sub {
print_log "Ending $state second timer test";
}
# set $timer $state, "print_log 'Ending $state second timer test'";
}
The Timer object can be used to run an action one or more times, at a specified interval.
newUsed to create the object.
set($period, $action, $cycles)$period is the timer period in seconds $action (optional) is the code (either a string or a code reference) to run when the timer expires $cycles (optional) is how many times to repeat the timer. Set to -1 to repeat forever.
unsetUnset the timer. 'set $my_timer 0' has the same effect.
run_actionRuns the timers action, even if the timer has not expired.
expiredReturns true for the one pass after the timer has expired.
hours_remaining, hours_remaining_now, minutes_remaining, minutes_remaining_now, seconds_remaining, seconds_remaining_nowThese methods return the hours, minutes or seconds remaining on the timer. The _now methods only return the remaining time on the hour, minute, or second boundary.
activeReturns true if the timer is still running.
inactiveReturns true if the timer is has expired or has not been set.
startStarts the timer
restartRestarts the timer (start on an active timer does nothing)
stopStops a timer.
pausePauses
resumeBet you can guess :)
queryReturns the seconds on the timer.
get_type()Returns the class (or type, in Misterhouse terminology) of this item.
NONE
UNK
See mh/code/bruce/timers.pl for more examples
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
| Timer.pm |