]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py
add '_is_deinited()' to guard against reads/writes on an inactive pin.
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / generic_linux / sysfs_pwmout.py
index e7d64a0ab066510d6dbe406dc30c0b3a8476847d..3ce2ee3a195f2f1f3b26fb35b2af5976c9905bf6 100644 (file)
@@ -118,7 +118,15 @@ class PWMOut(object):
         self._channel = None
         self._pwmpin = None
 
         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):
     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),
         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):
             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),
         path = os.path.join(
             self._sysfs_path,
             self._channel_path.format(self._channel),