Timers

class mpf.core.timer.Timer(machine, mode, name, config)

Bases: mpf.core.logging.LogMixin

Parent class for a mode timer.

Parameters:
  • machine -- The main MPF MachineController object.
  • mode -- The parent mode object that this timer belongs to.
  • name -- The string name of this timer.
  • config -- A Python dictionary which contains the configuration settings for this timer.

Methods & Attributes

The Timers has the following methods & attributes available. Note that methods & attributes inherited from the base class are not included here.

add(timer_value, **kwargs)

Add ticks to this timer.

Parameters:
  • timer_value -- The number of ticks you want to add to this timer's current value.
  • kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
change_tick_interval(change=0.0, **kwargs)

Change the interval for each "tick" of this timer.

Parameters:
  • change -- Float or int of the change you want to make to this timer's tick rate. Note this value is added to the current tick interval. To set an absolute value, use the set_tick_interval() method. To shorten the tick rate, use a negative value.
  • **kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
configure_logging(logger, console_level='basic', file_level='basic')

Configure the logging for the module this class is mixed into.

Parameters:
  • logger -- The string name of the logger to use
  • console_level -- The level of logging for the console. Valid options are "none", "basic", or "full".
  • file_level -- The level of logging for the console. Valid options are "none", "basic", or "full".
debug_log(msg, *args, **kwargs)

Log a message at the debug level.

Note that whether this message shows up in the console or log file is controlled by the settings used with configure_logging().

error_log(msg, *args, **kwargs)

Log a message at the error level.

These messages will always be shown in the console and the log file.

info_log(msg, *args, **kwargs)

Log a message at the info level.

Whether this message shows up in the console or log file is controlled by the settings used with configure_logging().

jump(timer_value, **kwargs)

Set the current amount of time of this timer.

This value is expressed in "ticks" since the interval per tick can be something other than 1 second).

Parameters:
  • timer_value -- Integer of the current value you want this timer to be.
  • **kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
kill()

Stop this timer and also removes all the control events.

pause(timer_value=0, **kwargs)

Pause the timer and posts the 'timer_<name>_paused' event.

Parameters:
  • timer_value -- How many seconds you want to pause the timer for. Note that this pause time is real-world seconds and does not take into consideration this timer's tick interval.
  • **kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
reset(**kwargs)

Reset this timer based to the starting value that's already been configured.

Does not start or stop the timer.

Parameters:**kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
restart(**kwargs)

Restart the timer by resetting it and then starting it.

Essentially this is just a reset() then a start().

Parameters:**kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
set_tick_interval(timer_value, **kwargs)

Set the number of seconds between ticks for this timer.

This is an absolute setting. To apply a change to the current value, use the change_tick_interval() method.

Parameters:
  • timer_value -- The new number of seconds between each tick of this timer. This value should always be positive.
  • **kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
start(**kwargs)

Start this timer based on the starting value that's already been configured.

Use jump() if you want to set the starting time value.

Parameters:**kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
stop(**kwargs)

Stop the timer and posts the 'timer_<name>_stopped' event.

Parameters:**kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
subtract(timer_value, **kwargs)

Subtract ticks from this timer.

Parameters:
  • timer_value -- The number of ticks you want to subtract from this timer's current value.
  • **kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
timer_complete(**kwargs)

Automatically called when this timer completes.

Posts the 'timer_<name>_complete' event. Can be manually called to mark this timer as complete.

Parameters:**kwargs -- Not used in this method. Only exists since this method is often registered as an event handler which may contain additional keyword arguments.
warning_log(msg, *args, **kwargs)

Log a message at the warning level.

These messages will always be shown in the console and the log file.