Skip to content

Commit

Permalink
Merge pull request #1785 from avanwinkle/dev
Browse files Browse the repository at this point in the history
Delay ball jam reordering to init phase 5
  • Loading branch information
avanwinkle committed Mar 24, 2024
2 parents a9b12f1 + db9fe2d commit 0985237
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mpf/_version.py
Expand Up @@ -10,7 +10,7 @@
"""

__version__ = '0.57.1.dev2' # Also consider whether MPF-MC pyproject.toml should be updated
__version__ = '0.57.1.dev3' # Also consider whether MPF-MC pyproject.toml should be updated
'''The full version of MPF.'''

__short_version__ = '0.57'
Expand Down
18 changes: 13 additions & 5 deletions mpf/devices/ball_device/ball_count_handler.py
Expand Up @@ -94,11 +94,8 @@ async def initialize(self):
self._ball_count = await self.counter.count_balls()
# on start try to reorder balls if count is unstable
if self.counter.is_count_unreliable() or self.counter.is_jammed():
self.info_log("BCH: Count is unstable. Trying to reorder balls.")
await self.ball_device.ejector.reorder_balls()
self.info_log("BCH: Repulse done. Waiting for balls to settle.")
# recount
self._ball_count = await self.counter.count_balls()
# Platform watchdogs don't open until init phase 3/4, so wait before reordering
self.machine.events.add_async_handler("init_phase_5", self._reorder_balls)

self.info_log("BCH: Initial count: %s", self._ball_count)

Expand All @@ -108,6 +105,17 @@ async def initialize(self):
await super().initialize()
self._count_valid.set()

async def _reorder_balls(self, **kwargs):
del kwargs
self.machine.events.remove_handler(self._reorder_balls)
self.info_log("BCH: Count is unstable. Trying to reorder balls.")
await self.ball_device.ejector.reorder_balls()
self.info_log("BCH: Repulse done. Waiting for balls to settle.")
# recount
self._ball_count = await self.counter.count_balls()

self.info_log("BCH: Reordered count: %s", self._ball_count)

@property
def has_ball(self) -> bool:
"""Return true if the device has at least one ball."""
Expand Down

0 comments on commit 0985237

Please sign in to comment.