From fbfe93a3c99295a95854897ac81b32c6270d0b9f Mon Sep 17 00:00:00 2001 From: Alex Burr Date: Fri, 8 Jul 2016 17:01:42 +0100 Subject: [PATCH] Add is_speaker_plugged API to daemon, allowing clients to know if the speaker is there. Change spu_monitor not to poll processes when speaker is not present, to reduce cpu usage. --- debian/changelog | 6 ++++++ kano_peripherals/speaker_leds/driver/service.py | 4 ++++ kano_peripherals/speaker_leds/use_cases.py | 15 ++++++++++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index edd6227..105c2cc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +kano-peripherals (3.4.0-0) unstable; urgency=low + + * Added is_speaker_plugged api to daemon + + -- Team Kano Mon, 11 Jan 2016 12:00:00 +0000 + kano-peripherals (2.3.0-0) unstable; urgency=low * Added LED Speaker daemon. diff --git a/kano_peripherals/speaker_leds/driver/service.py b/kano_peripherals/speaker_leds/driver/service.py index 2e7a4d4..805afdc 100644 --- a/kano_peripherals/speaker_leds/driver/service.py +++ b/kano_peripherals/speaker_leds/driver/service.py @@ -95,6 +95,10 @@ def _detect_thread(self): return True # keep calling this method indefinitely + @dbus.service.method(SPEAKER_LEDS_IFACE, in_signature='', out_signature='b') + def is_speaker_plugged(self): + return self.is_plugged + def _locking_thread(self): """ Check if the locking processes are still alive. diff --git a/kano_peripherals/speaker_leds/use_cases.py b/kano_peripherals/speaker_leds/use_cases.py index 6a58492..d5b4490 100644 --- a/kano_peripherals/speaker_leds/use_cases.py +++ b/kano_peripherals/speaker_leds/use_cases.py @@ -83,16 +83,21 @@ def cpu_monitor_start(update_rate, check_settings, retry_count): duration = update_rate cycles = duration / 2 + speakerleds_iface = high_level.get_speakerleds_interface() + while not high_level.interrupted: - led_speeds = _get_cpu_led_speeds(0.1, num_leds) + if speakerleds_iface.is_speaker_plugged(): + + led_speeds = _get_cpu_led_speeds(0.1, num_leds) - vf2 = high_level.pulse_each(vf, led_speeds) - successful = high_level.animate(vf2, duration, cycles) + vf2 = high_level.pulse_each(vf, led_speeds) + successful = high_level.animate(vf2, duration, cycles) - if not successful: + if not successful: + time.sleep(duration) + else: time.sleep(duration) - def cpu_monitor_stop(): _stop('cpu-monitor')