Răsfoiți Sursa

add docstring for Rpi class

nico 8 ani în urmă
părinte
comite
88c6891dc0
1 a modificat fișierele cu 28 adăugiri și 4 ștergeri
  1. 28 4
      kalliope/core/Utils/RpiUtils.py

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

@@ -19,7 +19,11 @@ class RpiUtils(Thread):
 
     def __init__(self, rpi_settings=None, callback=None):
         """
-        
+        Class used to:
+        - manage RPI GPIO
+        - thread to catch mute button signal
+        The object receive a rpi settings object which contains pin number to use on the Rpi
+        When a signal is caught form the mute button, the callback method from the main controller is called
         :param rpi_settings: Settings object with GPIO pin number to use
         :type rpi_settings: RpiSettings
         :param callback: Callback function from the main controller to call when the mute button is pressed
@@ -32,6 +36,9 @@ class RpiUtils(Thread):
         self.init_gpio(self.rpi_settings)
 
     def run(self):
+        """
+        Start the thread to make kalliope waiting for an input GPIO signal
+        """
         # run the main thread
         try:
             while True:  # keep the thread alive
@@ -43,8 +50,7 @@ class RpiUtils(Thread):
     def switch_kalliope_mute_led(self, event):
         """
         Switch the state of the MUTE LED
-        :param event: 
-        :return: 
+        :param event: not used
         """
         logger.debug("[RpiUtils] Event button caught. Switching mute led")
         # get led status
@@ -59,11 +65,21 @@ class RpiUtils(Thread):
             self.switch_pin_to_on(self.rpi_settings.pin_led_muted)
             self.callback(muted=True)
 
-    def destroy(self):
+    @staticmethod
+    def destroy():
+        """
+        Cleanup GPIO to not keep a pin to HIGH status
+        :return: 
+        """
         logger.debug("[RpiUtils] Cleanup GPIO configuration")
         GPIO.cleanup()
 
     def init_gpio(self, rpi_settings):
+        """
+        Initialize GPIO pin to a default value. Leds are off by default
+        Mute button is set as an input
+        :param rpi_settings: RpiSettings object
+        """
         # All led are off by default
         if self.rpi_settings.pin_led_muted:
             GPIO.setup(rpi_settings.pin_led_muted, GPIO.OUT, initial=GPIO.LOW)
@@ -82,10 +98,18 @@ class RpiUtils(Thread):
 
     @classmethod
     def switch_pin_to_on(cls, pin_number):
+        """
+        Switch the pin_number of the RPI GPIO board to HIGH status
+        :param pin_number: integer pin number to switch HIGH
+        """
         logger.debug("[RpiUtils] Switching pin number %s to ON" % pin_number)
         GPIO.output(pin_number, GPIO.HIGH)
 
     @classmethod
     def switch_pin_to_off(cls, pin_number):
+        """
+        Switch the pin_number of the RPI GPIO board to LOW status
+        :param pin_number: integer pin number to switch LOW
+        """
         logger.debug("[RpiUtils] Switching pin number %s to OFF" % pin_number)
         GPIO.output(pin_number, GPIO.LOW)