How to use the mpf.system.utility_functions.Util function in mpf

To help you get started, we’ve selected a few mpf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github missionpinball / mpf / mpf / system / switch_controller.py View on Github external
switch.config['activation_events']):

                    if "|" in event:
                        ev_name, ev_time = event.split("|")
                        self.add_switch_handler(
                            switch_name=switch.name,
                            callback=self.machine.events.post,
                            state=1,
                            ms=Timing.string_to_ms(ev_time),
                            callback_kwargs={'event': ev_name}
                        )
                    else:
                        switch.activation_events.add(event)

            if 'deactivation_events' in switch.config:
                for event in Util.string_to_lowercase_list(
                        switch.config['deactivation_events']):

                    if "|" in event:
                        ev_name, ev_time = event.split("|")
                        self.add_switch_handler(
                            switch_name=switch.name,
                            callback=self.machine.events.post,
                            state=0,
                            ms=Timing.string_to_ms(ev_time),
                            callback_kwargs={'event': ev_name}
                        )
                    else:
                        switch.deactivation_events.add(event)
github missionpinball / mpf-mc / mc / core / assets.py View on Github external
self.member_cls = member_cls
        self.loading_members = set()
        self._callbacks = set()
        self.assets = list()
        self._last_asset = None
        self._asset_sequence = deque()
        self._assets_sent = set()
        self._total_weights = 0

        if 'load' not in config:
            config['load'] = 'on_demand'

        if 'type' not in config:
            config['type'] = 'sequence'

        for asset in Util.string_to_list(self.config[
                                             self.member_cls.config_section]):
            try:
                name, number = asset.split('|')
                if not number:
                    number = 1
                else:
                    number = int(number)
            except ValueError:
                name = asset
                number = 1

            try:
                self.assets.append((
                    getattr(self.mc, self.member_cls.attribute)[name],
                    number))
            except KeyError:
github missionpinball / mpf / fast2.py View on Github external
return_dict['pwm32']  = Util.pwm32_to_hex_string(pulse_power32)
        elif pulse_power is not None:
            return_dict['pwm1']  = Util.pwm8_to_hex_string(pulse_power)

        if hold_pwm_mask:
            hold_pwm_mask = str(hold_pwm_mask)
            if len(hold_pwm_mask) == 32:
                return_dict['pwm2'] = Util.bin_str_to_hex_str(hold_pwm_mask, 8)
            elif len(hold_pwm_mask) == 8:
                return_dict['pwm2'] = Util.bin_str_to_hex_str(hold_pwm_mask, 2)
            else:
                raise ValueError("hold_pwm_mask must either be 8 or 32 bits")
        elif hold_power32 is not None:
            return_dict['pwm32'] = Util.pwm32_to_hex_string(hold_power32)
        elif hold_power is not None:
            return_dict['pwm2'] = Util.pwm8_to_hex_string(hold_power)

        return return_dict
github missionpinball / mpf / mpf / _media_controller / core / mode.py View on Github external
def configure_mode_settings(self, config):
        """Processes this mode's configuration settings from a config
        dictionary.
        """

        if not ('priority' in config and type(config['priority']) is int):
            config['priority'] = 0

        if 'start_events' in config:
            config['start_events'] = Util.string_to_list(
                config['start_events'])
        else:
            config['start_events'] = list()

        if 'stop_events' in config:
            config['stop_events'] = Util.string_to_list(
                config['stop_events'])
        else:
            config['stop_events'] = list()

        # register mode start events
        if 'start_events' in config:
            for event in config['start_events']:
                self.machine.events.add_handler(event, self.start)

        self.config['mode'] = config
github missionpinball / mpf / mpf / _media_controller / elements / virtualdmd.py View on Github external
if self.dmd_object.depth == 8:

            if 'pixel_color' not in kwargs:
                self.config['pixel_color'] = 'ff5500'

            if 'dark_color' not in self.config:
                self.config['dark_color'] = '221100'

            if 'pixel_spacing' not in self.config:
                self.config['pixel_spacing'] = 2

            # convert hex colors to list of ints
            self.config['pixel_color'] = Util.hex_string_to_list(
                self.config['pixel_color'])
            self.config['dark_color'] = Util.hex_string_to_list(
                self.config['dark_color'])

            # This needs to match the source DMD or it could get weird
            self.config['shades'] = self.dmd_object.config['shades']

            self.palette = mpf.media_controller.display_modules.dmd.create_palette(
                bright_color=self.config['pixel_color'],
                dark_color=self.config['dark_color'],
                steps=self.config['shades'])

        if ('width' in self.config and
                'height' not in self.config):
            self.config['height'] = self.config['width'] / 4
        elif ('height' in self.config and
                'width' not in self.config):
            self.config['width'] = self.config['height'] * 4
