Skip to content

Commit dd7a0ab

Browse files
committed
moving measurement_delay and measure average to properties.
1 parent 719aebd commit dd7a0ab

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed

adafruit_tmp117.py

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,6 @@ def averaged_measurements(self):
260260
261261
tmp117 = adafruit_tmp117.TMP117(i2c)
262262
263-
In order to print information in a nicer way we create a dictionary with the
264-
sensor information for the averaged measurements.
265-
266-
.. code-block::python3
267-
268-
Average_Measure = {1: "AVERAGE_1X", 2: "AVERAGE_8X", 3: "AVERAGE_32X", 4: "AVERAGE_64X"}
269-
270-
We print the information for the Temperature sensor
271-
272-
.. code-block::python3
273-
274263
# uncomment different options below to see how it affects the reported temperature
275264
# tmp117.averaged_measurements = adafruit_tmp117.AVERAGE_1X
276265
# tmp117.averaged_measurements = adafruit_tmp117.AVERAGE_8X
@@ -279,7 +268,7 @@ def averaged_measurements(self):
279268
280269
print(
281270
"Number of averaged samples per measurement:",
282-
Average_Measure[tmp117.averaged_measurements],
271+
tmp117.averaged_measurements,
283272
)
284273
print("")
285274
@@ -288,7 +277,15 @@ def averaged_measurements(self):
288277
time.sleep(0.1)
289278
290279
"""
291-
return self._raw_averaged_measurements
280+
281+
average_measure = {
282+
1: "AVERAGE_1X",
283+
2: "AVERAGE_8X",
284+
3: "AVERAGE_32X",
285+
4: "AVERAGE_64X",
286+
}
287+
288+
return average_measure[self._raw_averaged_measurements]
292289

293290
@averaged_measurements.setter
294291
def averaged_measurements(self, value: int):
@@ -360,25 +357,6 @@ def measurement_delay(self):
360357
361358
tmp117 = adafruit_tmp117.TMP117(i2c)
362359
363-
In order to print information in a nicer way, we create a dictionary with the
364-
sensor information for the measurement delay.
365-
366-
.. code-block::python3
367-
368-
Delay_times = {
369-
0: "DELAY_0_0015_S",
370-
1: "DELAY_0_125_S",
371-
2: "DELAY_0_250_S",
372-
3: "DELAY_0_500_S",
373-
4: "DELAY_1_S",
374-
5: "DELAY_4_S",
375-
6: "DELAY_8_S",
376-
7: "DELAY_16_S",
377-
}
378-
379-
We print the information for the Temperature sensor
380-
381-
.. code-block::python3
382360
383361
# uncomment different options below to see how it affects the reported temperature
384362
@@ -392,7 +370,7 @@ def measurement_delay(self):
392370
# tmp117.measurement_delay = adafruit_tmp117.DELAY_16_S
393371
394372
print("Minimum time between measurements:",
395-
Delay_times[tmp117.measurement_delay])
373+
tmp117.measurement_delay)
396374
397375
print("")
398376
@@ -402,7 +380,18 @@ def measurement_delay(self):
402380
403381
"""
404382

405-
return self._raw_measurement_delay
383+
delay_times = {
384+
0: "DELAY_0_0015_S",
385+
1: "DELAY_0_125_S",
386+
2: "DELAY_0_250_S",
387+
3: "DELAY_0_500_S",
388+
4: "DELAY_1_S",
389+
5: "DELAY_4_S",
390+
6: "DELAY_8_S",
391+
7: "DELAY_16_S",
392+
}
393+
394+
return delay_times[self._raw_measurement_delay]
406395

407396
@measurement_delay.setter
408397
def measurement_delay(self, value: int) -> None:

examples/tmp117_rate_and_averaging_test.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515
tmp117 = adafruit_tmp117.TMP117(i2c)
1616

1717

18-
# Values here for the average_measurements and measurement_delay
19-
Delay_times = {
20-
0: "DELAY_0_0015_S",
21-
1: "DELAY_0_125_S",
22-
2: "DELAY_0_250_S",
23-
3: "DELAY_0_500_S",
24-
4: "DELAY_1_S",
25-
5: "DELAY_4_S",
26-
6: "DELAY_8_S",
27-
7: "DELAY_16_S",
28-
}
29-
Average_Measure = {1: "AVERAGE_1X", 2: "AVERAGE_8X", 3: "AVERAGE_32X", 4: "AVERAGE_64X"}
30-
3118
# uncomment different options below to see how it affects the reported temperature
3219
# tmp117.averaged_measurements = adafruit_tmp117.AVERAGE_1X
3320
# tmp117.averaged_measurements = adafruit_tmp117.AVERAGE_8X
@@ -45,9 +32,9 @@
4532

4633
print(
4734
"Number of averaged samples per measurement:",
48-
Average_Measure[tmp117.averaged_measurements],
35+
tmp117.averaged_measurements,
4936
)
50-
print("Minimum time between measurements:", Delay_times[tmp117.measurement_delay])
37+
print("Minimum time between measurements:", tmp117.measurement_delay)
5138
print("")
5239

5340
while True:

examples/tmp117_single_measurement_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
print(
2323
"Number of averaged samples per measurement:",
24-
Average_Measure[tmp117.averaged_measurements],
24+
tmp117.averaged_measurements,
2525
)
2626

2727
while True:

0 commit comments

Comments
 (0)