Exemplo n.º 1
0
 def _stop_heartbeat(self):
     """
     Stop the heartbeat animation if its currently running.
     """
     if self.heartbeat:
         cancel(self.heartbeat)
         self.heartbeat = None
Exemplo n.º 2
0
 def on_exit(self):
     # Stop all LED animations before exiting
     if self.led_fade:
         cancel(self.led_fade)
         self.led_fade = None
     if self.led_fade_in_out:
         cancel(self.led_fade_in_out)
         self.led_fade_in_out = None
Exemplo n.º 3
0
 def stop(self):
     """
     Stop the current running animation (if any).
     """
     self.current += 1
     if self.animation:
         self.animation._running = False
     if self.runner:
         cancel(self.runner)
         self.runner = None
Exemplo n.º 4
0
 def on_right_button_up(self):
     """
     Invoked when the user no longer presses down the right button.
     Stop the adjust coroutine if it's running to stop adjusting
     the actuator values.
     """
     if self.adjust:
         cancel(self.adjust)
         self.adjust = None
     self._update_display()
Exemplo n.º 5
0
    def on_resume(self):
        current_program = self.get_current_program()
        current_image = current_program.get_image()
        animation = shift_in_from_bottom(current_image)

        hub.sound.play(Sounds.PROGRAM_STOP, 16000)
        hub.display.show(animation, delay=44)

        # Stop LED fading in and out animation
        if self.led_fade_in_out:
            cancel(self.led_fade_in_out)
            self.led_fade_in_out = None

        # Start LED fade in animation
        self.led_fade = call_soon(led_fade_to(BLUE, 100, 1))
Exemplo n.º 6
0
    def on_pause(self):
        current_program = self.get_current_program()
        current_image = current_program.get_image()
        animation = shift_out_to_bottom(current_image)

        hub.sound.play(Sounds.PROGRAM_START, 16000)
        hub.display.show(animation, delay=44)

        # Stop LED fade in animation
        if self.led_fade:
            cancel(self.led_fade)
            self.led_fade = None

        # Start LED fading in and out animation
        self.led_fade_in_out = call_soon(led_fade_in_out())
Exemplo n.º 7
0
    def on_disconnected_right(self):
        """
        Invoked when the user disconnects the device in the right port.
        """
        # Make sure this method won't fail even if invoked when no left
        # device connected
        if not self.right:
            return

        # Stop reading sensor values from this device
        if self.right_read:
            cancel(self.right_read)
            self.right_read = None

        # Set other device' value to zero if this was a sensor
        if self.right.is_sensor() and self.left:
            self.left.set_value(0)

        self.right = None
        self.right_value = 0
        self._update_display()
Exemplo n.º 8
0
    def on_exit(self):
        """
        Invoked as the last thing before the default application exists.
        """
        self.running = False

        # Stop ongoing animation
        self.display.animation.stop()

        # Stop reading sensor values from these devices
        if self.left_read:
            cancel(self.left_read)
            self.left_read = None
        if self.right_read:
            cancel(self.right_read)
            self.right_read = None

        # Stop adjusting actuator values
        if self.adjust:
            cancel(self.adjust)
            self.adjust = None

        if self.left:
            self.left.set_value(0)
            self.left = None
        if self.right:
            self.right.set_value(0)
            self.right = None

        self.left_value = 0
        self.right_value = 0