예제 #1
0
    def track_eject(self, eject_tracker: EjectTracker, already_left):
        """Remove one ball from count."""
        ball_left = self._wait_for_ball_to_leave(
        ) if not already_left else None
        ball_activity = self.wait_for_ball_activity()
        # we are stable from here on
        eject_tracker.set_ready()
        count = self._entrance_count
        while True:
            if ball_left:
                futures = [ball_activity, ball_left]
            else:
                futures = [ball_activity]

            yield from Util.any(futures, loop=self.machine.clock.loop)

            if ball_left and ball_left.done():
                ball_left = False
                eject_tracker.track_ball_left()
                self.debug_log(
                    "Device ejected a ball. Reducing ball count by one.")
                self._entrance_count -= 1
                count -= 1
                if self._entrance_count < 0:
                    self._entrance_count = 0
                    self.ball_device.log.warning("Entrance count went below 0")

            if ball_activity.done() and self._entrance_count > count:
                for _ in range(self._entrance_count - count):
                    yield from eject_tracker.track_ball_entrance()

                count = self._entrance_count
                ball_activity = self.wait_for_ball_activity()
예제 #2
0
    def track_eject(self, eject_tracker: EjectTracker, already_left):
        """Return eject_process dict."""
        # count active switches
        while True:
            waiter = self.wait_for_ball_activity()
            try:
                active_switches = self._count_switches_sync()
                waiter.cancel()
                break
            except ValueError:
                yield from waiter

        ball_left_future = Util.ensure_future(
            self._wait_for_ball_to_leave(active_switches),
            loop=self.machine.clock.loop) if not already_left else None

        # all switches are stable. we are ready now
        eject_tracker.set_ready()

        jam_active_before_eject = self.is_jammed()
        jam_active_after_eject = False
        active_switches = active_switches
        count = len(active_switches)
        while True:
            ball_count_change = Util.ensure_future(
                self.wait_for_ball_count_changes(count),
                loop=self.machine.clock.loop)
            if ball_left_future:
                futures = [ball_count_change, ball_left_future]
            else:
                futures = [ball_count_change]
            yield from Util.any(futures, loop=self.machine.clock.loop)

            if ball_left_future and ball_left_future.done():
                ball_left_future = None
                eject_tracker.track_ball_left()
                count -= 1
                ball_count_change.cancel()
            elif ball_count_change.done():
                new_count = ball_count_change.result()
                # check jam first
                if not jam_active_after_eject and not jam_active_before_eject and self.is_jammed(
                ):
                    eject_tracker.track_ball_returned()
                    jam_active_after_eject = True
                    count += 1
                if new_count > count:
                    # TODO: add some magic to detect entrances
                    pass
                if new_count > count:
                    eject_tracker.track_unknown_balls(new_count - count)
                elif count > new_count:
                    eject_tracker.track_lost_balls(count - new_count)
                count = new_count