Пример #1
0
    def __init__(self, mpf_path: str, machine_path: str, options: dict) -> None:
        """Initialize machine controller."""
        super().__init__()
        self.log = logging.getLogger("Machine")     # type: Logger
        self.log.info("Mission Pinball Framework Core Engine v%s", __version__)

        self.log.info("Command line arguments: %s", options)
        self.options = options
        self.config_processor = ConfigProcessor()

        self.log.info("MPF path: %s", mpf_path)
        self.mpf_path = mpf_path

        self.log.info("Machine path: %s", machine_path)
        self.machine_path = machine_path

        self.verify_system_info()
        self._exception = None      # type: Any
        self._boot_holds = set()    # type: Set[str]
        self.is_init_done = None    # type: asyncio.Event

        self._done = False
        self.monitors = dict()      # type: Dict[str, Set[Callable]]
        self.plugins = list()       # type: List[Any]
        self.scriptlets = list()    # type: List[Scriptlet]
        self.modes = DeviceCollection(self, 'modes', None)          # type: Dict[str, Mode]
        self.game = None            # type: Game
        self.machine_vars = dict()
        self.machine_var_monitor = False
        self.machine_var_data_manager = None    # type: DataManager
        self.thread_stopper = threading.Event()

        self.config = None      # type: Any

        # add some type hints
        MYPY = False    # noqa
        if MYPY:   # pragma: no cover
            # controllers
            self.events = None                          # type: EventManager
            self.switch_controller = None               # type: SwitchController
            self.mode_controller = None                 # type: ModeController
            self.settings = None                        # type: SettingsController
            self.bcp = None                             # type: Bcp
            self.asset_manager = None                   # type: BaseAssetManager
            self.ball_controller = None                 # type: BallController
            self.show_controller = None                 # type: ShowController
            self.placeholder_manager = None             # type: PlaceholderManager
            self.device_manager = None                  # type: DeviceManager
            self.auditor = None                         # type: Auditor
            self.tui = None                             # type: TextUi
            self.service = None                         # type: ServiceController

            # devices
            self.autofires = None                       # type: DeviceCollectionType[str, AutofireCoil]
            self.motors = None                          # type: DeviceCollectionType[str, Motor]
            self.digital_outputs = None                 # type: DeviceCollectionType[str, DigitalOutput]
            self.shows = None                           # type: DeviceCollectionType[str, Show]
            self.shots = None                           # type: DeviceCollectionType[str, Shot]
            self.shot_groups = None                     # type: DeviceCollectionType[str, ShotGroup]
            self.switches = None                        # type: DeviceCollectionType[str, Switch]
            self.coils = None                           # type: DeviceCollectionType[str, Driver]
            self.lights = None                          # type: DeviceCollectionType[str, Light]
            self.ball_devices = None                    # type: DeviceCollectionType[str, BallDevice]
            self.accelerometers = None                  # type: DeviceCollectionType[str, Accelerometer]
            self.playfield = None                       # type: Playfield
            self.playfields = None                      # type: DeviceCollectionType[str, Playfield]
            self.counters = None                        # type: DeviceCollectionType[str, Counter]
            self.sequences = None                       # type: DeviceCollectionType[str, Sequence]
            self.accruals = None                        # type: DeviceCollectionType[str, Accrual]
            self.drop_targets = None                    # type: DeviceCollectionType[str, DropTarget]
            self.servos = None                          # type: DeviceCollectionType[str, Servo]
            self.segment_displays = None                # type: DeviceCollectionType[str, SegmentDisplay]

        self._set_machine_path()

        self.config_validator = ConfigValidator(self)

        self._load_config()
        self.machine_config = self.config       # type: Any
        self.configure_logging(
            'Machine',
            self.config['logging']['console']['machine_controller'],
            self.config['logging']['file']['machine_controller'])

        self.delayRegistry = DelayManagerRegistry(self)
        self.delay = DelayManager(self.delayRegistry)

        self.hardware_platforms = dict()    # type: Dict[str, SmartVirtualHardwarePlatform]
        self.default_platform = None        # type: SmartVirtualHardwarePlatform

        self.clock = self._load_clock()
        self.stop_future = asyncio.Future(loop=self.clock.loop)     # type: asyncio.Future
