Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cumulative drop_target reset delays for multi-coil banks #1621

Merged
Merged
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
18 changes: 11 additions & 7 deletions mpf/devices/drop_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def _initialize(self):

# can't read the switch until the switch controller is set up
self.machine.events.add_handler('init_phase_4',
self._update_state_from_switch, priority=2)
self._update_state_from_switch, priority=2, reconcile=True)
self.machine.events.add_handler('init_phase_4',
self._register_switch_handlers, priority=1)

Expand Down Expand Up @@ -405,20 +405,24 @@ def reset(self, attempt=None):
if self.reset_coil:
coils.add(self.reset_coil)

# now pulse the coils
self.debug_log('Pulsing reset coils: %s', coils)
restore_delay_ms = 0
for coil in coils:
wait_ms = coil.pulse(max_wait_ms=self.config['reset_coil_max_wait_ms'])
self.debug_log("Coil %s firing has a wait of %s!", coil, wait_ms)
restore_delay_ms += wait_ms

if self.config['ignore_switch_ms']:
restore_delay_ms += self.config['ignore_switch_ms']
if self.config['max_reset_attempts'] and attempt is None:
attempt = 1
self._ignore_switch_hits = True
self.delay.add(ms=self.config['ignore_switch_ms'],
self.delay.add(ms=restore_delay_ms,
callback=self._restore_switch_hits,
name='ignore_hits',
reset_attempt=attempt)

# now pulse the coils
self.debug_log('Pulsing reset coils: %s', coils)
for coil in coils:
coil.pulse(max_wait_ms=self.config['reset_coil_max_wait_ms'])

def _restore_switch_hits(self, reset_attempt=None):
self._ignore_switch_hits = False
self.member_target_change()
Expand Down
28 changes: 21 additions & 7 deletions mpf/tests/test_DropTargets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from mpf.tests.MpfFakeGameTestCase import MpfFakeGameTestCase
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch

from mpf.tests.MpfTestCase import MpfTestCase

Expand Down Expand Up @@ -43,7 +43,7 @@ def test_drop_target_bank(self):
self.assertIn('left3', self.machine.drop_targets)
self.assertIn('left_bank', self.machine.drop_target_banks)

self.machine.coils["coil1"].pulse = MagicMock()
self.machine.coils["coil1"].pulse = MagicMock(return_value=200)

self.assertFalse(self.machine.drop_targets["left1"].complete)
self.assertFalse(self.machine.drop_targets["left2"].complete)
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_drop_target_bank(self):
self.assertFalse(self.machine.drop_target_banks["left_bank"].complete)

# check that the bank does not reset if already down
self.machine.coils["coil1"].pulse = MagicMock()
self.machine.coils["coil1"].pulse = MagicMock(return_value=100)
self.machine.drop_target_banks['left_bank'].reset()
assert not self.machine.coils["coil1"].pulse.called

Expand Down Expand Up @@ -132,7 +132,7 @@ def test_drop_targets_in_mode(self):
self.machine.modes['mode1'].start()
self.advance_time_and_run()

self.machine.coils["coil2"].pulse = MagicMock()
self.machine.coils["coil2"].pulse = MagicMock(return_value=30)

self.assertFalse(self.machine.drop_targets["left4"].complete)
self.assertFalse(self.machine.drop_targets["left5"].complete)
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_drop_target_ignore_ms_ball_search(self):
# wait until ball search phase 1
event_future = self.machine.events.wait_for_event("ball_search_phase_1")
self.machine.clock.loop.run_until_complete(event_future)

self.advance_time_and_run(.25)

self.hit_switch_and_run('switch10', .1)
Expand All @@ -352,7 +352,7 @@ def test_drop_target_ignore_ms_ball_search(self):
# wait until ball search phase 2
event_future = self.machine.events.wait_for_event("ball_search_phase_2")
self.machine.clock.loop.run_until_complete(event_future)

self.advance_time_and_run(.25)

self.hit_switch_and_run('switch10', .1)
Expand All @@ -369,7 +369,7 @@ def test_drop_target_ignore_ms_ball_search(self):
# wait until ball search phase 3
event_future = self.machine.events.wait_for_event("ball_search_phase_3")
self.machine.clock.loop.run_until_complete(event_future)

self.advance_time_and_run(.25)

self.hit_switch_and_run('switch10', .1)
Expand Down Expand Up @@ -415,6 +415,20 @@ def test_drop_target_bank_ignore_ms(self):
# up should have been called by now
self.assertEventCalled('drop_target_bank_right_bank_up')

def test_drop_target_bank_restore_delay_ms(self):
# Set a specific ms that the pulse will wait before firing
self.machine.coils['coil5'].pulse = MagicMock(return_value=27)
with patch('mpf.core.delays.DelayManager.add') as add:
self.hit_switch_and_run('switch8', 1)
self.hit_switch_and_run('switch9', 1)

self.post_event('reset_right_bank', 1.5)
bank = self.machine.drop_target_banks['right_bank']
# Verify that the ignore_ms is the config value (1000) plus the wait
add.assert_called_with(ms=1027, name='ignore_hits',
callback=bank._restore_switch_hits,
reset_attempt=None)


class TestDropTargetsInGame(MpfFakeGameTestCase):

Expand Down