Parcourir la source

fix RpiUtils. User can comment out some pin

nico il y a 8 ans
Parent
commit
457cfe4452
3 fichiers modifiés avec 17 ajouts et 5 suppressions
  1. 10 0
      Docs/settings.md
  2. 2 1
      kalliope/core/MainController.py
  3. 5 4
      kalliope/core/Utils/RpiUtils.py

+ 10 - 0
Docs/settings.md

@@ -347,6 +347,16 @@ rpi:
   pin_led_listening: 22
 ```
 
+You can also define a couple led instead of all if you don't use them
+```yml
+rpi:
+  pin_mute_button: 6
+  pin_led_started: 5
+#  pin_led_muted: 17
+#  pin_led_talking: 27
+#  pin_led_listening: 22
+```
+
 **Example circuit**
 
 You will be using one of the ‘ground’ (GND) pins to act like the ‘negative’ or 0 volt ends of a battery. 

+ 2 - 1
kalliope/core/MainController.py

@@ -46,9 +46,10 @@ class MainController:
 
         self.rpi_utils = None
         if self.settings.rpi_settings:
+            # the useer set GPIO pin, we need to instantiate the RpiUtils class in order to setup GPIO
+            self.rpi_utils = RpiUtils(self.settings.rpi_settings, self.muted_button_pressed)
             if self.settings.rpi_settings.pin_mute_button:
                 # start the listening for button pressed thread only if the user set a pin
-                self.rpi_utils = RpiUtils(self.settings.rpi_settings, self.muted_button_pressed)
                 self.rpi_utils.daemon = True
                 self.rpi_utils.start()
         # switch high the start led, as kalliope is started. Only if the setting exist

+ 5 - 4
kalliope/core/Utils/RpiUtils.py

@@ -91,10 +91,11 @@ class RpiUtils(Thread):
             GPIO.setup(rpi_settings.pin_led_talking, GPIO.OUT, initial=GPIO.LOW)
 
         # MUTE button
-        GPIO.setup(rpi_settings.pin_mute_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
-        GPIO.add_event_detect(rpi_settings.pin_mute_button, GPIO.FALLING,
-                              callback=self.switch_kalliope_mute_led,
-                              bouncetime=500)
+        if self.rpi_settings.pin_mute_button:
+            GPIO.setup(rpi_settings.pin_mute_button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
+            GPIO.add_event_detect(rpi_settings.pin_mute_button, GPIO.FALLING,
+                                  callback=self.switch_kalliope_mute_led,
+                                  bouncetime=500)
 
     @classmethod
     def switch_pin_to_on(cls, pin_number):