Exemplo n.º 1
0
    def _setup_fade(self):
        self.fade_in_progress = True

        if not self.fade_task:
            if self.debug_logging:
                print "setting up fade task"
            self.fade_task = Task.Create(self._fade_task)
        elif self.debug_logging:
                print "already have a fade task"
Exemplo n.º 2
0
    def start(self):
        """Begin the ball search process"""
        self.log.debug("Starting the ball search")

        self.active = True
        self.task = Task.Create(self.tick)
Exemplo n.º 3
0
    def __init__(self, options):
        self.options = options
        self.log = logging.getLogger("Machine")
        self.log.info("Mission Pinball Framework v%s", version.__version__)
        self.log_system_info()

        self.loop_start_time = 0
        self.num_loops = 0
        self.physical_hw = options['physical_hw']
        self.done = False
        self.machineflow_index = None
        self.machine_path = None  # Path to this machine's folder root
        self.monitors = dict()
        self.plugins = list()
        self.scriptlets = list()
        self.game_modes = list()
        self.asset_managers = dict()

        self.num_assets_to_load = 0

        self.crash_queue = Queue.Queue()
        Task.Create(self._check_crash_queue)

        self.config = dict()
        self._load_config()

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

        if self.physical_hw:
            for section, platform in self.config['hardware'].iteritems():
                if platform.lower() != 'default' and section != 'driverboards':
                    self.add_platform(platform)
        else:
            self.add_platform('virtual')

        if self.physical_hw:
            self.set_default_platform(self.config['hardware']['platform'])
        else:
            self.set_default_platform('virtual')

        self._load_system_modules()

        self.events.add_handler('action_shutdown', self.power_off)
        self.events.add_handler('sw_shutdown', self.power_off)
        self.events.add_handler('action_quit', self.quit)
        self.events.add_handler('sw_quit', self.quit)
        self.events.add_handler('machine_reset_phase_3',
                                self.flow_advance,
                                position=0)

        self.events.post("init_phase_1")
        self._load_device_modules()
        self.events.post("init_phase_2")
        self._load_plugins()
        self.events.post("init_phase_3")
        self._load_scriptlets()
        self.events.post("init_phase_4")
        self._init_machine_flow()
        self.events.post("init_phase_5")

        self.reset()
