Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Contains the Driver parent class."""
from typing import Optional
from mpf.core.delays import DelayManager
from mpf.core.events import event_handler
from mpf.core.machine import MachineController
from mpf.core.platform import DriverPlatform, DriverConfig
from mpf.core.system_wide_device import SystemWideDevice
from mpf.exceptions.driver_limits_error import DriverLimitsError
from mpf.platforms.interfaces.driver_platform_interface import DriverPlatformInterface, PulseSettings, HoldSettings
class Driver(SystemWideDevice):
"""Generic class that holds driver objects.
A 'driver' is any device controlled from a driver board which is typically
the high-voltage stuff like coils and flashers.
This class exposes the methods you should use on these driver types of
devices. Each platform module (i.e. P-ROC, FAST, etc.) subclasses this
class to actually communicate with the physical hardware and perform the
actions.
Args: Same as the Device parent class
"""
config_section = 'coils'
collection = 'coils'
"""Contains the Switch parent class."""
import copy
from mpf.core.device_monitor import DeviceMonitor
from mpf.core.machine import MachineController
from mpf.core.system_wide_device import SystemWideDevice
@DeviceMonitor("state", "recycle_jitter_count")
class Switch(SystemWideDevice):
"""A switch in a pinball machine."""
config_section = 'switches'
collection = 'switches'
class_label = 'switch'
def __init__(self, machine: MachineController, name):
"""Initialise switch."""
self.hw_switch = None
super().__init__(machine, name)
self.deactivation_events = set()
self.activation_events = set()
self.state = 0
""" The logical state of a switch. 1 = active, 0 = inactive. This takes
"""Contains the MultiBall device class."""
from mpf.core.enable_disable_mixin import EnableDisableMixin
from mpf.core.delays import DelayManager
from mpf.core.device_monitor import DeviceMonitor
from mpf.core.events import event_handler
from mpf.core.mode_device import ModeDevice
from mpf.core.placeholder_manager import NativeTypeTemplate
from mpf.core.system_wide_device import SystemWideDevice
@DeviceMonitor("shoot_again", "balls_added_live", "balls_live_target")
class Multiball(EnableDisableMixin, SystemWideDevice, ModeDevice):
"""Multiball device for MPF."""
config_section = 'multiballs'
collection = 'multiballs'
class_label = 'multiball'
__slots__ = ["ball_locks", "source_playfield", "delay", "balls_added_live", "balls_live_target", "shoot_again"]
def __init__(self, machine, name):
"""Initialise multiball."""
self.ball_locks = None
self.source_playfield = None
super().__init__(machine, name)
self.delay = DelayManager(machine)
"""Contains the MatrixLight class."""
from operator import itemgetter
from mpf.core.device_monitor import DeviceMonitor
from mpf.core.machine import MachineController
from mpf.core.mode import Mode
from mpf.core.settings_controller import SettingEntry
from mpf.core.system_wide_device import SystemWideDevice
@DeviceMonitor(_brightness="brightness",
_corrected_brightness="corrected_brightness")
class MatrixLight(SystemWideDevice):
"""Represents a light connected to a traditional lamp matrix in a pinball machine.
This light could be an incandescent lamp or a replacement single-color
LED. The key is that they're connected up to a lamp matrix.
"""
config_section = 'matrix_lights'
collection = 'lights'
class_label = 'light'
machine = None
lights_to_update = set()
lights_to_fade = set()
_updater_task = None
"""Contains the BallHold device class."""
from collections import deque
from mpf.core.enable_disable_mixin import EnableDisableMixin
from mpf.core.device_monitor import DeviceMonitor
from mpf.core.events import event_handler
from mpf.core.mode_device import ModeDevice
from mpf.core.system_wide_device import SystemWideDevice
@DeviceMonitor("balls_held")
class BallHold(EnableDisableMixin, SystemWideDevice, ModeDevice):
"""Ball hold device which can be used to keep balls in ball devices and control their eject later on."""
config_section = 'ball_holds'
collection = 'ball_holds'
class_label = 'ball_hold'
__slots__ = ["hold_devices", "source_playfield", "balls_held", "_release_hold", "_released_balls",
"hold_queue"]
def __init__(self, machine, name):
"""Initialise ball hold."""
self.hold_devices = None
self.source_playfield = None
super().__init__(machine, name)
def __init__(self, priority, key, start_time, start_color, dest_time, dest_color):
"""Initialize light stack entry."""
self.priority = priority
self.key = key
self.start_time = start_time
self.start_color = start_color
self.dest_time = dest_time
self.dest_color = dest_color
def __gt__(self, other):
"""Compare two stack entries."""
return self.priority > other.priority or (self.priority == other.priority and self.key > other.key)
@DeviceMonitor(_color="color", _do_not_overwrite_setter=True)
class Light(SystemWideDevice, DevicePositionMixin):
"""A light in a pinball machine."""
config_section = 'lights'
collection = 'lights'
class_label = 'light'
__slots__ = ["hw_drivers", "platforms", "delay", "default_fade_ms", "_color_correction_profile", "stack",
"hw_driver_functions", "_off_color"]
def __init__(self, machine, name):
"""Initialise light."""
self.hw_drivers = {} # type: Dict[str, List[LightPlatformInterface]]
self.hw_driver_functions = []
self.platforms = set() # type: Set[LightsPlatform]
super().__init__(machine, name)
"""Shot profiles."""
from mpf.core.mode import Mode
from mpf.core.system_wide_device import SystemWideDevice
from mpf.core.mode_device import ModeDevice
class ShotProfile(ModeDevice, SystemWideDevice):
"""A shot profile."""
config_section = 'shot_profiles'
collection = 'shot_profiles'
class_label = 'shot_profile'
__slots__ = []
def device_removed_from_mode(self, mode: Mode) -> None:
"""Remove from mode."""
from mpf.core.delays import DelayManager
from mpf.core.events import event_handler
from mpf.core.machine import MachineController
from mpf.core.platform import DriverConfig
from mpf.core.system_wide_device import SystemWideDevice
from mpf.platforms.interfaces.driver_platform_interface import PulseSettings, HoldSettings
MYPY = False
if MYPY: # pragma: no cover
from mpf.core.platform import DriverPlatform, LightsPlatform # pylint: disable-msg=cyclic-import,unused-import
from mpf.platforms.interfaces.driver_platform_interface import DriverPlatformInterface # pylint: disable-msg=cyclic-import,unused-import; # noqa
from mpf.platforms.interfaces.light_platform_interface import LightPlatformInterface # pylint: disable-msg=cyclic-import,unused-import; # noqa
class DigitalOutput(SystemWideDevice):
"""A digital output on either a light or driver platform."""
config_section = 'digital_outputs'
collection = 'digital_outputs'
class_label = 'digital_output'
__slots__ = ["hw_driver", "platform", "type", "__dict__"]
def __init__(self, machine: MachineController, name: str) -> None:
"""Initialise digital output."""
self.hw_driver = None # type: Union[DriverPlatformInterface, LightPlatformInterface]
self.platform = None # type: Union[DriverPlatform, LightsPlatform]
self.type = None # type: str
super().__init__(machine, name)
self.delay = DelayManager(self.machine)
"""Implements a servo in MPF."""
from mpf.core.delays import DelayManager
from mpf.core.device_monitor import DeviceMonitor
from mpf.core.events import event_handler
from mpf.core.platform import ServoPlatform
from mpf.core.system_wide_device import SystemWideDevice
@DeviceMonitor(_position="position")
class Servo(SystemWideDevice):
"""Represents a servo in a pinball machine.
Args: Same as the Device parent class.
"""
config_section = 'servos'
collection = 'servos'
class_label = 'servo'
def __init__(self, machine, name):
"""Initialise servo."""
self.hw_servo = None
self.platform = None # type: ServoPlatform
self._position = None
self.speed_limit = None
self._load_enable_based_on_config_default()
elif self.enabled:
self._enable()
else:
self._load_enable_based_on_config_default()
def device_removed_from_mode(self, mode) -> None:
"""Forget enable state."""
del mode
self._disable()
self.player = None
self._enabled = None
@DeviceMonitor("enabled")
class EnableDisableMixinSystemWideDevice(SystemWideDevice, metaclass=abc.ABCMeta):
"""Implements enable and disable_events."""
__slots__ = ["enabled"]
def __init__(self, machine: MachineController, name: str) -> None:
"""Remember the enable state."""
self.enabled = False # type: bool
super().__init__(machine, name)
def _enable(self):
"""Enable the device.
Overwrite this method.
"""