From 5dfa3efbbccad4fd13de4b635aeabf55a22d6b4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@hornquist.se>
Date: Thu, 27 Sep 2018 16:50:53 +0200
Subject: [PATCH] Fix double hit problem.

---
 time_machine/machine.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/time_machine/machine.py b/time_machine/machine.py
index b2e0595..efd746d 100644
--- a/time_machine/machine.py
+++ b/time_machine/machine.py
@@ -141,9 +141,19 @@ def main():
             wait_for_bottle_place()
             print "BOTTLE PLACED"
 
-            end_time = time_ms()
+            # Wait for bottle placed is in a loop because if the time
+            # is under 1 secound then we want to wait again. This is
+            # to prevent a finger or similar from stopping the time.
+            while True:
+                wait_for_bottle_place()
+                print "BOTTLE PLACED"
+
+                end_time = time_ms()
+                t = (end_time - start_time) / 1000.0
+                if t > 1:
+                    # Allow timing to halt
+                    break
 
-            t = (end_time - start_time) / 1000.0
             print "Hafvtid: {0} s".format(t)
             last_time = t
             lcd_info("Avvakta", last_time)
-- 
GitLab