]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py
Updated pylint config and linted everything
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / bcm283x / pulseio / PulseIn.py
index fd9febee7dabdbe70f5fec1bd3d9810fb2943b43..4f7ae362ddf449d2b9b5f610e0a3227b02188af8 100644 (file)
@@ -1,15 +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 struct
 import sysv_ipc
 
 DEBUG = False
 queues = []
 procs = []
 
 import sysv_ipc
 
 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
@@ -25,7 +30,8 @@ def final():
 
 atexit.register(final)
 
 
 atexit.register(final)
 
-# pylint: disable=c-extension-no-member, consider-using-with
+
+# pylint: disable=c-extension-no-member
 class PulseIn:
     """PulseIn Class to read PWM signals"""
 
 class PulseIn:
     """PulseIn Class to read PWM signals"""
 
@@ -49,9 +55,15 @@ class PulseIn:
                 "Message queue creation failed"
             ) from sysv_ipc.ExistentialError
 
                 "Message queue creation failed"
             ) from sysv_ipc.ExistentialError
 
+        # Check if OS is 64-bit
+        if struct.calcsize("P") * 8 == 64:  # pylint: disable=no-member
+            libgpiod_filename = "libgpiod_pulsein64"
+        else:
+            libgpiod_filename = "libgpiod_pulsein"
+
         dir_path = os.path.dirname(os.path.realpath(__file__))
         cmd = [
         dir_path = os.path.dirname(os.path.realpath(__file__))
         cmd = [
-            dir_path + "/libgpiod_pulsein",
+            dir_path + "/" + libgpiod_filename,
             "--pulses",
             str(maxlen),
             "--queue",
             "--pulses",
             str(maxlen),
             "--queue",
@@ -64,7 +76,7 @@ class PulseIn:
         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