Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mpf/config_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ fast_breakout:
led_ports: list|subconfig(fast_led_port)|None
fast_led_port:
port: single|str|
type: single|enum(ws2812,apa-102)|ws2812
leds: single|int|32
fast_aud:
port: list|str|auto
Expand Down Expand Up @@ -1543,6 +1542,7 @@ shots:
switches: list|machine(switches)|None
start_enabled: single|bool|None
delay_switch: dict|machine(switches):ms|None
delay_event_list: dict|event_handler:ms|None
persist_enable: single|bool|true
playfield: single|machine(playfields)|playfield
priority: single|int|0
Expand Down
32 changes: 20 additions & 12 deletions mpf/devices/shot.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ async def _initialize(self) -> None:

for switch in self.config['switches'] + list(self.config['delay_switch'].keys()):
# mark the playfield active no matter what
switch.add_handler(self._mark_active,
callback_kwargs={'playfield': switch.config['playfield']})
switch.add_handler(self._mark_active, callback_kwargs={'playfield': switch.config['playfield']})

def _mark_active(self, playfield, **kwargs):
"""Mark playfield active."""
Expand Down Expand Up @@ -85,17 +84,27 @@ def validate_and_parse_config(self, config: dict, is_mode_config: bool, debug_pr

def _register_switch_handlers(self):
self._handlers = []
priority = self.mode.priority + self.config['priority']
for switch in self.config['switches']:
self._handlers.append(self.machine.events.add_handler("{}_active".format(switch.name),
self.event_hit,
priority=self.mode.priority + self.config['priority'],
priority=priority,
blocking_facility="shot"))

for switch in list(self.config['delay_switch'].keys()):
for switch, ms in list(self.config['delay_switch'].items()):
self._handlers.append(self.machine.events.add_handler("{}_active".format(switch.name),
self._delay_switch_hit,
switch_name=switch.name,
priority=self.mode.priority + self.config['priority'],
name=switch.name,
ms=ms,
priority=priority,
blocking_facility="shot"))

for event, ms in list(self.config['delay_event_list'].items()):
self._handlers.append(self.machine.events.add_handler(event,
self._delay_switch_hit,
name=event,
ms=ms,
priority=priority,
blocking_facility="shot"))

def _remove_switch_handlers(self):
Expand Down Expand Up @@ -406,18 +415,17 @@ def _notify_monitors(self, profile, state):
callback(name=self.name, profile=profile, state=state)

@event_handler(4)
def _delay_switch_hit(self, switch_name, **kwargs):
def _delay_switch_hit(self, name, ms, **kwargs):
del kwargs
if not self.enabled:
return

self.delay.reset(name=switch_name + '_delay_timer',
ms=self.config['delay_switch']
[self.machine.switches[switch_name]],
self.delay.reset(name=name + '_delay_timer',
ms=ms,
callback=self._release_delay,
switch=switch_name)
switch=name)

self.active_delays.add(switch_name)
self.active_delays.add(name)

def _release_delay(self, switch):
self.active_delays.remove(switch)
Expand Down
Loading
Loading