Add some smoothing

master
James Gao 2014-11-29 20:58:58 -08:00
rodzic 4230a71665
commit a951660d01
1 zmienionych plików z 12 dodań i 4 usunięć

Wyświetl plik

@ -77,18 +77,26 @@ class Simulate(object):
return tempsample(self.last, sum(self.history) / float(len(self.history)))
class Breakout(object):
def __init__(self, addr):
def __init__(self, addr, smooth_window=16):
import breakout
self.device = breakout.Breakout(addr)
self.history = deque(smooth_window)
self.last = None
def get(self):
time.sleep(.25)
temp = self.device.temperature if not isnan(self.device.temperature) else -1
return tempsample(time.time(), temp)
temp = self.device.temperature
self.last = time.time()
if not isnan(temp):
self.history.append(temp)
return self.temperature
@property
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):
def __init__(self, cls=MAX31850, **kwargs):