]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Merge pull request #336 from makermelissa/master 5.3.1
authorLimor "Ladyada" Fried <limor@ladyada.net>
Tue, 25 Aug 2020 23:31:53 +0000 (19:31 -0400)
committerGitHub <noreply@github.com>
Tue, 25 Aug 2020 23:31:53 +0000 (19:31 -0400)
Added missing OneWire as NotImplemented stub

15 files changed:
src/adafruit_blinka/microcontroller/am335x/sysfs_pwmout.py
src/adafruit_blinka/microcontroller/amlogic/meson_g12_common/pin.py
src/adafruit_blinka/microcontroller/bcm283x/pulseio/PulseIn.py
src/adafruit_blinka/microcontroller/generic_linux/i2c.py
src/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py
src/adafruit_blinka/microcontroller/generic_linux/periphery_pin.py
src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogin.py
src/adafruit_blinka/microcontroller/generic_linux/sysfs_analogout.py
src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py
src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py
src/adafruit_blinka/microcontroller/mcp2221/mcp2221.py
src/adafruit_blinka/microcontroller/nova/pwmout.py
src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py
src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py
src/busio.py

index 2ba135927da79d86e24ae76fd758e9fed9383c63..b99e1cc8000ef88293ecb81146fd8e3b49bc6bbf 100644 (file)
@@ -9,7 +9,7 @@ import os
 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):
@@ -105,7 +105,7 @@ class PWMOut:
                 ) 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()
@@ -135,7 +135,9 @@ class PWMOut:
                     ) 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
@@ -192,7 +194,9 @@ class PWMOut:
         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
@@ -230,7 +234,9 @@ class PWMOut:
         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
