@@ -84,20 +84,17 @@ class TMP007:
84
84
85
85
86
86
87
- def __init__ (self , i2c , address = _TMP007_I2CADDR ):
87
+ def __init__ (self , i2c , address = _TMP007_I2CADDR , samplerate = CFG_16SAMPLE ):
88
88
"""Initialize TMP007 device on the specified I2C address and bus number.
89
89
Address defaults to 0x40 and bus number defaults to the appropriate bus
90
90
for the hardware.
91
- """
92
- self ._device = I2CDevice (i2c , address )
93
-
94
- def begin (self , samplerate = CFG_16SAMPLE ):
95
- """Start taking temperature measurements. Samplerate can be one of
91
+ Start taking temperature measurements. Samplerate can be one of
96
92
TMP007_CFG_1SAMPLE, TMP007_CFG_2SAMPLE, TMP007_CFG_4SAMPLE,
97
93
TMP007_CFG_8SAMPLE, or TMP007_CFG_16SAMPLE. The default is 16 samples
98
94
for the highest resolution. Returns True if the device is intialized,
99
95
False otherwise.
100
96
"""
97
+ self ._device = I2CDevice (i2c , address )
101
98
self ._write_u16 (_TMP007_CONFIG , _TMP007_CFG_RESET )
102
99
time .sleep (.5 )
103
100
if samplerate not in (CFG_1SAMPLE , CFG_2SAMPLE , CFG_4SAMPLE , CFG_8SAMPLE ,
@@ -109,10 +106,11 @@ def begin(self, samplerate=CFG_16SAMPLE):
109
106
config = _TMP007_CFG_MODEON | _TMP007_CFG_DRDYEN | samplerate
110
107
self ._write_u16 (_TMP007_CONFIG , config )
111
108
# Check device ID match expected value.
112
- return self .read_register (_TMP007_DEVID ) == 0x0078
113
-
114
-
109
+ dev_id = self .read_register (_TMP007_DEVID )
110
+ if dev_id != 0x78 :
111
+ raise ValueError ( 'Init failed - Did not find TMP007' )
115
112
113
+ @property
116
114
def sleep (self ):
117
115
"""Put TMP007 into low power sleep mode. No measurement data will be
118
116
updated while in sleep mode.
@@ -121,13 +119,15 @@ def sleep(self):
121
119
control &= ~ (_TMP007_CFG_MODEON )
122
120
self ._write_u16 (_TMP007_CONFIG , control )
123
121
122
+ @property
124
123
def wake (self ):
125
124
"""Wake up TMP007 from low power sleep mode."""
126
125
control = self ._read_u16 (_TMP007_CONFIG )
127
126
control |= _TMP007_CFG_MODEON
128
127
self ._write_u16 (_TMP007_CONFIG , control )
129
128
130
- def read_raw_voltage (self ):
129
+ @property
130
+ def raw_voltage (self ):
131
131
"""Read raw voltage from TMP007 sensor. Meant to be used in the
132
132
calculation of temperature values.
133
133
"""
@@ -136,19 +136,22 @@ def read_raw_voltage(self):
136
136
raw = (raw & 0x7fff ) - 32768
137
137
return raw
138
138
139
- def read_raw_die_temperature (self ):
139
+ @property
140
+ def raw_sensor_temperature (self ):
140
141
"""Read raw die temperature from TMP007 sensor. Meant to be used in the
141
142
calculation of temperature values.
142
143
"""
143
144
raw = self ._read_u16 (_TMP007_TAMB )
144
145
return raw >> 2
145
146
146
- def read_die_temp_c (self ):
147
+ @property
148
+ def die_temperature (self ):
147
149
"""Read sensor die temperature and return its value in degrees celsius."""
148
- t_die = self .read_raw_die_temperature ()
150
+ t_die = self .raw_sensor_temperature
149
151
return t_die * 0.03125
150
152
151
- def read_obj_temp_c (self ):
153
+ @property
154
+ def temperature (self ):
152
155
"""Read object temperature from TMP007 sensor.
153
156
"""
154
157
raw = self ._read_u16 (_TMP007_TOBJ )
0 commit comments