本文整理汇总了Python中mpf.system.utility_functions.Util类的典型用法代码示例。如果您正苦于以下问题:Python Util类的具体用法?Python Util怎么用?Python Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Util类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: configure_led
def configure_led(self, config):
if not self.rgb_connection:
self.log.critical("A request was made to configure a FAST LED, "
"but no connection to an LED processor is "
"available")
sys.exit()
if not self.flag_led_tick_registered:
self.machine.events.add_handler('timer_tick', self.update_leds)
self.flag_led_tick_registered = True
# if the LED number is in <channel> - <led> format, convert it to a
# FAST hardware number
if '-' in config['number_str']:
num = config['number_str'].split('-')
config['number'] = (int(num[0]) * 64) + int(num[1])
self.config['config_number_format'] = 'int'
else:
config['number'] = str(config['number'])
if self.config['config_number_format'] == 'int':
config['number'] = Util.int_to_hex_string(config['number'])
else:
config['number'] = Util.normalize_hex_string(config['number'])
this_fast_led = FASTDirectLED(config['number'])
self.fast_leds.add(this_fast_led)
return this_fast_led
开发者ID:qcapen,项目名称:mpf,代码行数:30,代码来源:fast2.py
示例2: validate_config_item2
def validate_config_item2(self, spec, validation_failure_info,
item='item not in [email protected]#',):
default = 'default [email protected]#'
item_type, validation, default = spec.split('|')
if default.lower() == 'none':
default = None
if item == 'item not in [email protected]#':
if default == 'default [email protected]#':
log.error('Required setting missing from config file. Run with '
'verbose logging and look for the last '
'ConfigProcessor entry above this line to see where '
'the problem is.')
sys.exit()
else:
item = default
if item_type == 'single':
item = self.validate_item(item, validation, validation_failure_info)
elif item_type == 'list':
item = Util.string_to_list(item)
new_list = list()
for i in item:
new_list.append(
self.validate_item(i, validation, validation_failure_info))
item = new_list
elif item_type == 'set':
item = set(Util.string_to_list(item))
new_set = set()
for i in item:
new_set.add(
self.validate_item(i, validation, validation_failure_info))
item = new_set
elif item_type == 'dict':
item = self.validate_item(item, validation,
validation_failure_info)
if not item:
item = dict()
else:
self.log.error("Invalid Type '%s' in config spec %s:%s", item_type,
validation_failure_info[0][0],
validation_failure_info[1])
sys.exit()
return item
开发者ID:qcapen,项目名称:mpf,代码行数:60,代码来源:config.py
示例3: receive_sa
def receive_sa(self, msg):
self.log.info("Received SA: %s", msg)
hw_states = dict()
num_local, local_states, num_nw, nw_states = msg.split(',')
for offset, byte in enumerate(bytearray.fromhex(nw_states)):
for i in range(8):
num = Util.int_to_hex_string((offset * 8) + i)
if byte & (2**i):
hw_states[(num, 1)] = 1
else:
hw_states[(num, 1)] = 0
for offset, byte in enumerate(bytearray.fromhex(local_states)):
for i in range(8):
num = Util.int_to_hex_string((offset * 8) + i)
if byte & (2**i):
hw_states[(num, 0)] = 1
else:
hw_states[(num, 0)] = 0
self.hw_switch_data = hw_states
开发者ID:qcapen,项目名称:mpf,代码行数:27,代码来源:fast2.py
示例4: configure_mode_settings
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
开发者ID:HarryXS,项目名称:mpf,代码行数:26,代码来源:mode.py
示例5: __init__
def __init__(self, slide, machine, dmd_object=None, x=None, y=None, h_pos=None, v_pos=None, layer=0, **kwargs):
super(VirtualDMD, self).__init__(slide, x, y, h_pos, v_pos, layer)
if not dmd_object:
self.dmd_object = machine.display.displays["dmd"]
else:
self.dmd_object = dmd_object
self.config = kwargs
self.name = "VirtualDMD"
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
elif "width" not in self.config and "height" not in self.config:
self.config["width"] = 512
self.config["height"] = 128
# Create a Pygame surface for the on screen DMD
self.element_surface = pygame.Surface(
(self.config["width"], self.config["height"]), depth=self.dmd_object.depth
)
if self.dmd_object.depth == 8:
self.element_surface.set_palette(self.palette)
self.layer = layer
self.set_position(x, y, h_pos, v_pos)
开发者ID:mini338,项目名称:mpf,代码行数:55,代码来源:virtualdmd.py
示例6: load_config_file
def load_config_file(filename, verify_version=True, halt_on_error=True):
config = FileManager.load(filename, verify_version, halt_on_error)
if 'config' in config:
path = os.path.split(filename)[0]
for file in Util.string_to_list(config['config']):
full_file = os.path.join(path, file)
config = Util.dict_merge(config,
Config.load_config_file(full_file))
return config
开发者ID:HarryXS,项目名称:mpf,代码行数:11,代码来源:config.py
示例7: _initialize_switches
def _initialize_switches(self):
self.update_switches_from_hw()
for switch in self.machine.switches:
# Populate self.switches
self.set_state(switch.name, switch.state, reset_time=True)
# Populate self.registered_switches
self.registered_switches[switch.name + '-0'] = list()
self.registered_switches[switch.name + '-1'] = list()
if self.machine.config['mpf']['auto_create_switch_events']:
switch.activation_events.add(
self.machine.config['mpf']['switch_event_active'].replace(
'%', switch.name))
switch.deactivation_events.add(
self.machine.config['mpf'][
'switch_event_inactive'].replace(
'%', switch.name))
if 'activation_events' in switch.config:
for event in Util.string_to_lowercase_list(
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)
开发者ID:HarryXS,项目名称:mpf,代码行数:52,代码来源:switch_controller.py
示例8: pulse
def pulse(self, milliseconds=None):
"""Pulses this driver. """
if not milliseconds:
hex_ms_string = self.driver_settings['pulse_ms']
else:
hex_ms_string = Util.int_to_hex_string(milliseconds)
if self.autofire:
cmd = (self.driver_settings['trigger_cmd'] +
self.driver_settings['number'] + ',' +
'01')
if milliseconds:
self.log.debug("Received command to pulse driver for %sms, but"
"this driver is configured with an autofire rule"
", so that pulse value will be used instead.")
else:
cmd = (self.driver_settings['config_cmd'] +
self.driver_settings['number'] +
',89,00,10,' +
hex_ms_string + ',' +
self.driver_settings['pwm1'] + ',00,00,' +
self.driver_settings['recycle_ms'])
self.log.debug("Sending Pulse Command: %s", cmd)
self.send(cmd)
self.check_auto()
开发者ID:qcapen,项目名称:mpf,代码行数:27,代码来源:fast2.py
示例9: __init__
def __init__(self, machine, config):
super(FadeCandyOPClient, self).__init__(machine, config)
self.log = logging.getLogger('FadeCandyClient')
self.update_every_tick = True
self.gamma = self.machine.config['led_settings']['gamma']
self.whitepoint = Util.string_to_list(
self.machine.config['led_settings']['whitepoint'])
self.whitepoint[0] = float(self.whitepoint[0])
self.whitepoint[1] = float(self.whitepoint[1])
self.whitepoint[2] = float(self.whitepoint[2])
self.linear_slope = (
self.machine.config['led_settings']['linear_slope'])
self.linear_cutoff = (
self.machine.config['led_settings']['linear_cutoff'])
self.keyframe_interpolation = (
self.machine.config['led_settings']['keyframe_interpolation'])
self.dithering = self.machine.config['led_settings']['dithering']
if not self.dithering:
self.disable_dithering()
if not self.keyframe_interpolation:
self.update_every_tick = False
self.set_global_color_correction()
self.write_firmware_options()
开发者ID:HarryXS,项目名称:mpf,代码行数:32,代码来源:fadecandy.py
示例10: load
def load(self, filename, verify_version=True):
"""Loads a YAML file from disk.
Args:
filename: The file to load.
verify_version: Boolean which specifies whether this method should
verify whether this file's config_version is compatible with
this version of MPF. Default is True.
Returns:
A dictionary of the settings from this YAML file.
"""
config = Util.keys_to_lower(self.byteify(json.load(open(filename, 'r'))))
# if verify_version:
# self.check_config_file_version(filename)
#
# try:
# self.log.debug("Loading configuration file: %s", filename)
# config = Util.keys_to_lower(json.loads(open(filename, 'r')))
# except yaml.YAMLError, exc:
# if hasattr(exc, 'problem_mark'):
# mark = exc.problem_mark
# self.log.critical("Error found in config file %s. Line %s, "
# "Position %s", filename, mark.line+1,
# mark.column+1)
# sys.exit()
# except:
# self.log.critical("Couldn't load from file: %s", filename)
# raise
return config
开发者ID:HarryXS,项目名称:mpf,代码行数:34,代码来源:json_interface.py
示例11: __init__
def __init__(self, machine, name, config, collection=None, validate=True):
self.shots = list() # list of strings
for shot in Util.string_to_list(config['shots']):
self.shots.append(machine.shots[shot])
# If this device is setup in a machine-wide config, make sure it has
# a default enable event.
# TODO add a mode parameter to the device constructor and do the logic
# there.
if not machine.modes:
if 'enable_events' not in config:
config['enable_events'] = 'ball_starting'
if 'disable_events' not in config:
config['disable_events'] = 'ball_ended'
if 'reset_events' not in config:
config['reset_events'] = 'ball_ended'
if 'profile' in config:
for shot in self.shots:
shot.update_enable_table(profile=config['profile'],
mode=None)
super(ShotGroup, self).__init__(machine, name, config, collection,
validate=validate)
self.rotation_enabled = True
if self.debug:
self._enable_related_device_debugging()
开发者ID:HarryXS,项目名称:mpf,代码行数:33,代码来源:shot_group.py
示例12: __init__
def __init__(self, machine, name, player, config):
self.machine = machine
self.name = name
self.player = player
self.handler_keys = set()
self.enabled = False
config_spec = '''
enable_events: list|None
disable_events: list|None
reset_events: list|None
restart_events: list|None
restart_on_complete: boolean|False
disable_on_complete: boolean|True
persist_state: boolean|False
'''
self.config = Config.process_config(config_spec=config_spec,
source=config)
if 'events_when_complete' not in config:
self.config['events_when_complete'] = ([
'logicblock_' + self.name + '_complete'])
else:
self.config['events_when_complete'] = Util.string_to_list(
config['events_when_complete'])
开发者ID:HarryXS,项目名称:mpf,代码行数:28,代码来源:logic_blocks.py
示例13: bcp_receive_get
def bcp_receive_get(self, names, **kwargs):
"""Processes an incoming BCP 'get' command by posting an event
'bcp_get_<name>'. It's up to an event handler to register for that
event and to send the response BCP 'set' command.
"""
for name in Util.string_to_list(names):
self.machine.events.post('bcp_get_{}'.format(name))
开发者ID:HarryXS,项目名称:mpf,代码行数:8,代码来源:bcp.py
示例14: configure_matrixlight
def configure_matrixlight(self, config):
if not self.net_connection:
self.log.critical("A request was made to configure a FAST matrix "
"light, but no connection to a NET processor is "
"available")
sys.exit()
if self.machine_type == 'wpc': # translate number to FAST light num
config['number'] = self.wpc_light_map.get(
config['number_str'].upper())
elif self.config['config_number_format'] == 'int':
config['number'] = Util.int_to_hex_string(config['number'])
else:
config['number'] = Util.normalize_hex_string(config['number'])
return (FASTMatrixLight(config['number'], self.net_connection.send),
config['number'])
开发者ID:qcapen,项目名称:mpf,代码行数:18,代码来源:fast2.py
示例15: getOptions
def getOptions(self):
return {
'force_platform': self.get_platform(),
'mpfconfigfile': "mpf/mpfconfig.yaml",
'machine_path': self.getMachinePath(),
'configfile': Util.string_to_list(self.getConfigFile()),
'debug': True,
'bcp': self.get_use_bcp()
}
开发者ID:HarryXS,项目名称:mpf,代码行数:9,代码来源:MpfTestCase.py
示例16: register_mpfmc_trigger_events
def register_mpfmc_trigger_events(self, config, **kwargs):
"""Scans an MPF config file and creates trigger events for the config
settings that need them.
Args:
config: An MPF config dictionary (can be the machine-wide or a mode-
specific one).
**kwargs: Not used. Included to catch any additional kwargs that may
be associted with this method being registered as an event
handler.
"""
self.log.debug("Registering Trigger Events")
try:
for event in config['show_player'].keys():
self.create_trigger_event(event)
except KeyError:
pass
try:
for event in config['slide_player'].keys():
self.create_trigger_event(event)
except KeyError:
pass
try:
for event in config['event_player'].keys():
self.create_trigger_event(event)
except KeyError:
pass
try:
for k, v in config['sound_player'].iteritems():
if 'start_events' in v:
for event in Util.string_to_list(v['start_events']):
self.create_trigger_event(event)
if 'stop_events' in v:
for event in Util.string_to_list(v['stop_events']):
self.create_trigger_event(event)
except KeyError:
pass
开发者ID:HarryXS,项目名称:mpf,代码行数:43,代码来源:bcp.py
示例17: _configure
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('(\(.*?\))')
开发者ID:HarryXS,项目名称:mpf,代码行数:11,代码来源:language.py
示例18: create_driver_settings
def create_driver_settings(self, machine, pulse_ms=None, **kwargs):
return_dict = dict()
if pulse_ms is None:
pulse_ms = machine.config['mpf']['default_pulse_ms']
return_dict['pulse_ms'] = Util.int_to_hex_string(pulse_ms)
return_dict['pwm1'] = 'ff'
return_dict['pwm2'] = 'ff'
return_dict['recycle_ms'] = '00'
return return_dict
开发者ID:qcapen,项目名称:mpf,代码行数:11,代码来源:fast2.py
示例19: configure_driver
def configure_driver(self, config, device_type='coil'):
if not self.net_connection:
self.log.critical("A request was made to configure a FAST driver, "
"but no connection to a NET processor is "
"available")
sys.exit()
# If we have WPC driver boards, look up the driver number
if self.machine_type == 'wpc':
config['number'] = self.wpc_driver_map.get(
config['number_str'].upper())
if ('connection' in config and
config['connection'].lower() == 'network'):
config['connection'] = 1
else:
config['connection'] = 0 # local driver (default for WPC)
# If we have FAST IO boards, we need to make sure we have hex strings
elif self.machine_type == 'fast':
if self.config['config_number_format'] == 'int':
config['number'] = Util.int_to_hex_string(config['number'])
else:
config['number'] = Util.normalize_hex_string(config['number'])
# Now figure out the connection type
if ('connection' in config and
config['connection'].lower() == 'local'):
config['connection'] = 0
else:
config['connection'] = 1 # network driver (default for FAST)
else:
self.log.critical("Invalid machine type: {0{}}".format(
self.machine_type))
sys.exit()
return (FASTDriver(config, self.net_connection.send, self.machine),
(config['number'], config['connection']))
开发者ID:qcapen,项目名称:mpf,代码行数:40,代码来源:fast2.py
示例20: _load_machine_config
def _load_machine_config(self):
for num, config_file in enumerate(self.options['configfile']):
if not (config_file.startswith('/') or
config_file.startswith('\\')):
config_file = os.path.join(self.machine_path,
self.config['mpf']['paths']['config'], config_file)
self.log.info("Machine config file #%s: %s", num+1, config_file)
self.config = Util.dict_merge(self.config,
Config.load_config_file(config_file))
开发者ID:HarryXS,项目名称:mpf,代码行数:13,代码来源:machine.py
注:本文中的mpf.system.utility_functions.Util类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论