Skip to content

Commit

Permalink
feeback Comments on library.
Browse files Browse the repository at this point in the history
  • Loading branch information
jposada202020 committed Apr 12, 2023
1 parent a9c0675 commit 719aebd
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions adafruit_tmp117.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def initialize(self):
def temperature(self):
"""The current measured temperature in degrees Celsius"""

return self._read_temperature()
return self._raw_temperature * _TMP117_RESOLUTION

@property
def temperature_offset(self):
Expand Down Expand Up @@ -260,6 +260,17 @@ def averaged_measurements(self):
tmp117 = adafruit_tmp117.TMP117(i2c)
In order to print information in a nicer way we create a dictionary with the
sensor information for the averaged measurements.
.. code-block::python3
Average_Measure = {1: "AVERAGE_1X", 2: "AVERAGE_8X", 3: "AVERAGE_32X", 4: "AVERAGE_64X"}
We print the information for the Temperature sensor
.. code-block::python3
# uncomment different options below to see how it affects the reported temperature
# tmp117.averaged_measurements = adafruit_tmp117.AVERAGE_1X
# tmp117.averaged_measurements = adafruit_tmp117.AVERAGE_8X
Expand All @@ -268,7 +279,7 @@ def averaged_measurements(self):
print(
"Number of averaged samples per measurement:",
tmp117.averaged_measurements,
Average_Measure[tmp117.averaged_measurements],
)
print("")
Expand All @@ -282,7 +293,7 @@ def averaged_measurements(self):
@averaged_measurements.setter
def averaged_measurements(self, value: int):
if value not in [0, 1, 2, 3]:
raise ValueError("averaged_measurements must be 0, 1, 2 or 3")
raise ValueError("averaged_measurements must be set to 0, 1, 2 or 3")
self._raw_averaged_measurements = value

@property
Expand Down Expand Up @@ -349,6 +360,26 @@ def measurement_delay(self):
tmp117 = adafruit_tmp117.TMP117(i2c)
In order to print information in a nicer way, we create a dictionary with the
sensor information for the measurement delay.
.. code-block::python3
Delay_times = {
0: "DELAY_0_0015_S",
1: "DELAY_0_125_S",
2: "DELAY_0_250_S",
3: "DELAY_0_500_S",
4: "DELAY_1_S",
5: "DELAY_4_S",
6: "DELAY_8_S",
7: "DELAY_16_S",
}
We print the information for the Temperature sensor
.. code-block::python3
# uncomment different options below to see how it affects the reported temperature
# tmp117.measurement_delay = adafruit_tmp117.DELAY_0_0015_S
Expand All @@ -361,7 +392,7 @@ def measurement_delay(self):
# tmp117.measurement_delay = adafruit_tmp117.DELAY_16_S
print("Minimum time between measurements:",
tmp117.measurement_delay)
Delay_times[tmp117.measurement_delay])
print("")
Expand All @@ -375,6 +406,10 @@ def measurement_delay(self):

@measurement_delay.setter
def measurement_delay(self, value: int) -> None:
if value not in [0, 1, 2, 3, 4, 5, 6, 7]:
raise ValueError(
"averaged_measurements must be set to 0, 1, 2, 3, 4, 5, 6, 7"
)
self._raw_measurement_delay = value

def take_single_measurement(self) -> float:
Expand Down Expand Up @@ -416,7 +451,7 @@ def alert_mode(self, value: Literal[ALERT_WINDOW, ALERT_HYSTERESIS]):
"""
if value not in [0, 1]:
raise ValueError("alert_mode must be an 0 or 1")
raise ValueError("alert_mode must be set to 0 or 1")
self._raw_alert_mode = value

@property
Expand Down Expand Up @@ -451,7 +486,7 @@ def _set_mode_and_wait_for_measurement(self, mode: int) -> float:
while not self._read_status()[2]:
time.sleep(0.001)

return self._read_temperature()
return self._raw_temperature * _TMP117_RESOLUTION

# eeprom write enable to set defaults for limits and config
# requires context manager or something to perform a general call reset
Expand All @@ -466,9 +501,6 @@ def _read_status(self) -> Tuple[int, int, int]:

return (high_alert, low_alert, data_ready)

def _read_temperature(self) -> float:
return self._raw_temperature * _TMP117_RESOLUTION

# pylint: disable=no-self-use
@staticmethod
def _scaled_limit(value: float) -> int:
Expand Down

0 comments on commit 719aebd

Please sign in to comment.