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 ); } ?>