File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -196,10 +196,18 @@ def calculateColorTemperature(rgb):
196196 Y = (- 0.32466 * rgb ['r' ]) + (1.57837 * rgb ['g' ]) + (- 0.73191 * rgb ['b' ])
197197 Z = (- 0.68202 * rgb ['r' ]) + (0.77073 * rgb ['g' ]) + ( 0.56332 * rgb ['b' ])
198198
199+ # Check for divide by 0 (total darkness) and return None.
200+ if (x + y + z ) == 0 :
201+ return None
202+
199203 # 2. Calculate the chromaticity co-ordinates
200204 xc = (X ) / (X + Y + Z )
201205 yc = (Y ) / (X + Y + Z )
202206
207+ # Check for divide by 0 again and return None.
208+ if (0.1858 - yc ) == 0 :
209+ return None
210+
203211 # 3. Use McCamy's formula to determine the CCT
204212 n = (xc - 0.3320 ) / (0.1858 - yc )
205213
Original file line number Diff line number Diff line change 1616colorTemp = tcs .calculateColorTemperature (rgb )
1717lux = tcs .calculateLux (rgb )
1818print rgb
19- print "Color Temperature: %d K" % colorTemp
19+ if colorTemp is None :
20+ print 'Too dark to determine color temperature!'
21+ else :
22+ print "Color Temperature: %d K" % colorTemp
2023print "Luminosity: %d lux" % lux
2124tcs .setInterrupt (True )
2225sleep (1 )
You can’t perform that action at this time.
0 commit comments