]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py
Restructure and move pins to generic linux
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / generic_linux / sysfs_pin.py
index 50c27a7b6ca0a3d13bad10b0c413c89cbbc54ba1..86c9a5fd69cda0d07100bfd0afce1b8a08467585 100644 (file)
@@ -1,3 +1,6 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """
 Much code from https://github.com/vsergeev/python-periphery/blob/master/periphery/gpio.py
 Copyright (c) 2015-2019 vsergeev / Ivan (Vanya) A. Sergeev
 """
 Much code from https://github.com/vsergeev/python-periphery/blob/master/periphery/gpio.py
 Copyright (c) 2015-2019 vsergeev / Ivan (Vanya) A. Sergeev
@@ -8,6 +11,7 @@ import os
 import errno
 import time
 
 import errno
 import time
 
+
 # pylint: disable=unnecessary-pass
 class GPIOError(IOError):
     """Base class for GPIO errors."""
 # pylint: disable=unnecessary-pass
 class GPIOError(IOError):
     """Base class for GPIO errors."""
@@ -132,7 +136,7 @@ class Pin:
         if not os.path.isdir(gpio_path):
             # Export the line
             try:
         if not os.path.isdir(gpio_path):
             # Export the line
             try:
-                with open("/sys/class/gpio/export", "w") as f_export:
+                with open("/sys/class/gpio/export", "w", encoding="utf-8") as f_export:
                     f_export.write("{:d}\n".format(self.id))
             except IOError as e:
                 raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror) from IOError
                     f_export.write("{:d}\n".format(self.id))
             except IOError as e:
                 raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror) from IOError
@@ -155,7 +159,9 @@ class Pin:
             # permission rule application after export
             for i in range(self.GPIO_OPEN_RETRIES):
                 try:
             # permission rule application after export
             for i in range(self.GPIO_OPEN_RETRIES):
                 try:
-                    with open(os.path.join(gpio_path, "direction"), "w") as f_direction:
+                    with open(
+                        os.path.join(gpio_path, "direction"), "w", encoding="utf-8"
+                    ) as f_direction:
                         f_direction.write(direction.lower() + "\n")
                     break
                 except IOError as e:
                         f_direction.write(direction.lower() + "\n")
                     break
                 except IOError as e:
@@ -170,7 +176,9 @@ class Pin:
         else:
             # Write direction
             try:
         else:
             # Write direction
             try:
-                with open(os.path.join(gpio_path, "direction"), "w") as f_direction:
+                with open(
+                    os.path.join(gpio_path, "direction"), "w", encoding="utf-8"
+                ) as f_direction:
                     f_direction.write(direction.lower() + "\n")
             except IOError as e:
                 raise GPIOError(
                     f_direction.write(direction.lower() + "\n")
             except IOError as e:
                 raise GPIOError(
@@ -268,7 +276,7 @@ class Pin:
         gpio_path = "/sys/class/gpio/{:s}/label".format(self.chip_name)
 
         try:
         gpio_path = "/sys/class/gpio/{:s}/label".format(self.chip_name)
 
         try:
-            with open(gpio_path, "r") as f_label:
+            with open(gpio_path, "r", encoding="utf-8") as f_label:
                 label = f_label.read()
         except (GPIOError, IOError) as e:
             if isinstance(e, IOError):
                 label = f_label.read()
         except (GPIOError, IOError) as e:
             if isinstance(e, IOError):
@@ -287,7 +295,9 @@ class Pin:
     def _get_direction(self):
         # Read direction
         try:
     def _get_direction(self):
         # Read direction
         try:
-            with open(os.path.join(self._path, "direction"), "r") as f_direction:
+            with open(
+                os.path.join(self._path, "direction"), "r", encoding="utf-8"
+            ) as f_direction:
                 direction = f_direction.read()
         except IOError as e:
             raise GPIOError(
                 direction = f_direction.read()
         except IOError as e:
             raise GPIOError(
@@ -304,7 +314,9 @@ class Pin:
 
         # Write direction
         try:
 
         # Write direction
         try:
-            with open(os.path.join(self._path, "direction"), "w") as f_direction:
+            with open(
+                os.path.join(self._path, "direction"), "w", encoding="utf-8"
+            ) as f_direction:
                 f_direction.write(direction.lower() + "\n")
         except IOError as e:
             raise GPIOError(
                 f_direction.write(direction.lower() + "\n")
         except IOError as e:
             raise GPIOError(