@@ -93,12 +93,16 @@ def add_values(cls, value_tuples):
93
93
"""Add CV values to the class"""
94
94
cls .string = {}
95
95
cls .lsb = {}
96
+ cls .factor = {} # Scale or bit resolution factor
97
+ cls .integration = {} # Lux data integration factor
96
98
97
99
for value_tuple in value_tuples :
98
- name , value , string , lsb = value_tuple
100
+ name , value , string , lsb , factor , integration = value_tuple
99
101
setattr (cls , name , value )
100
102
cls .string [value ] = string
101
103
cls .lsb [value ] = lsb
104
+ cls .factor [value ] = factor
105
+ cls .integration [value ] = integration
102
106
103
107
@classmethod
104
108
def is_valid (cls , value ):
@@ -128,11 +132,11 @@ class Gain(CV):
128
132
129
133
Gain .add_values (
130
134
(
131
- ("GAIN_1X" , 0 , "1X" , None ),
132
- ("GAIN_3X" , 1 , "3X" , None ),
133
- ("GAIN_6X" , 2 , "6X" , None ),
134
- ("GAIN_9X" , 3 , "9X" , None ),
135
- ("GAIN_18X" , 4 , "18X" , None ),
135
+ ("GAIN_1X" , 0 , "1X" , None , 1 , None ),
136
+ ("GAIN_3X" , 1 , "3X" , None , 3 , None ),
137
+ ("GAIN_6X" , 2 , "6X" , None , 6 , None ),
138
+ ("GAIN_9X" , 3 , "9X" , None , 9 , None ),
139
+ ("GAIN_18X" , 4 , "18X" , None , 18 , None ),
136
140
)
137
141
)
138
142
@@ -161,12 +165,12 @@ class Resolution(CV):
161
165
162
166
Resolution .add_values (
163
167
(
164
- ("RESOLUTION_20BIT" , 0 , "20 bits" , None ),
165
- ("RESOLUTION_19BIT" , 1 , "19 bits" , None ),
166
- ("RESOLUTION_18BIT" , 2 , "18 bits" , None ),
167
- ("RESOLUTION_17BIT" , 3 , "17 bits" , None ),
168
- ("RESOLUTION_16BIT" , 4 , "16 bits" , None ),
169
- ("RESOLUTION_13BIT" , 5 , "13 bits" , None ),
168
+ ("RESOLUTION_20BIT" , 0 , "20 bits" , None , 20 , 4.0 ),
169
+ ("RESOLUTION_19BIT" , 1 , "19 bits" , None , 19 , 2.0 ),
170
+ ("RESOLUTION_18BIT" , 2 , "18 bits" , None , 18 , 1.0 ),
171
+ ("RESOLUTION_17BIT" , 3 , "17 bits" , None , 17 , 0.5 ),
172
+ ("RESOLUTION_16BIT" , 4 , "16 bits" , None , 16 , 0.25 ),
173
+ ("RESOLUTION_13BIT" , 5 , "13 bits" , None , 13 , 0.03125 ),
170
174
)
171
175
)
172
176
@@ -197,13 +201,13 @@ class MeasurementDelay(CV):
197
201
198
202
MeasurementDelay .add_values (
199
203
(
200
- ("DELAY_25MS" , 0 , "25" , None ),
201
- ("DELAY_50MS" , 1 , "50" , None ),
202
- ("DELAY_100MS" , 2 , "100" , None ),
203
- ("DELAY_200MS" , 3 , "200" , None ),
204
- ("DELAY_500MS" , 4 , "500" , None ),
205
- ("DELAY_1000MS" , 5 , "1000" , None ),
206
- ("DELAY_2000MS" , 6 , "2000" , None ),
204
+ ("DELAY_25MS" , 0 , "25" , None , 25 , None ),
205
+ ("DELAY_50MS" , 1 , "50" , None , 50 , None ),
206
+ ("DELAY_100MS" , 2 , "100" , None , 100 , None ),
207
+ ("DELAY_200MS" , 3 , "200" , None , 200 , None ),
208
+ ("DELAY_500MS" , 4 , "500" , None , 500 , None ),
209
+ ("DELAY_1000MS" , 5 , "1000" , None , 1000 , None ),
210
+ ("DELAY_2000MS" , 6 , "2000" , None , 2000 , None ),
207
211
)
208
212
)
209
213
@@ -260,6 +264,7 @@ def initialize(self):
260
264
self ._mode = UV
261
265
self .gain = Gain .GAIN_3X # pylint:disable=no-member
262
266
self .resolution = Resolution .RESOLUTION_16BIT # pylint:disable=no-member
267
+ self ._window_factor = 1 # default window transmission factor
263
268
264
269
# ltr.setThresholds(100, 1000);
265
270
# self.low_threshold = 100
@@ -331,7 +336,7 @@ def resolution(self, value):
331
336
self ._resolution_bits = value
332
337
333
338
def enable_alerts (self , enable , source , persistance ):
334
- """The configuraiton of alerts raised by the sensor
339
+ """The configuration of alerts raised by the sensor
335
340
336
341
:param enable: Whether the interrupt output is enabled
337
342
:param source: Whether to use the ALS or UVS data register to compare
@@ -351,11 +356,49 @@ def enable_alerts(self, enable, source, persistance):
351
356
@property
352
357
def measurement_delay (self ):
353
358
"""The delay between measurements. This can be used to set the measurement rate which
354
- affects the sensors power usage."""
359
+ affects the sensor power usage."""
355
360
return self ._measurement_delay_bits
356
361
357
362
@measurement_delay .setter
358
363
def measurement_delay (self , value ):
359
364
if not MeasurementDelay .is_valid (value ):
360
365
raise AttributeError ("measurement_delay must be a MeasurementDelay" )
361
366
self ._measurement_delay_bits = value
367
+
368
+ @property
369
+ def uvi (self ):
370
+ """Read UV count and return calculated UV Index (UVI) value based upon the rated sensitivity
371
+ of 1 UVI per 2300 counts at 18X gain factor and 20-bit resolution."""
372
+ return (
373
+ self .uvs
374
+ / (
375
+ (Gain .factor [self .gain ] / 18 )
376
+ * (2 ** Resolution .factor [self .resolution ])
377
+ / (2 ** 20 )
378
+ * 2300
379
+ )
380
+ * self ._window_factor
381
+ )
382
+
383
+ @property
384
+ def lux (self ):
385
+ """Read light level and return calculated Lux value."""
386
+ return (
387
+ (self .light * 0.6 )
388
+ / (Gain .factor [self .gain ] * Resolution .integration [self .resolution ])
389
+ ) * self ._window_factor
390
+
391
+ @property
392
+ def window_factor (self ):
393
+ """Window transmission factor (Wfac) for UVI and Lux calculations.
394
+ A factor of 1 (default) represents no window or clear glass; > 1 for a tinted window.
395
+ Factor of > 1 requires an emperical calibration with a reference light source."""
396
+ return self ._window_factor
397
+
398
+ @window_factor .setter
399
+ def window_factor (self , factor = 1 ):
400
+ if factor < 1 :
401
+ raise ValueError (
402
+ "window transmission factor must be a value of 1.0 or greater"
403
+ )
404
+ self ._window_factor = factor
0 commit comments