From 500c93b72fc3c5c5c07816c49c94e1f0cdd4e261 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 24 Feb 2017 10:20:29 +0100 Subject: [PATCH] [Fix] Manage timeout reset if more than 1/2 sec --- lib/mfrc522/source/loop.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/mfrc522/source/loop.php b/lib/mfrc522/source/loop.php index a959eb2..c85a30a 100755 --- a/lib/mfrc522/source/loop.php +++ b/lib/mfrc522/source/loop.php @@ -338,10 +338,13 @@ /* [1] Wait for rfid card =========================================================*/ - /* (1) Read card */ + /* (1) Start timer */ + $start_ts = microtime(true); + + /* (2) Read card */ $code = syscall(SOURCE_DIR.'/lib/mfrc522/read'); - /* (2) If no card read -> reset @last_user / @timeout + abort */ + /* (3) If no card read -> reset @last_user / @timeout + abort */ if( $code === false ){ $last_user = null; @@ -350,8 +353,18 @@ } + /* (4) If timeout exceeded -> reset @timeout and @last_user */ + if( microtime(true) - $start_ts >= 0.5 ){ + $timeout = 0; + $last_user = null; + } - /* (3) If code -> format it */ + /* (5) Wait for 1/2 second */ + while( microtime(true) - $start_ts < 0.5 ); + + + + /* (6) If code -> format it */ $code = strtoupper($code); slog("card '$code' read", 'mfrc522:read'); @@ -447,7 +460,6 @@ mfrc522_loop(); - while( microtime(true) - $start_ts < 0.5 ); } ?>