@@ -170,11 +170,21 @@ def _set_thermocouple_type(self, thermocouple_type: ThermocoupleType):
170
170
conf_reg_1 |= int (thermocouple_type ) & 0x0F
171
171
self ._write_u8 (_MAX31856_CR1_REG , conf_reg_1 )
172
172
173
- def set_sampling ( self , num_samples : int ):
174
- """
175
- Sets the number of samples averaged by the sensor in each reading .
176
- :param int num_samples: number of samples ( 1, 2, 4, 8 or 16).
173
+ @ property
174
+ def averaging ( self ) -> int :
175
+ """Number of samples averaged together in each result .
176
+ Must be 1, 2, 4, 8, or 16. Default is 1 (no averaging ).
177
177
"""
178
+ conf_reg_1 = self ._read_register (_MAX31856_CR1_REG , 1 )[0 ]
179
+ avgsel = conf_reg_1 & ~ 0b10001111 # clear bits other than 4-6
180
+ # check which byte this corresponds to
181
+ for key , value in _AVGSEL_CONSTS .items ():
182
+ if value == avgsel :
183
+ return key
184
+ raise KeyError (f"AVGSEL bit pattern was not recognised ({ avgsel :>08b} )" )
185
+
186
+ @averaging .setter
187
+ def averaging (self , num_samples : int ):
178
188
# This option is set in bits 4-6 of register CR1.
179
189
if num_samples not in _AVGSEL_CONSTS :
180
190
raise ValueError ("Num_samples must be one of 1,2,4,8,16" )
@@ -186,14 +196,19 @@ def set_sampling(self, num_samples: int):
186
196
conf_reg_1 |= avgsel
187
197
self ._write_u8 (_MAX31856_CR1_REG , conf_reg_1 )
188
198
189
- def select_mains_filtering (self , frequency : int = 60 ):
199
+ @property
200
+ def noise_rejection (self ) -> int :
190
201
"""
191
- Select mains filtering frequency (50/60Hz).
192
- Note that filtering is always enabled, and set to 60Hz by default.
193
- Use this function to instead filter 50Hz in 50Hz localities.
194
- :param int frequency: mains frequency (must be either 50 or 60)"""
202
+ The frequency (Hz) to be used by the noise rejection filter.
203
+ Must be 50 or 60. Default is 60."""
195
204
# this value is stored in bit 0 of register CR0.
196
- # get current value of CR0 Reg
205
+ conf_reg_0 = self ._read_register (_MAX31856_CR0_REG , 1 )[0 ]
206
+ if conf_reg_0 & _MAX31856_CR0_50HZ :
207
+ return 50
208
+ return 60
209
+
210
+ @noise_rejection .setter
211
+ def noise_rejection (self , frequency : int ):
197
212
conf_reg_0 = self ._read_register (_MAX31856_CR0_REG , 1 )[0 ]
198
213
if frequency == 50 :
199
214
conf_reg_0 |= _MAX31856_CR0_50HZ # set the 50hz bit
0 commit comments