Skip to content
ggodart edited this page Jan 6, 2021 · 1 revision

Timer

See original

SYNOPSIS

  $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'";
  }

DESCRIPTION

The Timer object can be used to run an action one or more times, at a specified interval.

INHERITS

INI PARAMETERS

METHODS

Method Description
new Used to create the object.
set($period, $action, $cycles) $periodis 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.
unset Unset the timer. 'set $my_timer 0' has the same effect.
run_action Runs the timers action, even if the timer has not expired.
expired Returns true for the one pass after the timer has expired.
hours_remaining,
hours_remaining_now,
minutes_remaining,
minutes_remaining_now,
seconds_remaining,
`econds_remaining_now
These 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.
active Returns true if the timer is still running.
inactive Returns true if the timer is has expired or has not been set.
start Starts the timer
restart Restarts the timer (start on an active timer does nothing)
stop Stops a timer.
pause Pauses
resume Bet you can guess :)
query Returns the seconds on the timer.
get_type() Returns the class (or type, in MisterHouse terminology) of this item.

AUTHOR

Clone this wiki locally