mirror of
https://github.com/pimoroni/grow-python
synced 2025-10-25 15:19:23 +00:00
Add support for history
This commit is contained in:
@@ -30,6 +30,8 @@ class Moisture(object):
|
|||||||
|
|
||||||
self._count = 0
|
self._count = 0
|
||||||
self._reading = 0
|
self._reading = 0
|
||||||
|
self._history = []
|
||||||
|
self._history_length = 200
|
||||||
self._last_pulse = time.time()
|
self._last_pulse = time.time()
|
||||||
self._new_data = False
|
self._new_data = False
|
||||||
self._wet_point = wet_point if wet_point is not None else 0.7
|
self._wet_point = wet_point if wet_point is not None else 0.7
|
||||||
@@ -56,10 +58,23 @@ dtoverlay=spi0-cs,cs0_pin=14 # Re-assign CS0 from BCM 8 so that Grow can use it
|
|||||||
self._last_pulse = time.time()
|
self._last_pulse = time.time()
|
||||||
if self._time_elapsed >= 1.0:
|
if self._time_elapsed >= 1.0:
|
||||||
self._reading = self._count / self._time_elapsed
|
self._reading = self._count / self._time_elapsed
|
||||||
|
self._history.insert(0, self._reading)
|
||||||
|
self._history = self._history[:self._history_length]
|
||||||
self._count = 0
|
self._count = 0
|
||||||
self._time_last_reading = time.time()
|
self._time_last_reading = time.time()
|
||||||
self._new_data = True
|
self._new_data = True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def history(self):
|
||||||
|
history = []
|
||||||
|
|
||||||
|
for moisture in self._history:
|
||||||
|
saturation = float(moisture - self._dry_point) / self.range
|
||||||
|
saturation = round(saturation, 3)
|
||||||
|
history.append(max(0.0, min(1.0, saturation)))
|
||||||
|
|
||||||
|
return history
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _time_elapsed(self):
|
def _time_elapsed(self):
|
||||||
return time.time() - self._time_last_reading
|
return time.time() - self._time_last_reading
|
||||||
|
|||||||
Reference in New Issue
Block a user