- update
git-svn-id: http://moon:8086/svn/projects/HendiControl@266 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -6,8 +6,8 @@ from matplotlib.pyplot import figure, clf, plot, xlabel, ylabel, xlim, ylim, tit
|
||||
import signal
|
||||
import threading
|
||||
|
||||
from tempSensorSim import TempSensorSim
|
||||
#from max31865 import Max31865
|
||||
#from tempSensorSim import TempSensorSim
|
||||
from max31865 import Max31865
|
||||
|
||||
class TempLogger():
|
||||
def __init__(self, sensor, filename="temp.log"):
|
||||
@@ -15,17 +15,20 @@ class TempLogger():
|
||||
self.sensor = sensor
|
||||
self.temps = np.empty(0)
|
||||
self.times = np.empty(0)
|
||||
self.count = 0
|
||||
self.time = 0
|
||||
|
||||
self.abort = False
|
||||
self.thread = None
|
||||
self.sema = threading.Semaphore(0)
|
||||
|
||||
def start(self, dt, duration):
|
||||
if self.thread == None:
|
||||
self.thread = threading.Thread(target=self.run, args=(dt, duration,))
|
||||
self.thread.start()
|
||||
|
||||
try:
|
||||
if self.thread == None:
|
||||
self.thread = threading.Thread(target=self.run, args=(dt, duration,))
|
||||
self.thread.start()
|
||||
except:
|
||||
self.sema.release()
|
||||
|
||||
def stop(self):
|
||||
if self.thread:
|
||||
self.abort = True
|
||||
@@ -37,13 +40,13 @@ class TempLogger():
|
||||
duration = args[1]
|
||||
|
||||
fp = open(self.filename, 'w')
|
||||
for t in range(0, duration):
|
||||
while self.time < duration:
|
||||
temp = self.sensor.temperature()
|
||||
print ("Current temperature is {:0.2f} °C".format(temp))
|
||||
self.times = np.append(self.times, self.count)
|
||||
self.times = np.append(self.times, self.time)
|
||||
self.temps = np.append(self.temps, temp)
|
||||
fp.write("{:04d} {:0.2f}\n".format(self.count, temp))
|
||||
self.count += 1
|
||||
fp.write("{:0.2f} {:0.2f}\n".format(self.time, temp))
|
||||
self.time += dt
|
||||
time.sleep(dt)
|
||||
if self.abort:
|
||||
break
|
||||
@@ -81,10 +84,10 @@ if __name__ == '__main__':
|
||||
signal.signal(signal.SIGINT, handler)
|
||||
signal.signal(signal.SIGHUP, handler)
|
||||
|
||||
# sensor = Max31865()
|
||||
sensor = TempSensorSim("FakeTemp")
|
||||
sensor = Max31865()
|
||||
# sensor = TempSensorSim("FakeTemp")
|
||||
logger = TempLogger(sensor)
|
||||
logger.start(1.0, 10)
|
||||
logger.start(1.0, 30*60)
|
||||
logger.wait()
|
||||
tempPlot(logger.result())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user