From de258bc1adb87e9a5a2dc0fd4a60af95ad769d2e Mon Sep 17 00:00:00 2001 From: Ben Nuttall Date: Thu, 26 May 2016 23:21:29 +0100 Subject: [PATCH] Add max_voltage property, ensure it is positive and cast to a float --- gpiozero/spi_devices.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gpiozero/spi_devices.py b/gpiozero/spi_devices.py index 60d9fa0..d109007 100644 --- a/gpiozero/spi_devices.py +++ b/gpiozero/spi_devices.py @@ -76,8 +76,10 @@ class AnalogInputDevice(SPIDevice): if bits is None: raise InputDeviceError('you must specify the bit resolution of the device') self._bits = bits + if max_voltage <= 0: + raise InputDeviceError('max_voltage must be positive') + self._max_voltage = float(max_voltage) super(AnalogInputDevice, self).__init__(shared=True, **spi_args) - self._max_voltage = max_voltage @property def bits(self): @@ -104,6 +106,13 @@ class AnalogInputDevice(SPIDevice): """ return self._read() + @property + def max_voltage(self): + """ + The voltage required to set the device's value to 1 + """ + return self._max_voltage + @property def voltage(self): """