X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/48a8b0cfe0b7d5b75ffcb357a1125ca25d972045..bdd86c7e4ff0b579f69965f9ff0e5b6bfc973f95:/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py diff --git a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py index e95a1e6..f751b71 100644 --- a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py +++ b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py @@ -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