Skip to content

Commit 2a550c8

Browse files
committed
Multiball lock ball handler fixes for multiple-eject devices
1 parent 9256f34 commit 2a550c8

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

mpf/devices/ball_device/outgoing_balls_handler.py

+19
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,25 @@ async def _eject_ball(self, eject_request: OutgoingBall, eject_try: int) -> bool
424424
result = await self._handle_confirm(eject_request, ball_eject_process, incoming_ball_at_target,
425425
eject_try)
426426
await self.ball_device.ball_count_handler.end_eject(ball_eject_process, result)
427+
428+
self.info_log("Eject successful, looking for missing balls")
429+
new_balls = await self.ball_device.ball_count_handler.counter.count_balls()
430+
old_balls = self.ball_device.counted_balls
431+
self.info_log("Found %s physical balls and %s expected balls", new_balls, old_balls)
432+
if new_balls < old_balls:
433+
# Post that the ball is lost
434+
await self.ball_device.lost_idle_ball()
435+
# Cancel the eject queue for the lost ball
436+
self.info_log("How many ejects are requested? %s", self.ball_device.requested_balls)
437+
self.info_log("Playfield ejects requested? %s", self.machine.playfields.playfield.num_balls_requested)
438+
for _ in range(0, old_balls - new_balls):
439+
self.info_log("Cancelling one queued request")
440+
self._eject_queue.get_nowait()
441+
self._eject_queue.task_done()
442+
self.info_log("Necessary queue requests are completed. Updating ball count to %s." % new_balls)
443+
self.ball_device.ball_count_handler._set_ball_count(new_balls)
444+
445+
427446
return result
428447
except asyncio.CancelledError:
429448
ball_eject_process.cancel()

mpf/devices/multiball_lock.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ def _lock_ball(self, unclaimed_balls: int, new_available_balls: int, device: "Ba
319319
'''
320320

321321
# schedule eject of new balls for all physically locked balls
322-
if self.config['balls_to_replace'] == -1 or self.locked_balls <= self.config['balls_to_replace']:
323-
self.debug_log("{} locked balls and {} to replace, requesting {} new balls"
324-
.format(self.locked_balls, self.config['balls_to_replace'], balls_to_lock_physically))
322+
if self.config['balls_to_replace'] == -1 or new_locked_balls <= self.config['balls_to_replace']:
323+
self.info_log("{} locked balls and {} to replace, requesting {} new balls"
324+
.format(new_locked_balls, self.config['balls_to_replace'], balls_to_lock_physically))
325325
self._request_new_balls(balls_to_lock_physically)
326326
else:
327-
self.debug_log("{} locked balls exceeds {} to replace, not requesting any balls"
328-
.format(self.locked_balls, self.config['balls_to_replace']))
327+
self.info_log("{} locked balls exceeds {} to replace, not requesting any balls"
328+
.format(new_locked_balls, self.config['balls_to_replace']))
329329

330-
self.debug_log("Locked %s balls virtually and %s balls physically", balls_to_lock, balls_to_lock_physically)
330+
self.info_log("Locked %s balls virtually and %s balls physically", balls_to_lock, balls_to_lock_physically)
331331

332332
return {'unclaimed_balls': unclaimed_balls - balls_to_lock_physically}
333333

0 commit comments

Comments
 (0)