github missionpinball / mpf / mpf / platform / opp.py View on Github external
mask = 1 << int(solenoid)
            
            msg = []
            msg.append(self.solCard.addr)
            msg.append(OppRs232Intf.KICK_SOL_CMD)
            msg.append(chr((mask >> 8) & 0xff))
            msg.append(chr(mask & 0xff))
            msg.append(chr((mask >> 8) & 0xff))
            msg.append(chr(mask & 0xff))
            msg.append(OppRs232Intf.calc_crc8_whole_msg(msg))
            cmd = ''.join(msg)
            self.log.debug("Pulse driver: %s", "".join(" 0x%02x" % ord(b) for b in cmd))
            self.solCard.platform.opp_connection.send(cmd)
        
        hex_ms_string = self.driver_settings['pulse_ms']
        return Util.hex_string_to_int(hex_ms_string)
github missionpinball / mpf / mpf / _media_controller / core / mode.py View on Github external
def configure_mode_settings(self, config):
        """Processes this mode's configuration settings from a config
        dictionary.
        """

        if not ('priority' in config and type(config['priority']) is int):
            config['priority'] = 0

        if 'start_events' in config:
            config['start_events'] = Util.string_to_list(
                config['start_events'])
        else:
            config['start_events'] = list()

        if 'stop_events' in config:
            config['stop_events'] = Util.string_to_list(
                config['stop_events'])
        else:
            config['stop_events'] = list()

        # register mode start events
        if 'start_events' in config:
            for event in config['start_events']:
                self.machine.events.add_handler(event, self.start)

        self.config['mode'] = config
github missionpinball / mpf / mpf / kmc / core / mode_controller.py View on Github external
if os.path.isfile(mpf_mode_config):
            config = Config.load_config_file(mpf_mode_config)

        # Now figure out if there's a machine-specific config for this mode, and
        # if so, merge it into the config

        mode_config_folder = os.path.join(self.mc.machine_path,
            self.mc.machine_config['kmc']['paths']['modes'], mode_string, 'config')

        found_file = False
        for path, _, files in os.walk(mode_config_folder):
            for file in files:
                file_root, file_ext = os.path.splitext(file)

                if file_root == mode_string:
                    config = Util.dict_merge(config,
                        Config.load_config_file(os.path.join(path, file)))
                    found_file = True
                    break

            if found_file:
                break

        return Mode(self.mc, config, mode_string, mode_path)
github missionpinball / mpf / mpf / _media_controller / core / sound.py View on Github external
if 'sound' not in config:
            return False
        elif type(config['sound']) is str:
            config['sound'] = self.machine.sounds[config['sound']]
        # this is kind of weird because once the sound has been registered, the
        # sound will still be converted from the string to the object. This is
        # an unintended side effect of passing around a dict, but I guess it's
        # ok? We just have to check to make sure we have a string before we
        # try to convert it to an object. If not, the conversion has already
        # been done.

        if 'start_events' not in config:
            config['start_events'] = list()
        else:
            config['start_events'] = Util.string_to_list(
                config['start_events'])

        if 'stop_events' not in config:
            config['stop_events'] = list()
        else:
            config['stop_events'] = Util.string_to_list(
                config['stop_events'])

        if 'duration' not in config or config['duration'] is None:
            config['duration'] = None

        if 'loops' not in config or config['loops'] is None:
            config['loops'] = 0

        if 'priority' not in config or config['priority'] is None:
            config['priority'] = 0
github missionpinball / mpf / mpf / _media_controller / core / language.py View on Github external
def _configure(self):
        self.config = self.machine.config['languages']
        self.machine.language = self
        self.languages = Util.string_to_lowercase_list(
            self.machine.config['languages'])

        # Set the default language to the first entry in the list
        self.set_language(self.languages[0])
        self.default_language = self.languages[0]

        self.find_text = re.compile('(\(.*?\))')