@@ -94,8 +94,8 @@ def __init__(
94
94
data_rate : Optional [int ] = None ,
95
95
mode : int = Mode .SINGLE ,
96
96
comparator_queue_length : int = 0 ,
97
- comparator_low_threshold : Optional [ int ] = None ,
98
- comparator_high_threshold : Optional [ int ] = None ,
97
+ comparator_low_threshold : int = - 32768 ,
98
+ comparator_high_threshold : int = 32767 ,
99
99
address : int = _ADS1X15_DEFAULT_ADDRESS ,
100
100
):
101
101
# pylint: disable=too-many-arguments
@@ -106,16 +106,8 @@ def __init__(
106
106
self .mode = mode
107
107
self .comparator_queue_length = comparator_queue_length
108
108
self .i2c_device = I2CDevice (i2c , address )
109
- self .comparator_low_threshold = (
110
- self ._comp_low_thres_default ()
111
- if comparator_low_threshold is None
112
- else comparator_low_threshold
113
- )
114
- self .comparator_high_threshold = (
115
- self ._comp_high_thres_default ()
116
- if comparator_high_threshold is None
117
- else comparator_high_threshold
118
- )
109
+ self .comparator_low_threshold = comparator_low_threshold
110
+ self .comparator_high_threshold = comparator_high_threshold
119
111
120
112
@property
121
113
def bits (self ) -> int :
@@ -198,23 +190,35 @@ def comparator_high_threshold(self) -> int:
198
190
199
191
@comparator_low_threshold .setter
200
192
def comparator_low_threshold (self , value : int ) -> None :
201
- """Set comparator low threshold value for ADS1015 ADC
193
+ """Set comparator low threshold value for ADS1x15 ADC
202
194
203
195
:param int value: 16-bit signed integer to write to register
204
196
"""
205
- if value < 0 or value > 65535 :
206
- raise ValueError ("Comparator Threshold value must be between 0 and 65535" )
197
+ if value < - 32768 or value > 32767 :
198
+ raise ValueError (
199
+ "Comparator Threshold value must be between -32768 and 32767"
200
+ )
201
+
202
+ if (self .bits == 12 ) & (value & 0x000F > 0 ):
203
+ print ("4 LSBs will be truncated for ADS1015 for 12-bit value" )
204
+
207
205
self ._comparator_low_threshold = value
208
206
self ._write_register (_ADS1X15_POINTER_LO_THRES , self .comparator_low_threshold )
209
207
210
208
@comparator_high_threshold .setter
211
209
def comparator_high_threshold (self , value : int ) -> None :
212
- """Set comparator high threshold value for ADS1015 ADC
210
+ """Set comparator high threshold value for ADS1x15 ADC
213
211
214
212
:param int value: 16-bit signed integer to write to register
215
213
"""
216
- if value < 0 or value > 65535 :
217
- raise ValueError ("Comparator Threshold value must be between 0 and 65535" )
214
+ if value < - 32768 or value > 32767 :
215
+ raise ValueError (
216
+ "Comparator Threshold value must be between -32768 and 32767"
217
+ )
218
+
219
+ if (self .bits == 12 ) & (value & 0x000F > 0 ):
220
+ print ("4 LSBs will be truncated for ADS1015 for 12-bit value" )
221
+
218
222
self ._comparator_high_threshold = value
219
223
self ._write_register (_ADS1X15_POINTER_HI_THRES , self .comparator_high_threshold )
220
224
@@ -244,18 +248,6 @@ def _data_rate_default(self) -> int:
244
248
"""
245
249
raise NotImplementedError ("Subclasses must implement _data_rate_default!" )
246
250
247
- def _comp_low_thres_default (self ) -> int :
248
- """Retrieve the default comparator low threshold for this ADC (in 16-bit signed int).
249
- Should be implemented by subclasses.
250
- """
251
- raise NotImplementedError ("Subclasses must implement _comp_low_thres_default!" )
252
-
253
- def _comp_high_thres_default (self ) -> int :
254
- """Retrieve the default comparator high threshold for this ADC (in 16-bit signed int).
255
- Should be implemented by subclasses.
256
- """
257
- raise NotImplementedError ("Subclasses must implement _comp_high_thres_default!" )
258
-
259
251
def _conversion_value (self , raw_adc : int ) -> int :
260
252
"""Subclasses should override this function that takes the 16 raw ADC
261
253
values of a conversion result and returns a signed integer value.
0 commit comments