11# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
22# SPDX-FileCopyrightText: Copyright (c) 2022 Carter Nelson for Adafruit Industries
3+ # SPDX-FileCopyrightText: Copyright (c) 2024 Aaron W Morris (aaronwmorris)
34#
45# SPDX-License-Identifier: MIT
56"""
6667_RAM_CHLIST = const (0x01 )
6768
6869
70+ # Gain Parameters
71+ _ALS_VIS_ADC_GAIN = const (0x11 )
72+ _ALS_VIS_ADC_MISC = const (0x12 )
73+ _ALS_IR_ADC_GAIN = const (0x1E )
74+ _ALS_IR_ADC_MISC = const (0x1F )
75+
76+
77+ # Gain technically increases integration time
78+ GAIN_ADC_CLOCK_DIV_1 = const (0x00 )
79+ GAIN_ADC_CLOCK_DIV_2 = const (0x01 )
80+ GAIN_ADC_CLOCK_DIV_4 = const (0x02 )
81+ GAIN_ADC_CLOCK_DIV_8 = const (0x03 )
82+ GAIN_ADC_CLOCK_DIV_16 = const (0x04 )
83+ GAIN_ADC_CLOCK_DIV_32 = const (0x05 )
84+ GAIN_ADC_CLOCK_DIV_64 = const (0x06 )
85+ GAIN_ADC_CLOCK_DIV_128 = const (0x07 )
86+
87+
6988class SI1145 :
7089 """Driver for the SI1145 UV, IR, Visible Light Sensor."""
7190
91+ # pylint: disable=too-many-instance-attributes, maybe-no-member
92+
7293 _device_info = Struct (_PART_ID , "<BBB" )
7394 _ucoeff_0 = Struct (_COEFF_0 , "<B" )
7495 _ucoeff_1 = Struct (_COEFF_1 , "<B" )
@@ -86,6 +107,7 @@ def __init__(self, i2c: I2C, address: int = _DEFAULT_ADDRESS) -> None:
86107 self ._write_register (_HW_KEY , 0x17 )
87108 self ._als_enabled = True
88109 self ._uv_index_enabled = True
110+
89111 self .als_enabled = self ._als_enabled
90112 self .uv_index_enabled = self ._uv_index_enabled
91113
@@ -143,6 +165,80 @@ def uv_index(self) -> float:
143165 self ._send_command (_CMD_ALS_FORCE )
144166 return self ._aux_data [0 ] / 100
145167
168+ @property
169+ def vis_gain (self ) -> int :
170+ """Visible gain value"""
171+ div = self ._param_query (_ALS_VIS_ADC_GAIN )
172+ return div & ~ 0b11111000
173+
174+ @vis_gain .setter
175+ def vis_gain (self , value : int ) -> None :
176+ self ._param_set (_ALS_VIS_ADC_GAIN , value )
177+
178+ @property
179+ def ir_gain (self ) -> int :
180+ """IR gain value"""
181+ div = self ._param_query (_ALS_IR_ADC_GAIN )
182+ return div & ~ 0b11111000
183+
184+ @ir_gain .setter
185+ def ir_gain (self , value : int ) -> None :
186+ self ._param_set (_ALS_IR_ADC_GAIN , value )
187+
188+ @property
189+ def gain (self ) -> Tuple [int , int ]:
190+ """Visble and IR gain values"""
191+ # return both vis and ir gains
192+ return self .vis_gain , self .ir_gain
193+
194+ @gain .setter
195+ def gain (self , value : int ) -> None :
196+ # set both vis and ir gains
197+ self .vis_gain = value
198+ self .ir_gain = value
199+
200+ @property
201+ def als_vis_range_high (self ) -> bool :
202+ """Visible high range value"""
203+ vis_adc_misc = self ._param_query (_ALS_VIS_ADC_MISC )
204+ return bool ((vis_adc_misc & ~ 0b11011111 ) >> 5 )
205+
206+ @als_vis_range_high .setter
207+ def als_vis_range_high (self , enable : bool ) -> None :
208+ vis_adc_misc = self ._param_query (_ALS_VIS_ADC_MISC )
209+ if enable :
210+ vis_adc_misc |= 0b00100000
211+ else :
212+ vis_adc_misc &= ~ 0b00100000
213+ self ._param_set (_ALS_VIS_ADC_MISC , vis_adc_misc )
214+
215+ @property
216+ def als_ir_range_high (self ) -> bool :
217+ """IR high range value"""
218+ ir_adc_misc = self ._param_query (_ALS_IR_ADC_MISC )
219+ return bool ((ir_adc_misc & ~ 0b11011111 ) >> 5 )
220+
221+ @als_ir_range_high .setter
222+ def als_ir_range_high (self , enable : bool ) -> None :
223+ ir_adc_misc = self ._param_query (_ALS_IR_ADC_MISC )
224+ if enable :
225+ ir_adc_misc |= 0b00100000
226+ else :
227+ ir_adc_misc &= ~ 0b00100000
228+ self ._param_set (_ALS_IR_ADC_MISC , ir_adc_misc )
229+
230+ @property
231+ def als_range_high (self ) -> Tuple [bool , bool ]:
232+ """Visbile and IR high range values"""
233+ # return both vis and ir range
234+ return self ._als_vis_range_high , self ._als_ir_range_high
235+
236+ @als_range_high .setter
237+ def als_range_high (self , enable : bool ) -> None :
238+ # set both vis and ir ranges
239+ self .als_vis_range_high = enable
240+ self .als_ir_range_high = enable
241+
146242 def reset (self ) -> None :
147243 """Perform a software reset of the firmware."""
148244 self ._send_command (_CMD_RESET )
0 commit comments