kopia lustrzana https://github.com/jamesgao/kiln_controller
Add some smoothing
rodzic
4230a71665
commit
a951660d01
|
@ -77,18 +77,26 @@ class Simulate(object):
|
||||||
return tempsample(self.last, sum(self.history) / float(len(self.history)))
|
return tempsample(self.last, sum(self.history) / float(len(self.history)))
|
||||||
|
|
||||||
class Breakout(object):
|
class Breakout(object):
|
||||||
def __init__(self, addr):
|
def __init__(self, addr, smooth_window=16):
|
||||||
import breakout
|
import breakout
|
||||||
self.device = breakout.Breakout(addr)
|
self.device = breakout.Breakout(addr)
|
||||||
|
self.history = deque(smooth_window)
|
||||||
|
self.last = None
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
time.sleep(.25)
|
time.sleep(.25)
|
||||||
temp = self.device.temperature if not isnan(self.device.temperature) else -1
|
temp = self.device.temperature
|
||||||
return tempsample(time.time(), temp)
|
self.last = time.time()
|
||||||
|
if not isnan(temp):
|
||||||
|
self.history.append(temp)
|
||||||
|
return self.temperature
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self):
|
def temperature(self):
|
||||||
return self.device.temperature if not isnan(self.device.temperature) else -1
|
if self.last is None or time.time() - self.last > 5:
|
||||||
|
return self.get()
|
||||||
|
|
||||||
|
return tempsample(self.last, sum(self.history) / float(len(self.history)))
|
||||||
|
|
||||||
class Monitor(threading.Thread):
|
class Monitor(threading.Thread):
|
||||||
def __init__(self, cls=MAX31850, **kwargs):
|
def __init__(self, cls=MAX31850, **kwargs):
|
||||||
|
|
Ładowanie…
Reference in New Issue