mirror of
https://github.com/pimoroni/grow-python
synced 2025-10-25 15:19:23 +00:00
Improve moisture sensor active detection
This commit is contained in:
@@ -30,6 +30,7 @@ class Moisture(object):
|
|||||||
|
|
||||||
self._count = 0
|
self._count = 0
|
||||||
self._reading = 0
|
self._reading = 0
|
||||||
|
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
|
||||||
self._dry_point = dry_point if dry_point is not None else 27.6
|
self._dry_point = dry_point if dry_point is not None else 27.6
|
||||||
@@ -49,12 +50,10 @@ dtoverlay=spi0-cs,cs0_pin=14 # Re-assign CS0 from BCM 8 so that Grow can use it
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
self._time_start = time.time()
|
self._time_start = time.time()
|
||||||
self._total_count = 0
|
|
||||||
self._minimum_hz = 5
|
|
||||||
|
|
||||||
def _event_handler(self, pin):
|
def _event_handler(self, pin):
|
||||||
self._count += 1
|
self._count += 1
|
||||||
self._total_count += 1
|
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._count = 0
|
self._count = 0
|
||||||
@@ -108,8 +107,7 @@ dtoverlay=spi0-cs,cs0_pin=14 # Re-assign CS0 from BCM 8 so that Grow can use it
|
|||||||
@property
|
@property
|
||||||
def active(self):
|
def active(self):
|
||||||
"""Check if the moisture sensor is producing a valid reading."""
|
"""Check if the moisture sensor is producing a valid reading."""
|
||||||
elapsed = time.time() - self._time_start
|
return (time.time() - self._last_pulse) < 1.0 and self._reading > 0 and self._reading < 28
|
||||||
return (self._total_count / elapsed) > self._minimum_hz
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def new_data(self):
|
def new_data(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user