Пример #2
0
    def __init__(self, options, config: MpfMcConfig, thread_stopper=None):

        self.log = logging.getLogger('mpfmc')
        self.log.info("Mission Pinball Framework Media Controller v%s",
                      __version__)
        self.log.info("Mission Pinball Framework Game Engine v%s",
                      __mpfversion__)

        if (__version__.split('.')[0] != __mpfversion__.split('.')[0]
                or __version__.split('.')[1] != __mpfversion__.split('.')[1]):

            self.log.error(
                "MPF MC and MPF Game engines must be same "
                "major.minor versions. You have MPF v%s and MPF-MC"
                " v%s", __mpfversion__, __version__)

            raise ValueError(
                "MPF MC and MPF Game engines must be same "
                "major.minor versions. You have MPF v{} and MPF-MC"
                " v{}".format(__mpfversion__, __version__))

        super().__init__()

        self.options = options
        self.machine_path = config.get_machine_path()
        self.log.info("Machine path: %s", self.machine_path)

        # load machine into path to load modules
        if self.machine_path not in sys.path:
            sys.path.append(self.machine_path)
        self.mc_config = config
        self.config_validator = ConfigValidator(self, config.get_config_spec())
        self.machine_config = self.mc_config.get_machine_config()
        self.config = self.machine_config

        self.clock = Clock
        # pylint: disable-msg=protected-access
        self.log.info("Starting clock at %sHz", Clock._max_fps)
        self._boot_holds = set()
        self.is_init_done = threading.Event()
        self.mpf_path = os.path.dirname(mpf.__file__)
        self.modes = CaseInsensitiveDict()
        self.player_list = list()
        self.player = None
        self.num_players = 0
        self.bcp_client_connected = False
        self.placeholder_manager = McPlaceholderManager(self)
        self.settings = McSettingsController(self)

        self.animation_configs = dict()
        self.active_slides = dict()
        self.custom_code = list()

        self.register_boot_hold('init')
        self.displays = DeviceCollection(self, "displays", "displays")
        self.machine_vars = CaseInsensitiveDict()
        self.machine_var_monitor = False
        self.monitors = dict()
        self.targets = dict()
        """Dict which contains all the active slide frames in the machine that
        a slide can target. Will always contain an entry called 'default'
        which will be used if a slide doesn't specify targeting.
        """

        self.keyboard = None
        self.dmds = []
        self.rgb_dmds = []
        self.crash_queue = queue.Queue()
        self.ticks = 0
        self.start_time = 0
        self.debug_refs = []

        MYPY = False  # NOQA
        if MYPY:  # pragma: no cover
            self.videos = None  # type: Dict[str, VideoAsset]

        if thread_stopper:
            self.thread_stopper = thread_stopper
        else:
            self.thread_stopper = threading.Event()

        # Core components
        self.events = EventManager(self)
        self.mode_controller = ModeController(self)
        create_config_collections(
            self, self.machine_config['mpf-mc']['config_collections'])
        self._preprocess_config(self.config)

        self.config_processor = ConfigProcessor(self)
        self.transition_manager = TransitionManager(self)
        self.effects_manager = EffectsManager(self)

        self._set_machine_path()

        self._load_font_paths()

        # Initialize the sound system (must be done prior to creating the AssetManager).
        # If the sound system is not available, do not load any other sound-related modules.
        if SoundSystem is None or self.options.get("no_sound"):
            self.sound_system = None
        else:
            self.sound_system = SoundSystem(self)
            if self.sound_system.audio_interface is None:
                self.sound_system = None

        self.asset_manager = ThreadedAssetManager(self)
        self.bcp_processor = BcpProcessor(self)

        # Asset classes
        ImageAsset.initialize(self)
        VideoAsset.initialize(self)
        BitmapFontAsset.initialize(self)

        self._initialise_sound_system()

        self.clock.schedule_interval(self._check_crash_queue, 1)

        self.events.add_handler("client_connected", self._create_dmds)
        self.events.add_handler("player_turn_start", self.player_start_turn)

        self.create_machine_var('mpfmc_ver', __version__)
        # force setting it here so we have it before MPF connects
        self.receive_machine_var_update('mpfmc_ver', __version__, 0, True)
