File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -249,9 +249,22 @@ def lux(self):
249
249
"""
250
250
(chan0 , chan1 ) = self ._getData ()
251
251
252
- chscale = self ._integrationTime .scale * self .gain
253
- schan0 = chan0 / chscale
254
- schan1 = chan1 / chscale
252
+ # The channel readings are pretty raw numbers. Given a steady light
253
+ # source, a (hypothetical) 10ms integration time would give a raw
254
+ # reading that was ten times higher than a 1ms integration time.
255
+ # Similarly, if the sensor is operating at 16x gain, the raw readings
256
+ # will by 16 times higher than a 1x gain.
257
+ #
258
+ # The calculations in the datasheet are based on a 402ms integration
259
+ # time and a 16x gain. If those aren't the parameters that were used
260
+ # for this reading, we need to scale the raw numbers to their 402ms/16x
261
+ # equivalents for purposes of doing the calculation. That's what the
262
+ # `chscale` variable accomplishes. The integration time scaling is
263
+ # precomputed. The gain scaling is simply based on the current gain
264
+ # relative the the 16x reference.
265
+ chscale = self ._integrationTime .scale * (16.0 / self .gain )
266
+ schan0 = chan0 * chscale
267
+ schan1 = chan1 * chscale
255
268
256
269
if schan0 != 0 :
257
270
ratio = schan1 / schan0
You can’t perform that action at this time.
0 commit comments