]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py
Merge pull request #1 from scottamain/pwmbug
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / generic_linux / sysfs_pwmout.py
index e95a1e627c74c4d1ea4e7f10a4343fe5b450821e..f751b71a4a017dc3870da1e1445820b6c521e1ce 100644 (file)
@@ -26,6 +26,7 @@ class PWMError(IOError):
 
 class PWMOut:
     """Pulse Width Modulation Output Class"""
+
     # Number of retries to check for successful PWM export on open
     PWM_STAT_RETRIES = 10
     # Delay between check for scucessful PWM export on open (100ms)
@@ -121,14 +122,17 @@ class PWMOut:
         for i in range(PWMOut.PWM_STAT_RETRIES):
             try:
                 with open(
-                    os.path.join(channel_path, self._pin_path.format(self._pwmpin), "period"), 'w'
+                    os.path.join(
+                        channel_path, self._pin_path.format(self._pwmpin), "period"
+                    ),
+                    "w",
                 ):
-                    print('#### okay ####')
                     break
             except IOError as e:
-                if e.errno != EACCES or (e.errno == EACCES and i == PWMOut.PWM_STAT_RETRIES - 1):
-                    print('#### catch ####')
-                    raise PWMError(e.errno, "Opening PWM period: " + e.strerror)
+                if e.errno != EACCES or (
+                    e.errno == EACCES and i == PWMOut.PWM_STAT_RETRIES - 1
+                ):
+                    raise PWMError(e.errno, "Opening PWM period: " + e.strerror) from e
             sleep(PWMOut.PWM_STAT_DELAY)
 
         # self._set_enabled(False) # This line causes a write error when trying to enable