-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.py
34 lines (25 loc) · 838 Bytes
/
temp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*-coding:utf-8-*-
from mlx90614 import MLX90614
import time
import threading
class TempMonitor(object):
LOOP_TIME = 1.0
def __init__(self, print_result=False):
self.temp = 0
self.print_result = print_result
def run_sensor(self):
sensor = MLX90614()
while not self._thread.stopped:
self.temp = sensor.readObjectTemperature() + 5
if self.print_result:
print("TEMP:{0}".format(self.temp))
time.sleep(self.LOOP_TIME)
sensor.shutdown()
def start_sensor(self):
self._thread = threading.Thread(target=self.run_sensor)
self._thread.stopped = False
self._thread.start()
def stop_sensor(self, timeout=2.0):
self._thread.stopped = True
self.temp = 0
self._thread.join(timeout)