Пример #3
0
    def __init__(self, options: dict, config: MpfConfig) -> None:
        """Initialize machine controller."""
        super().__init__()
        self.log = logging.getLogger("Machine")  # type: Logger
        self.log.info("Mission Pinball Framework Core Engine v%s", __version__)
        self._crash_handlers = []  # type: List[Callable]
        self.is_shutting_down = False

        self.log.info("Command line arguments: %s", options)
        self.options = options

        self.mpf_path = config.get_mpf_path()
        self.log.info("MPF path: %s", self.mpf_path)

        self.machine_path = config.get_machine_path()
        self.log.info("Machine path: %s", self.machine_path)

        self.verify_system_info()
        self._exception = None  # type: Any
        self._boot_holds = set()  # type: Set[str]
        self.is_init_done = None  # type: Optional[asyncio.Event]

        self._done = False
        self.monitors = dict()  # type: Dict[str, Set[Callable]]
        self.plugins = list()  # type: List[Any]
        self.custom_code = list()  # type: List[CustomCode]
        self.modes = DeviceCollection(self, 'modes',
                                      None)  # type: Dict[str, Mode]
        self.game = None  # type: Optional[Game]
        self.thread_stopper = threading.Event()

        self.config = config.get_machine_config()  # type: Any
        self.mpf_config = config  # type: MpfConfig
        self.config_validator = ConfigValidator(
            self, self.mpf_config.get_config_spec())

        self.variables = MachineVariables(self)  # type: MachineVariables

        # add some type hints
        if MYPY:  # pragma: no cover
            # controllers
            self.events = self.events  # type: EventManager
            self.switch_controller = self.switch_controller  # type: SwitchController
            self.mode_controller = self.mode_controller  # type: ModeController
            self.settings = self.settings  # type: SettingsController
            self.bcp = self.bcp  # type: Bcp
            self.ball_controller = self.ball_controller  # type: BallController
            self.show_controller = self.show_controller  # type: ShowController
            self.placeholder_manager = self.placeholder_manager  # type: PlaceholderManager
            self.device_manager = self.device_manager  # type: DeviceManager
            self.auditor = self.auditor  # type: Auditor
            self.tui = self.tui  # type: TextUi
            self.service = self.service  # type: ServiceController
            self.show_player = self.show_player  # type: ShowPlayer
            self.light_controller = self.light_controller  # type: LightController
            self.platform_controller = self.platform_controller  # type: PlatformController

            # devices
            self.autofires = {}  # type: Dict[str, AutofireCoil]
            self.motors = {}  # type: Dict[str, Motor]
            self.digital_outputs = {}  # type: Dict[str, DigitalOutput]
            self.shows = {}  # type: Dict[str, Show]
            self.shots = {}  # type: Dict[str, Shot]
            self.shot_groups = {}  # type: Dict[str, ShotGroup]
            self.switches = {}  # type: Dict[str, Switch]
            self.steppers = {}  # type: Dict[str, Stepper]
            self.coils = {}  # type: Dict[str, Driver]
            self.lights = {}  # type: Dict[str, Light]
            self.ball_devices = {}  # type: Dict[str, BallDevice]
            self.accelerometers = {}  # type: Dict[str, Accelerometer]
            self.playfield = None  # type: Optional[Playfield]
            self.playfields = {}  # type: Dict[str, Playfield]
            self.counters = {}  # type: Dict[str, Counter]
            self.sequences = {}  # type: Dict[str, Sequence]
            self.accruals = {}  # type: Dict[str, Accrual]
            self.drop_targets = {}  # type: Dict[str, DropTarget]
            self.drop_target_banks = {}  # type: Dict[str, DropTargetBank]
            self.servos = {}  # type: Dict[str, Servo]
            self.segment_displays = {}  # type: Dict[str, SegmentDisplay]
            self.dmds = {}  # type: Dict[str, Dmd]
            self.rgb_dmds = {}  # type: Dict[str, RgbDmd]
            self.flippers = {}  # type: Dict[str, Flipper]
            self.diverters = {}  # type: Dict[str, Diverter]
            self.multiball_locks = {}  # type: Dict[str, MultiballLock]
            self.multiballs = {}  # type: Dict[str, Multiball]
            self.ball_holds = {}  # type: Dict[str, BallHold]
            self.ball_saves = {}  # type: Dict[str, BallSave]
            self.magnets = {}  # type: Dict[str, Magnet]
            self.state_machines = {}  # type: Dict[str, StateMachine]
            self.extra_balls = {}  # type: Dict[str, ExtraBall]
            self.extra_ball_groups = {}  # type: Dict[str, ExtraBallGroup]
            self.achievements = {}  # type: Dict[str, Achievement]
            self.achievement_groups = {}  # type: Dict[str, AchievementGroup]
            self.combo_switches = {}  # type: Dict[str, ComboSwitch]
            self.score_queues = {}  # type: Dict[str, ScoreQueue]

        self._set_machine_path()

        self.configure_logging(
            'Machine', self.config['logging']['console']['machine_controller'],
            self.config['logging']['file']['machine_controller'])

        self.delay = DelayManager(self)

        self.hardware_platforms = dict(
        )  # type: Dict[str, SmartVirtualHardwarePlatform]
        self.default_platform = None  # type: Optional[SmartVirtualHardwarePlatform]

        self.clock = self._load_clock()
        self.stop_future = asyncio.Future()  # type: asyncio.Future
