try:
from microcontroller.pin import pwmOuts
except ImportError:
- raise RuntimeError("No PWM outputs defined for this board")
+ raise RuntimeError("No PWM outputs defined for this board") from ImportError
# pylint: disable=unnecessary-pass
class PWMError(IOError):
) as f_export:
f_export.write("%d\n" % self._pwmpin)
except IOError as e:
- raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror)
+ raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror) from IOError
# Look up the period, for fast duty cycle updates
self._period = self._get_period()
) as f_unexport:
f_unexport.write("%d\n" % self._pwmpin)
except IOError as e:
- raise PWMError(e.errno, "Unexporting PWM pin: " + e.strerror)
+ raise PWMError(
+ e.errno, "Unexporting PWM pin: " + e.strerror
+ ) from IOError
except Exception as e:
# due to a race condition for which I have not yet been
# able to find the root cause, deinit() often fails
try:
period_ns = int(period_ns)
except ValueError:
- raise PWMError(None, 'Unknown period value: "%s"' % period_ns)
+ raise PWMError(
+ None, 'Unknown period value: "%s"' % period_ns
+ ) from ValueError
# Convert period from nanoseconds to seconds
period = period_ns / 1e9
try:
duty_cycle_ns = int(duty_cycle_ns)
except ValueError:
- raise PWMError(None, 'Unknown duty cycle value: "%s"' % duty_cycle_ns)
+ raise PWMError(
+ None, 'Unknown duty cycle value: "%s"' % duty_cycle_ns
+ ) from ValueError
# Convert duty cycle from nanoseconds to seconds
duty_cycle = duty_cycle_ns / 1e9
"""
import re
-from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
import gpiod
+from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
chip0 = gpiod.Chip("0")
chip1 = gpiod.Chip("1")
print("Message Queue Key: ", self._mq.key)
queues.append(self._mq)
except sysv_ipc.ExistentialError:
- raise RuntimeError("Message queue creation failed")
+ raise RuntimeError(
+ "Message queue creation failed"
+ ) from sysv_ipc.ExistentialError
dir_path = os.path.dirname(os.path.realpath(__file__))
cmd = [
except FileNotFoundError:
raise RuntimeError(
"I2C Bus #%d not found, check if enabled in config!" % bus_num
- )
+ ) from RuntimeError
# pylint: enable=unused-argument
raise ImportError(
"libgpiod Python bindings not found, please install and try again! See "
"https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/libgpiod.sh"
- )
+ ) from ImportError
class Pin:
raise ImportError(
"Periphery Python bindings not found, please install and try again! "
"Try running 'pip3 install python-periphery'"
- )
+ ) from ImportError
class Pin:
try:
from microcontroller.pin import analogIns
except ImportError:
- raise RuntimeError("No Analog Inputs defined for this board")
+ raise RuntimeError("No Analog Inputs defined for this board") from ImportError
class AnalogIn(ContextManaged):
try:
from microcontroller.pin import analogOuts
except ImportError:
- raise RuntimeError("No Analog Outputs defined for this board")
+ raise RuntimeError("No Analog Outputs defined for this board") from ImportError
class AnalogOut(ContextManaged):
with open("/sys/class/gpio/export", "w") as f_export:
f_export.write("{:d}\n".format(self.id))
except IOError as e:
- raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror) from IOError
# Loop until GPIO is exported
exported = False
):
raise GPIOError(
e.errno, "Setting GPIO direction: " + e.strerror
- )
+ ) from IOError
time.sleep(self.GPIO_OPEN_DELAY)
else:
with open(os.path.join(gpio_path, "direction"), "w") as f_direction:
f_direction.write(direction.lower() + "\n")
except IOError as e:
- raise GPIOError(e.errno, "Setting GPIO direction: " + e.strerror)
+ raise GPIOError(
+ e.errno, "Setting GPIO direction: " + e.strerror
+ ) from IOError
# Open value
try:
self._fd = os.open(os.path.join(gpio_path, "value"), os.O_RDWR)
except OSError as e:
- raise GPIOError(e.errno, "Opening GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Opening GPIO: " + e.strerror) from OSError
self._path = gpio_path
try:
os.close(self._fd)
except OSError as e:
- raise GPIOError(e.errno, "Closing GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Closing GPIO: " + e.strerror) from OSError
self._fd = None
os.write(unexport_fd, "{:d}\n".format(self.id).encode())
os.close(unexport_fd)
except OSError as e:
- raise GPIOError(e.errno, "Unexporting GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Unexporting GPIO: " + e.strerror) from OSError
def _read(self):
# Read value
try:
buf = os.read(self._fd, 2)
except OSError as e:
- raise GPIOError(e.errno, "Reading GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Reading GPIO: " + e.strerror) from OSError
# Rewind
try:
os.lseek(self._fd, 0, os.SEEK_SET)
except OSError as e:
- raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror) from OSError
if buf[0] == b"0"[0]:
return False
else:
os.write(self._fd, b"0\n")
except OSError as e:
- raise GPIOError(e.errno, "Writing GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Writing GPIO: " + e.strerror) from OSError
# Rewind
try:
os.lseek(self._fd, 0, os.SEEK_SET)
except OSError as e:
- raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror)
+ raise GPIOError(e.errno, "Rewinding GPIO: " + e.strerror) from OSError
@property
def chip_name(self):
label = f_label.read()
except (GPIOError, IOError) as e:
if isinstance(e, IOError):
- raise GPIOError(e.errno, "Reading gpiochip label: " + e.strerror)
+ raise GPIOError(
+ e.errno, "Reading gpiochip label: " + e.strerror
+ ) from IOError
- raise GPIOError(None, "Reading gpiochip label: " + e.strerror)
+ raise GPIOError(
+ None, "Reading gpiochip label: " + e.strerror
+ ) from GPIOError
return label.strip()
with open(os.path.join(self._path, "direction"), "r") as f_direction:
direction = f_direction.read()
except IOError as e:
- raise GPIOError(e.errno, "Getting GPIO direction: " + e.strerror)
+ raise GPIOError(
+ e.errno, "Getting GPIO direction: " + e.strerror
+ ) from IOError
return direction.strip()
with open(os.path.join(self._path, "direction"), "w") as f_direction:
f_direction.write(direction.lower() + "\n")
except IOError as e:
- raise GPIOError(e.errno, "Setting GPIO direction: " + e.strerror)
+ raise GPIOError(
+ e.errno, "Setting GPIO direction: " + e.strerror
+ ) from IOError
direction = property(_get_direction, _set_direction)
try:
from microcontroller.pin import pwmOuts
except ImportError:
- raise RuntimeError("No PWM outputs defined for this board")
+ raise RuntimeError("No PWM outputs defined for this board") from ImportError
# pylint: disable=unnecessary-pass
with open(os.path.join(channel_path, self._export_path), "w") as f_export:
f_export.write("%d\n" % self._pwmpin)
except IOError as e:
- raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror)
+ raise PWMError(e.errno, "Exporting PWM pin: " + e.strerror) from IOError
# self._set_enabled(False) # This line causes a write error when trying to enable
) as f_unexport:
f_unexport.write("%d\n" % self._pwmpin)
except IOError as e:
- raise PWMError(e.errno, "Unexporting PWM pin: " + e.strerror)
+ raise PWMError(
+ e.errno, "Unexporting PWM pin: " + e.strerror
+ ) from IOError
self._channel = None
self._pwmpin = None
try:
period_ns = int(period_ns)
except ValueError:
- raise PWMError(None, 'Unknown period value: "%s"' % period_ns)
+ raise PWMError(
+ None, 'Unknown period value: "%s"' % period_ns
+ ) from ValueError
# Convert period from nanoseconds to seconds
period = period_ns / 1e9
try:
duty_cycle_ns = int(duty_cycle_ns)
except ValueError:
- raise PWMError(None, 'Unknown duty cycle value: "%s"' % duty_cycle_ns)
+ raise PWMError(
+ None, 'Unknown duty cycle value: "%s"' % duty_cycle_ns
+ ) from ValueError
# Convert duty cycle from nanoseconds to seconds
duty_cycle = duty_cycle_ns / 1e9
# from the C driver
# http://ww1.microchip.com/downloads/en/DeviceDoc/mcp2221_0_1.tar.gz
# others (???) determined during driver developement
-# pylint: disable=bad-whitespace
RESP_ERR_NOERR = 0x00
RESP_ADDR_NACK = 0x25
RESP_READ_ERR = 0x7F
MCP2221_RETRY_MAX = 50
MCP2221_MAX_I2C_DATA_LEN = 60
MASK_ADDR_NACK = 0x40
-# pylint: enable=bad-whitespace
class MCP2221:
try:
from microcontroller.pin import pwmOuts
except ImportError:
- raise RuntimeError("No PWM outputs defined for this board")
+ raise RuntimeError("No PWM outputs defined for this board") from ImportError
from microcontroller.pin import Pin
from greatfet.interfaces.adc import ADC
gf = GreatFET()
-except:
+except ModuleNotFoundError:
raise RuntimeError(
"Unable to create GreatFET object. Make sure library is "
"installed and the device is connected."
- )
+ ) from ModuleNotFoundError
class Pin:
try:
from microcontroller.pin import pwmOuts
except ImportError:
- raise RuntimeError("No PWM outputs defined for this board")
+ raise RuntimeError("No PWM outputs defined for this board") from ImportError
# pylint: disable=unnecessary-pass
class PWMError(IOError):
except AttributeError:
raise NotImplementedError(
"Frequency attribute not implemented for this platform"
- )
+ ) from AttributeError
def write(self, buf, start=0, end=None):
"""Write to the SPI device"""