コード例 #1
0
    def setUpClass(self):
        # Stop any possible running animations.
        BaseAnimation.stop('')

        # Get DBus interface to the board and attempt a recovery if it fails.
        self.iface = get_speakerleds_interface()
        if not self.iface:
            self._attempt_to_recover_daemon()

        self.iface = get_speakerleds_interface()
        if not self.iface:
            pass  # TODO: Stop here, no point going forward. THIS SHOULD NOT HAPPEN!

        # Lock the board API so nothing can interfere.
        self.iface.lock(self.iface.get_max_lock_priority())
コード例 #2
0
    def _add_led_speaker_checkbox(self):
        self.cpu_monitor_checkbox = Gtk.CheckButton()
        is_led_speaker_plugged = False
        is_pi_hat_plugged = False

        try:
            from kano_peripherals.speaker_leds.driver.high_level import \
                get_speakerleds_interface
            from kano_peripherals.pi_hat.driver.high_level import \
                get_pihat_interface

            speaker_led_api = get_speakerleds_interface(retry_count=0)
            if speaker_led_api:  # can be None
                is_led_speaker_plugged = speaker_led_api.detect()

            pi_hat_api = get_pihat_interface(retry_count=0)
            if pi_hat_api:  # can be None
                is_pi_hat_plugged = pi_hat_api.detect()

        except Exception as e:
            logger.error(
                "Something unexpected occured in _add_led_speaker_checkbox"
                " - [{}]".format(e))

        if has_min_performance(RPI_2_B_SCORE) and (is_led_speaker_plugged
                                                   or is_pi_hat_plugged):
            self.buttons.append(self.cpu_monitor_checkbox)
            self.label_button_and_pack(self.cpu_monitor_checkbox,
                                       _("Enable LED ring CPU Animation"), '')
コード例 #3
0
    def _add_led_speaker_checkbox(self):
        self.cpu_monitor_checkbox = Gtk.CheckButton()
        is_led_speaker_plugged = False
        is_pi_hat_plugged = False

        try:
            from kano_peripherals.speaker_leds.driver.high_level import \
                get_speakerleds_interface
            from kano_peripherals.pi_hat.driver.high_level import \
                get_pihat_interface

            speaker_led_api = get_speakerleds_interface(retry_count=0)
            if speaker_led_api:  # can be None
                is_led_speaker_plugged = speaker_led_api.detect()

            pi_hat_api = get_pihat_interface(retry_count=0)
            if pi_hat_api:  # can be None
                is_pi_hat_plugged = pi_hat_api.detect()

        except Exception as e:
            logger.error("Something unexpected occured in _add_led_speaker_checkbox"
                         " - [{}]".format(e))

        if has_min_performance(RPI_2_B_SCORE) and (is_led_speaker_plugged or is_pi_hat_plugged):
            self.buttons.append(self.cpu_monitor_checkbox)
            self.label_button_and_pack(
                self.cpu_monitor_checkbox,
                _("Enable LED ring CPU Animation"), ''
            )
コード例 #4
0
class TestSpeakerLED(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        # Stop any possible running animations.
        BaseAnimation.stop('')

        # Get DBus interface to the board and attempt a recovery if it fails.
        self.iface = get_speakerleds_interface()
        if not self.iface:
            self._attempt_to_recover_daemon()

        self.iface = get_speakerleds_interface()
        if not self.iface:
            pass  # TODO: Stop here, no point going forward. THIS SHOULD NOT HAPPEN!

        # Lock the board API so nothing can interfere.
        self.iface.lock(self.iface.get_max_lock_priority())

    @classmethod
    def teadDownClass(self):
        # Unlock the board API on DBus.
        self.iface.unlock()

    # --- Tests -------------------------------------------------------------------------

    def test_speakerled_board_detected(self):
        self.assertTrue(self.iface.detect(), 'Speaker LED board could not be detected!')

    @unittest.skipIf(not get_speakerleds_interface().detect(), 'Board not detected, skipping')
    def test_run_rgb_sequence(self):
        animation = InitFlow()
        animation.connect()

        response = ''

        while response not in ('yes', 'no', 'y', 'n'):
            animation.start(2.5, 5.0)
            text = 'Did you see the LEDs light up? Please type "y" or "n". Type "r" to replay. '
            response = raw_input(text).lower().strip()

        saw_animation = (response == 'yes' or response == 'y')

        self.assertTrue(saw_animation, 'Animation could not be observed on Speaker LED!')

    # --- Helpers -----------------------------------------------------------------------

    def _attempt_to_recover_daemon(self):
        os.system('/usr/bin/kano-boards-daemon &')
        time.sleep(2)