Пример #4
0
    def __init__(self, mpf_path: str, machine_path: str, options: dict):
        """Initialise machine controller."""
        self.log = logging.getLogger("Machine")
        self.log.info("Mission Pinball Framework Core Engine v%s", __version__)

        self.log.debug("Command line arguments: %s", options)
        self.options = options

        self.log.debug("MPF path: %s", mpf_path)
        self.mpf_path = mpf_path

        self.log.info("Machine path: %s", machine_path)
        self.machine_path = machine_path

        self.log.debug("Command line arguments: %s", self.options)
        self.verify_system_info()
        self._exception = None

        self._boot_holds = set()
        self.is_init_done = False
        self.register_boot_hold('init')

        self._done = False
        self.monitors = dict()
        self.plugins = list()
        self.scriptlets = list()
        self.modes = DeviceCollection(self, 'modes', None)
        self.game = None
        self.active_debugger = dict()
        self.machine_vars = CaseInsensitiveDict()
        self.machine_var_monitor = False
        self.machine_var_data_manager = None
        self.thread_stopper = threading.Event()

        self.delayRegistry = DelayManagerRegistry(self)
        self.delay = DelayManager(self.delayRegistry)

        self.crash_queue = queue.Queue()

        self.config = None
        self.events = None
        self.machine_config = None
        self._set_machine_path()

        self.config_validator = ConfigValidator(self)

        self._load_config()

        self.clock = self._load_clock()
        self._crash_queue_checker = self.clock.schedule_interval(
            self._check_crash_queue, 1)

        self.hardware_platforms = dict()
        self.default_platform = None

        self._load_hardware_platforms()

        self._initialize_credit_string()

        self._load_core_modules()
        # order is specified in mpfconfig.yaml

        # This is called so hw platforms have a chance to register for events,
        # and/or anything else they need to do with core modules since
        # they're not set up yet when the hw platforms are constructed.
        self._initialize_platforms()

        self._validate_config()

        self._register_config_players()
        self._register_system_events()
        self._load_machine_vars()
        self._run_init_phases()

        ConfigValidator.unload_config_spec()

        self.clear_boot_hold('init')