index 165bca71db19a9a3b4c7340212f4aaf5f7ca5b9d..82fa6ea267b07072b1c629589cdea8b71c8a8ed0 100644 (file)
@@ -9,8 +9,8 @@ Linux kernel 5.4.y (mainline)
 """
 
 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")
index d2390f6fed489d77f040b9735408ef42981d9084..aef942a6c93319a37578bfb503ec07ebb56bbc4a 100644 (file)
@@ -45,7 +45,9 @@ class PulseIn:
                 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 = [
index 1870dfc802eb28206a1bca6c8f3ddbd0fa10d124..7be7514a9426af43188158b0da31bfa423501405 100644 (file)
@@ -25,7 +25,7 @@ class I2C:
         except FileNotFoundError:
             raise RuntimeError(
                 "I2C Bus #%d not found, check if enabled in config!" % bus_num
-            )
+            ) from RuntimeError
 
     # pylint: enable=unused-argument
 
index 4ffa5c1725da19bf4e2d049e02940f7da1e527fd..db9007a6d55d479b4322ed2a67ba2b10804f43a7 100644 (file)
@@ -5,7 +5,7 @@ except ImportError:
     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:
index 69044f84757a26994a360eb45fca1c91c50335a0..0986d0135b11d3407321e24e539df89d44ae5644 100644 (file)
@@ -5,7 +5,7 @@ except ImportError:
     raise ImportError(
         "Periphery Python bindings not found, please install and try again! "
         "Try running 'pip3 install python-periphery'"
-    )
+    ) from ImportError
 
 
 class Pin:
index bf6988be1033b4b7192132722ed22a195f78f0ef..e8a7376c615786a0ea759229a7886d01e947ec45 100644 (file)
@@ -13,7 +13,7 @@ from adafruit_blinka import ContextManaged
 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):
index ec8b6c6ab58ffd7959625cf7f25e04fdd1d31d7f..56263d39555a384178cef873328139438747af36 100644 (file)
@@ -13,7 +13,7 @@ from adafruit_blinka import 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):
index c5b56e69869603a83308da2255d113646688d674..50c27a7b6ca0a3d13bad10b0c413c89cbbc54ba1 100644 (file)
@@ -135,7 +135,7 @@ class Pin:
                 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
@@ -164,7 +164,7 @@ class Pin:
                     ):
                         raise GPIOError(
                             e.errno, "Setting GPIO direction: " + e.strerror
-                        )
+                        ) from IOError
 
                 time.sleep(self.GPIO_OPEN_DELAY)
         else:
@@ -173,13 +173,15 @@ class Pin:
                 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
 
@@ -192,7 +194,7 @@ class Pin:
         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
 
@@ -202,20 +204,20 @@ class Pin:
             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
@@ -235,13 +237,13 @@ class Pin:
             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):
@@ -270,9 +272,13 @@ class Pin:
                 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()
 
@@ -284,7 +290,9 @@ class Pin:
             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()
 
@@ -299,7 +307,9 @@ class Pin:
             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)
 
index 6cf477c15dd63aa1e8422890504d92920d847b6d..4fc8e23b0fab29bdafb563476b3c9bb58e2b7a28 100644 (file)
@@ -9,7 +9,7 @@ import os
 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
@@ -107,7 +107,7 @@ class PWMOut:
             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
 
@@ -136,7 +136,9 @@ class PWMOut:
                 ) 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
@@ -184,7 +186,9 @@ class PWMOut:
         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
@@ -222,7 +226,9 @@ class PWMOut:
         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
index a4a1d990a58ecd8419873c81d2cd4b62403e6a5d..66d406dd902247aa1769cd76cdf4893191f906f1 100644 (file)
@@ -12,7 +12,6 @@ MCP2221_RESET_DELAY = float(os.environ.get("BLINKA_MCP2221_RESET_DELAY", 0.5))
 # 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
@@ -35,7 +34,6 @@ RESP_I2C_WRITINGNOSTOP = 0x45  # ???
 MCP2221_RETRY_MAX = 50
 MCP2221_MAX_I2C_DATA_LEN = 60
 MASK_ADDR_NACK = 0x40
-# pylint: enable=bad-whitespace
 
 
 class MCP2221:
index 413938028eb6335cd849d2713a07b8424c9ab411..2ff0c2594e909c7af5c0e27b21ee90e3e0baf5ed 100644 (file)
@@ -3,7 +3,7 @@
 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
 
index cfa96fe2ccababefb07f1e701a95a584d1842573..24d542dd5770a3a8d11b67f106fbd8f9822b35f3 100644 (file)
@@ -4,11 +4,11 @@ try:
     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:
index 5bb7889d3430f74aff8f13a37f2a6f6da742898d..91c3ede1b12e8902d2c3cc2a8ac3523d1d6b278c 100644 (file)
@@ -5,7 +5,7 @@ from greatfet import GreatFET
 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):
index 279bd46f80ba4910aff9e1518d54c70c482f5cc7..d63c815fbefe2b840186572d4fffea61c9881670 100755 (executable)
@@ -293,7 +293,7 @@ class SPI(Lockable):
         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"""
@@ -412,3 +412,36 @@ class UART(Lockable):
     def write(self, buf):
         """Write to the UART from a buffer"""
         return self._uart.write(buf)
+
+
+class OneWire:
+    """
+    Stub class for OneWire, which is currently not implemented
+    """
+
+    def __init__(self, pin):
+        raise NotImplementedError("OneWire has not been implemented")
+
+    def deinit(self):
+        """
+        Deinitialize the OneWire bus and release any hardware resources for reuse.
+        """
+        raise NotImplementedError("OneWire has not been implemented")
+
+    def reset(self):
+        """
+        Reset the OneWire bus and read presence
+        """
+        raise NotImplementedError("OneWire has not been implemented")
+
+    def read_bit(self):
+        """
+        Read in a bit
+        """
+        raise NotImplementedError("OneWire has not been implemented")
+
+    def write_bit(self, value):
+        """
+        Write out a bit based on value.
+        """
+        raise NotImplementedError("OneWire has not been implemented")