Exemple #1
0
    def _entrance_switch_handler(self):
        """Add a ball to the device since the entrance switch has been hit."""
        # If recycle is ongoing, do nothing
        if self.recycle_clear_time:
            self.debug_log("Entrance switch hit within ignore window, taking no action")
            return
        # If a recycle time is configured, set a timeout to prevent future entrance activity
        if self.recycle_secs:
            self.recycle_clear_time = self.machine.clock.get_time() + self.recycle_secs
            self.machine.clock.loop.call_at(self.recycle_clear_time, self._recycle_passed)

        self.debug_log("Entrance switch hit")
        if self.config['ball_capacity'] and self.config['ball_capacity'] <= self._last_count:
            # do not count beyond capacity
            self.ball_device.log.warning("Device received balls but is already full!")
        elif self.config['ball_capacity'] and self.config['entrance_switch_full_timeout'] and \
                self.config['ball_capacity'] == self._last_count + 1:
            # wait for entrance_switch_full_timeout before setting the device to full capacity
            self.invalidate_count()
        else:
            # increase count
            self._last_count += 1
            self._count_stable.set()
            self.trigger_activity()
            self.record_activity(BallEntranceActivity())
Exemple #2
0
    def _entrance_switch_handler(self, switch_name):
        """Add a ball to the device since the entrance switch has been hit."""
        # always invalidate count if this has been triggered by a real switch
        if switch_name != "event":
            self.invalidate_count()
        # If recycle is ongoing, do nothing
        if self.recycle_clear_time.get(switch_name, False):
            self.debug_log("Entrance switch hit within ignore window, taking no action")
            return
        # If a recycle time is configured, set a timeout to prevent future entrance activity
        if self.recycle_secs:
            self.recycle_clear_time[switch_name] = self.machine.clock.get_time() + self.recycle_secs
            self.machine.clock.loop.call_at(self.recycle_clear_time[switch_name], self._recycle_passed, switch_name)

        self.debug_log("Entrance switch hit")
        if self.config['ball_capacity'] and self.config['ball_capacity'] <= self._last_count:
            # do not count beyond capacity
            self.ball_device.log.warning("Device received balls but is already full!")
        elif self.config['ball_capacity'] and self.config['entrance_switch_full_timeout'] and \
                self.config['ball_capacity'] == self._last_count + 1:
            # wait for entrance_switch_full_timeout before setting the device to full capacity
            self._settle_delay.remove("count_stable")
        else:
            # increase count
            self._settle_delay.reset(self.config['settle_time_ms'], self.mark_count_as_stable_and_trigger_activity,
                                     "count_stable")
            self._last_count += 1
            self.record_activity(BallEntranceActivity())
Exemple #3
0
 def _entrance_switch_full_handler(self):
     # a ball is sitting on the entrance_switch. assume the device is full
     new_balls = self.config['ball_capacity'] - self._last_count
     self._count_stable.set()
     self.trigger_activity()
     if new_balls > 0:
         self.debug_log("Ball is sitting on entrance_switch. Assuming "
                        "device is full. Adding %s balls and setting balls"
                        "to %s", new_balls, self.config['ball_capacity'])
         self._last_count += new_balls
         for _ in range(new_balls):
             self.record_activity(BallEntranceActivity())
    async def _run(self):
        self._trigger_recount.set()
        while True:
            new_count = await self._recount()
            self._count_stable.set()

            if self._last_count is None:
                self._last_count = new_count
            elif self._last_count < 0:
                raise AssertionError("Count may never be negative")

            if self.is_jammed() and new_count == 1:
                # only jam is active. keep previous count
                self.debug_log(
                    "Counter is jammed. Only jam is active. Will no longer trust count."
                )
                # ball potentially returned
                if not self._is_unreliable:
                    self.trigger_activity()
                    self.record_activity(BallReturnActivity())
                    self._is_unreliable = True
                continue

            self._is_unreliable = False

            if new_count == self._last_count:
                # count did not change
                continue

            if new_count > self._last_count:
                # new ball
                for _ in range(new_count - self._last_count):
                    try:
                        last_entrance = self._entrances.pop(0)
                    except IndexError:
                        last_entrance = -1000

                    if last_entrance > self.machine.clock.get_time(
                    ) - self.config['entrance_event_timeout']:
                        self.record_activity(BallEntranceActivity())
                    else:
                        self.record_activity(UnknownBallActivity())
            elif new_count < self._last_count:
                # lost ball
                for _ in range(self._last_count - new_count):
                    self.record_activity(BallLostActivity())

            # update count
            self._last_count = new_count
            self.trigger_activity()
Exemple #5
0
    def _entrance_switch_handler(self):
        """Add a ball to the device since the entrance switch has been hit."""
        self.debug_log("Entrance switch hit")

        if self.config['ball_capacity'] and self.config['ball_capacity'] <= self._last_count:
            # do not count beyond capacity
            self.ball_device.log.warning("Device received balls but is already full!")
        elif self.config['ball_capacity'] and self.config['entrance_switch_full_timeout'] and \
                self.config['ball_capacity'] == self._last_count + 1:
            # wait for entrance_switch_full_timeout before setting the device to full capacity
            self.invalidate_count()
        else:
            # increase count
            self._last_count += 1
            self._count_stable.set()
            self.trigger_activity()
            self.record_activity(BallEntranceActivity())