]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py
Untangle code and remove pylint disables
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / bcm283x / pulseio / PulseIn.py
index 326f802ac3afb283b00c8721dbd016b00271d056..78d5761afcfb6df5cc0191f28d8e240c7b945eb9 100644 (file)
@@ -1,16 +1,20 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """Custom PulseIn Class to read PWM signals"""
 import time
 import subprocess
 import os
 import atexit
 import random
 """Custom PulseIn Class to read PWM signals"""
 import time
 import subprocess
 import os
 import atexit
 import random
-import sysv_ipc
 import struct
 import struct
+import sysv_ipc
 
 DEBUG = False
 queues = []
 procs = []
 
 
 DEBUG = False
 queues = []
 procs = []
 
+
 # The message queues live outside of python space, and must be formally cleaned!
 def final():
     """In case the program is cancelled or quit, we need to clean up the PulseIn
 # The message queues live outside of python space, and must be formally cleaned!
 def final():
     """In case the program is cancelled or quit, we need to clean up the PulseIn
@@ -26,6 +30,7 @@ def final():
 
 atexit.register(final)
 
 
 atexit.register(final)
 
+
 # pylint: disable=c-extension-no-member
 class PulseIn:
     """PulseIn Class to read PWM signals"""
 # pylint: disable=c-extension-no-member
 class PulseIn:
     """PulseIn Class to read PWM signals"""
@@ -51,7 +56,7 @@ class PulseIn:
             ) from sysv_ipc.ExistentialError
 
         # Check if OS is 64-bit
             ) from sysv_ipc.ExistentialError
 
         # Check if OS is 64-bit
-        if struct.calcsize("P") * 8 == 64:
+        if struct.calcsize("P") * 8 == 64:  # pylint: disable=no-member
             libgpiod_filename = "libgpiod_pulsein64"
         else:
             libgpiod_filename = "libgpiod_pulsein"
             libgpiod_filename = "libgpiod_pulsein64"
         else:
             libgpiod_filename = "libgpiod_pulsein"
@@ -66,12 +71,16 @@ class PulseIn:
         ]
         if idle_state:
             cmd.append("-i")
         ]
         if idle_state:
             cmd.append("-i")
-        cmd.append("gpiochip0")
-        cmd.append(str(pin))
+        if isinstance(pin.id, tuple):
+            cmd.append(f"gpiochip{pin.id[0]}")
+            cmd.append(str(pin.id[1]))
+        else:
+            cmd.append("gpiochip0")
+            cmd.append(str(pin))
         if DEBUG:
             print(cmd)
 
         if DEBUG:
             print(cmd)
 
-        self._process = subprocess.Popen(cmd)
+        self._process = subprocess.Popen(cmd)  # pylint: disable=consider-using-with
         procs.append(self._process)
 
         # wait for it to start up
         procs.append(self._process)
 
         # wait for it to start up