Skip to content

Commit 0ce05da

Browse files
committed
Ensure that the sensor is turned off when program exits.
1 parent 03003e9 commit 0ce05da

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Adafruit_TSL2561/Adafruit_TSL2561.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22

3+
import atexit
34
import time
45
import warnings
56
from Adafruit_I2C import Adafruit_I2C
@@ -151,6 +152,12 @@ class TSL2561(object):
151152
_gain = 1
152153
_integrationTime = _integrationTime(402)
153154

155+
@classmethod
156+
def reset_sensor(cls, address):
157+
Adafruit_I2C(address).write8(
158+
TSL2561._REGISTER['CONTROL'] | TSL2561._REG_MOD['COMMAND'],
159+
TSL2561._CONTROL['OFF'])
160+
154161
def __init__(self, address=ADDR_FLOAT, mode=MODE_CONTINUOUS, gain=_gain, integrationTime=_integrationTime.key, package='T', debug=False):
155162
if mode not in self._MODES:
156163
raise ValueError('Incorrect value passed as operating mode.')
@@ -166,6 +173,7 @@ def __init__(self, address=ADDR_FLOAT, mode=MODE_CONTINUOUS, gain=_gain, integra
166173
self.mode = mode
167174
if self.mode == TSL2561.MODE_CONTINUOUS:
168175
self._poweron()
176+
atexit.register(TSL2561.reset_sensor, address)
169177

170178
self.gain = gain
171179
self.integrationTime = integrationTime

0 commit comments

Comments
 (0)