Skip to content

Commit fa592d6

Browse files
author
David Miguel Susano Pinto
committed
RPiValueLogger: check for availability of MCP9808 and TSYS01 classes.
1 parent bcd3d86 commit fa592d6

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

microscope/valuelogger/raspberrypi.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,23 @@
3030
import time
3131
import typing
3232

33-
import Adafruit_MCP9808.MCP9808 as MCP9808
3433

35-
import microscope.abc
34+
try:
35+
from Adafruit_MCP9808 import MCP9808
36+
37+
has_MCP9808 = True
38+
except ModuleNotFoundError:
39+
has_MCP9808 = False
40+
41+
try:
42+
from TSYS01 import TSYS01
3643

44+
has_TSYS01 = True
45+
except ModuleNotFoundError:
46+
has_TSYS01 = False
3747

38-
# library for TSYS01 sensor
39-
# import TSYS01.TSYS01 as TSYS01
48+
49+
import microscope.abc
4050

4151

4252
# Support for async digital IO control on the Raspberryy Pi.
@@ -64,11 +74,19 @@ def __init__(self, sensors=[], **kwargs):
6474
"adding sensor: " + sensor_type + " Adress: %d " % i2c_address
6575
)
6676
if sensor_type == "MCP9808":
77+
if not has_MCP9808:
78+
raise microscope.LibraryLoadError(
79+
"Adafruit_MCP9808 Python package not found"
80+
)
6781
self._sensors.append(MCP9808.MCP9808(address=i2c_address))
6882
# starts the last one added
6983
self._sensors[-1].begin()
7084
print(self._sensors[-1].readTempC())
7185
elif sensor_type == "TSYS01":
86+
if not has_TSYS01:
87+
raise microscope.LibraryLoadError(
88+
"TSYS01 Python package not found"
89+
)
7290
self._sensors.append(TSYS01.TSYS01(address=i2c_address))
7391
print(self._sensors[-1].readTempC())
7492
self.initialize()

0 commit comments

Comments
 (0)