def configure_switch(self, number: str, config: SwitchConfig, platform_config: dict) -> FASTSwitch: """Configure the switch object for a FAST Pinball controller. FAST Controllers support two types of switches: `local` and `network`. Local switches are switches that are connected to the FAST controller board itself, and network switches are those connected to a FAST I/O board. MPF needs to know which type of switch is this is. You can specify the switch's connection type in the config file via the ``connection:`` setting (either ``local`` or ``network``). If a connection type is not specified, this method will use some intelligence to try to figure out which default should be used. If the DriverBoard type is ``fast``, then it assumes the default is ``network``. If it's anything else (``wpc``, ``system11``, ``bally``, etc.) then it assumes the connection type is ``local``. Connection types can be mixed and matched in the same machine. Args: number: Number of this switch. config: Switch config. platform_config: Platform specific settings. Returns: Switch object. """ if not number: raise AssertionError("Switch needs a number") if not self.net_connection: raise AssertionError("A request was made to configure a FAST " "switch, but no connection to a NET processor" "is available") if self.machine_type == 'wpc': # translate switch num to FAST switch try: number = fast_defines.WPC_SWITCH_MAP[str(number).upper()] except KeyError: self.raise_config_error("Could not find WPC switch {}".format(number), 2) if 'connection' not in platform_config: platform_config['connection'] = 0 # local switch (default for WPC) else: platform_config['connection'] = 1 # network switch elif self.machine_type == 'fast': if 'connection' not in platform_config: platform_config['connection'] = 1 # network switch (default for FAST) else: platform_config['connection'] = 0 # local switch try: number = self._parse_switch_number(number) except ValueError: raise AssertionError("Could not parse switch number {}. Seems " "to be not a valid switch number for the" "FAST platform.".format(number)) # convert the switch number into a tuple which is: # (switch number, connection) number_tuple = (number, platform_config['connection']) self.debug_log("FAST Switch hardware tuple: %s", number) switch = FASTSwitch(config=config, number_tuple=number_tuple, platform=self, platform_settings=platform_config) return switch
def configure_switch(self, config: dict) -> FASTSwitch: """Configure the switch object for a FAST Pinball controller. FAST Controllers support two types of switches: `local` and `network`. Local switches are switches that are connected to the FAST controller board itself, and network switches are those connected to a FAST I/O board. MPF needs to know which type of switch is this is. You can specify the switch's connection type in the config file via the ``connection:`` setting (either ``local`` or ``network``). If a connection type is not specified, this method will use some intelligence to try to figure out which default should be used. If the DriverBoard type is ``fast``, then it assumes the default is ``network``. If it's anything else (``wpc``, ``system11``, ``bally``, etc.) then it assumes the connection type is ``local``. Connection types can be mixed and matched in the same machine. Args: config: Switch config. Returns: Switch object. """ # dont modify the config. make a copy config = deepcopy(config) if not config['number']: raise AssertionError("Switch needs a number") if not self.net_connection: raise AssertionError("A request was made to configure a FAST " "switch, but no connection to a NET processor" "is available") if self.machine_type == 'wpc': # translate switch num to FAST switch config['number'] = fast_defines.wpc_switch_map.get( str(config['number']).upper()) if 'connection' not in config: config['connection'] = 0 # local switch (default for WPC) else: config['connection'] = 1 # network switch elif self.machine_type == 'fast': if 'connection' not in config: config['connection'] = 1 # network switch (default for FAST) else: config['connection'] = 0 # local switch try: config['number'] = self._parse_switch_number(config['number']) except ValueError: raise AssertionError( "Could not parse switch number %s. Seems " "to be not a valid switch number for the" "FAST platform.", config['number']) # convert the switch number into a tuple which is: # (switch number, connection) config['number'] = (config['number'], config['connection']) self.debug_log("FAST Switch hardware tuple: %s", config['number']) switch = FASTSwitch(config=config, sender=self.net_connection.send, platform=self) return switch