]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/bcm283x/pwmio/PWMOut.py
Untangle code and remove pylint disables
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / bcm283x / pwmio / PWMOut.py
index 3a58d64afbdf39226de60228e60c26d1efa66032..3633cebd62d3cd87f4e0b774771459a32373ec7a 100644 (file)
@@ -1,33 +1,25 @@
-# pylint: disable=invalid-name
 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
 #
 # SPDX-License-Identifier: MIT
 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
 #
 # SPDX-License-Identifier: MIT
-# pylint: enable=invalid-name
+
 """ PWMOut Class for lgpio lg library tx_pwm library """
 
 import lgpio
 """ PWMOut Class for lgpio lg library tx_pwm library """
 
 import lgpio
-import board    # need board to get access to the CHIP object in the pin module
+from adafruit_blinka.microcontroller.bcm283x.pin import CHIP
+
 
 
-# pylint: disable=unnecessary-pass
 class PWMError(IOError):
     """Base class for PWM errors."""
 
 class PWMError(IOError):
     """Base class for PWM errors."""
 
-    pass
-
-
-# pylint: enable=unnecessary-pass
 
 
-
-class PWMOut:            # pylint: disable=invalid-name
+class PWMOut:
     """Pulse Width Modulation Output Class"""
 
     """Pulse Width Modulation Output Class"""
 
-    def __init__(self, pin, *, frequency=500, duty_cycle=0,
-                 variable_frequency=False):
+    def __init__(self, pin, *, frequency=500, duty_cycle=0, variable_frequency=False):
         if variable_frequency:
             print("Variable Frequency is not supported, ignoring...")
         self._pin = pin
         if variable_frequency:
             print("Variable Frequency is not supported, ignoring...")
         self._pin = pin
-        result = lgpio.gpio_claim_output(board.pin.CHIP, self._pin.id,
-                                         lFlags=lgpio.SET_PULL_NONE)
+        result = lgpio.gpio_claim_output(CHIP, self._pin.id, lFlags=lgpio.SET_PULL_NONE)
         if result < 0:
             raise RuntimeError(lgpio.error_text(result))
         self._enabled = False
         if result < 0:
             raise RuntimeError(lgpio.error_text(result))
         self._enabled = False
@@ -45,19 +37,18 @@ class PWMOut:            # pylint: disable=invalid-name
     def __enter__(self):
         return self
 
     def __enter__(self):
         return self
 
-    def __exit__(self, exc_type, exc_val, exc_tb):
+    def __exit__(self, _exc_type, _exc_val, _exc_tb):
         self.deinit()
 
     def deinit(self):
         """Deinit the PWM."""
         if not self._deinited:
             if self.enabled:
         self.deinit()
 
     def deinit(self):
         """Deinit the PWM."""
         if not self._deinited:
             if self.enabled:
-                self._enabled = False       # turn off the pwm
+                self._enabled = False  # turn off the pwm
             self._deinited = True
 
             self._deinited = True
 
-
     def _is_deinited(self):
     def _is_deinited(self):
-        """ raise Value error if the object has been de-inited """
+        """raise Value error if the object has been de-inited"""
         if self._deinited:
             raise ValueError(
                 "Object has been deinitialize and can no longer "
         if self._deinited:
             raise ValueError(
                 "Object has been deinitialize and can no longer "
@@ -103,15 +94,14 @@ class PWMOut:            # pylint: disable=invalid-name
             raise TypeError("Invalid duty cycle type, should be int or float.")
 
         if not 0 <= duty_cycle <= 65535:
             raise TypeError("Invalid duty cycle type, should be int or float.")
 
         if not 0 <= duty_cycle <= 65535:
-            raise ValueError("Invalid duty cycle value, should be between "
-                             "0 and 65535")
+            raise ValueError("Invalid duty cycle value, should be between 0 and 65535")
 
         # convert from 16-bit
         duty_cycle /= 65535.0
 
         self._duty_cycle = duty_cycle
         if self._enabled:
 
         # convert from 16-bit
         duty_cycle /= 65535.0
 
         self._duty_cycle = duty_cycle
         if self._enabled:
-            self.enabled = True        # turn on with new values
+            self.enabled = True  # turn on with new values
 
     @property
     def frequency(self):
 
     @property
     def frequency(self):
@@ -133,7 +123,7 @@ class PWMOut:            # pylint: disable=invalid-name
 
         self._frequency = frequency
         if self.enabled:
 
         self._frequency = frequency
         if self.enabled:
-            self.enabled = True        # turn on with new values
+            self.enabled = True  # turn on with new values
 
     @property
     def enabled(self):
 
     @property
     def enabled(self):
@@ -155,13 +145,14 @@ class PWMOut:            # pylint: disable=invalid-name
         frequency = self._frequency if value else 0
         duty_cycle = round(self._duty_cycle * 100)
         self._enabled = value
         frequency = self._frequency if value else 0
         duty_cycle = round(self._duty_cycle * 100)
         self._enabled = value
-        result = lgpio.tx_pwm(board.pin.CHIP, self._pin.id, frequency, duty_cycle)
+        result = lgpio.tx_pwm(CHIP, self._pin.id, frequency, duty_cycle)
         if result < 0:
             raise RuntimeError(lgpio.error_text(result))
         return result
 
         if result < 0:
             raise RuntimeError(lgpio.error_text(result))
         return result
 
-
     # String representation
     def __str__(self):
     # String representation
     def __str__(self):
-        return (f"pin {self._pin} (freq={self.frequency:f} Hz, duty_cycle="
-                f"{self.duty_cycle}({round(self.duty_cycle / 655.35)}%)")
+        return (
+            f"pin {self._pin} (freq={self.frequency:f} Hz, duty_cycle="
+            f"{self.duty_cycle}({round(self.duty_cycle / 655.35)}%)"
+        )