From: sommersoft Date: Mon, 3 Jun 2019 21:05:11 +0000 (-0500) Subject: add '_is_deinited()' to guard against reads/writes on an inactive pin. X-Git-Tag: 1.3.4^2~1 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/f24cd41e8d3dd8bd9e752fc450fff2d01afe1092 add '_is_deinited()' to guard against reads/writes on an inactive pin. --- 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),