Skip to content

Commit

Permalink
Merge pull request #2 from flyte/develop
Browse files Browse the repository at this point in the history
Update ads1x15.py (flyte#329)
  • Loading branch information
Bluscream committed Jan 13, 2024
2 parents e38300b + 390cc52 commit 05955d8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions mqtt_io/modules/sensor/ads1x15.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
ADS1x15 analog to digital converters
"""
import threading

from typing import cast

from ...types import CerberusSchemaType, ConfigType, SensorValueType
Expand Down Expand Up @@ -78,15 +80,21 @@ def setup_module(self) -> None:
# Create single-ended input for each pin in config
self.channels = {pin: AnalogIn(self.ads, pin) for pin in self.config["pins"]}

# initialize mutex lock
self.lock = threading.Lock()

def get_value(self, sens_conf: ConfigType) -> SensorValueType:
"""
Get the value or voltage from the sensor
"""
sens_type = sens_conf["type"]
data = dict(
value=self.channels[sens_conf["pin"]].value,
voltage=self.channels[sens_conf["pin"]].voltage,
)
# acquire the lock
with self.lock:
sens_type = sens_conf["type"]
data = dict(
value=self.channels[sens_conf["pin"]].value,
voltage=self.channels[sens_conf["pin"]].voltage,
)

return cast(
float,
data[sens_type],
Expand Down

0 comments on commit 05955d8

Please sign in to comment.