From f24cd41e8d3dd8bd9e752fc450fff2d01afe1092 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 3 Jun 2019 16:05:11 -0500 Subject: [PATCH] add '_is_deinited()' to guard against reads/writes on an inactive pin. --- .../microcontroller/generic_linux/sysfs_pwmout.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py index e7d64a0..3ce2ee3 100644 --- a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py +++ b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py @@ -118,7 +118,15 @@ class PWMOut(object): self._channel = None self._pwmpin = None + def _is_deinited(self): + if self._pwmpin is None: + raise ValueError("Object has been deinitialize and can no longer " + "be used. Create a new object.") + def _write_pin_attr(self, attr, value): + # Make sure the pin is active + self._is_deinited() + path = os.path.join( self._sysfs_path, self._channel_path.format(self._channel), @@ -130,6 +138,9 @@ class PWMOut(object): f_attr.write(value + "\n") def _read_pin_attr(self, attr): + # Make sure the pin is active + self._is_deinited() + path = os.path.join( self._sysfs_path, self._channel_path.format(self._channel), -- 2.49.0