Skip to content

Commit a60e576

Browse files
authored
Merge pull request #24 from caternuson/iss23
Add retries for moisture reading
2 parents 2df8a67 + e604940 commit a60e576

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

adafruit_seesaw/seesaw.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,17 @@ def moisture_read(self):
236236
self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005)
237237
ret = struct.unpack(">H", buf)[0]
238238
time.sleep(.001)
239+
240+
# retry if reading was bad
241+
count = 0
242+
while ret > 4095:
243+
self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005)
244+
ret = struct.unpack(">H", buf)[0]
245+
time.sleep(.001)
246+
count += 1
247+
if count > 3:
248+
raise RuntimeError("Could not get a valid moisture reading.")
249+
239250
return ret
240251

241252
def pin_mode_bulk(self, pins, mode):

0 commit comments

Comments
 (0)