Exemplo n.º 4
0
    def __init__(self, options):
        self.options = options

        self.log = logging.getLogger("MediaController")
        self.log.info("Media Controller Version %s", version.__version__)
        self.log.info("Backbox Control Protocol Version %s",
                      version.__bcp_version__)
        self.log.info("Config File Version %s",
                      version.__config_version__)

        python_version = sys.version_info
        self.log.info("Python version: %s.%s.%s", python_version[0],
                      python_version[1], python_version[2])
        self.log.info("Platform: %s", sys.platform)
        self.log.info("Python executable location: %s", sys.executable)
        self.log.info("32-bit Python? %s", sys.maxsize < 2**32)

        self.config = dict()
        self.done = False  # todo
        self.machine_path = None
        self.asset_managers = dict()
        self.num_assets_to_load = 0
        self.window = None
        self.window_manager = None
        self.pygame = False
        self.pygame_requested = False
        self.registered_pygame_handlers = dict()
        self.pygame_allowed_events = list()
        self.socket_thread = None
        self.receive_queue = Queue.Queue()
        self.sending_queue = Queue.Queue()
        self.crash_queue = Queue.Queue()
        self.game_modes = CaseInsensitiveDict()
        self.player_list = list()
        self.player = None
        self.HZ = 0
        self.next_tick_time = 0
        self.secs_per_tick = 0

        Task.Create(self._check_crash_queue)

        self.bcp_commands = {'hello': self.bcp_hello,
                             'goodbye': self.bcp_goodbye,
                             'reset': self.reset,
                             'mode_start': self.bcp_mode_start,
                             'mode_stop': self.bcp_mode_stop,
                             'error': self.bcp_error,
                             'ball_start': self.bcp_ball_start,
                             'ball_end': self.bcp_ball_end,
                             'game_start': self.bcp_game_start,
                             'game_end': self.bcp_game_end,
                             'player_added': self.bcp_player_add,
                             'player_variable': self.bcp_player_variable,
                             'player_score': self.bcp_player_score,
                             'player_turn_start': self.bcp_player_turn_start,
                             'attract_start': self.bcp_attract_start,
                             'attract_stop': self.bcp_attract_stop,
                             'trigger': self.bcp_trigger,
                             'switch': self.bcp_switch,
                             'get': self.bcp_get,
                             'set': self.bcp_set,
                             'config': self.bcp_config,
                             'timer': self.bcp_timer
                            }

        # load the MPF config & machine defaults
        self.config = (
            Config.load_config_yaml(config=self.config,
                                    yaml_file=self.options['mcconfigfile']))

        # Find the machine_files location. If it starts with a forward or
        # backward slash, then we assume it's from the mpf root. Otherwise we
        # assume it's from the subfolder location specified in the
        # mpfconfigfile location

        if (options['machinepath'].startswith('/') or
                options['machinepath'].startswith('\\')):
            machine_path = options['machinepath']
        else:
            machine_path = os.path.join(self.config['mediacontroller']['paths']
                                        ['machine_files'],
                                        options['machinepath'])

        self.machine_path = os.path.abspath(machine_path)

        # Add the machine folder to our path so we can import modules from it
        sys.path.append(self.machine_path)

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

        # Now find the config file location. Same as machine_file with the
        # slash uses to specify an absolute path

        if (options['configfile'].startswith('/') or
                options['configfile'].startswith('\\')):
            config_file = options['configfile']
        else:

            if not options['configfile'].endswith('.yaml'):
                options['configfile'] += '.yaml'

            config_file = os.path.join(self.machine_path,
                                       self.config['mediacontroller']['paths']
                                       ['config'],
                                       options['configfile'])

        self.log.info("Base machine config file: %s", config_file)

        # Load the machine-specific config
        self.config = Config.load_config_yaml(config=self.config,
                                              yaml_file=config_file)

        mediacontroller_config_spec = '''
                        exit_on_disconnect: boolean|True
                        port: int|5050
                        '''

        self.config['mediacontroller'] = (
            Config.process_config(mediacontroller_config_spec,
                                  self.config['mediacontroller']))

        self.events = EventManager(self)
        self.timing = Timing(self)

        # Load the media controller modules
        self.config['mediacontroller']['modules'] = (
            self.config['mediacontroller']['modules'].split(' '))
        for module in self.config['mediacontroller']['modules']:
            self.log.info("Loading module: %s", module)
            module_parts = module.split('.')
            exec('self.' + module_parts[0] + '=' + module + '(self)')

            # todo there's probably a more pythonic way to do this, and I know
            # exec() is supposedly unsafe, but meh, if you have access to put
            # malicious files in the system folder then you have access to this
            # code too.

        self.start_socket_thread()

        self.events.post("init_phase_1")
        self.events.post("init_phase_2")
        self.events.post("init_phase_3")
        self.events.post("init_phase_4")
        self.events.post("init_phase_5")

        self.reset()
Exemplo n.º 5
0
 def start(self):
     """Starts this machine mode. """
     self.log.debug("Mode started")
     self.active = True
     self.task = Task.Create(self.tick, sleep=0)
     self.machine.events.post('machineflow_' + self.name + '_start')
Exemplo n.º 6
0
    def _setup_fade(self):
        self.fade_in_progress = True

        if not self.fade_task:
            self.fade_task = Task.Create(self._fade_task)
Exemplo n.º 7
0
 def start(self):
     """Starts this machine mode. """
     self.log.debug("Mode started")
     self.active = True
     self.task = Task.Create(self.tick, sleep=0)