From ac2f5929d334c8cc53a03d7aab9b49b552e5601e Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Thu, 28 Sep 2017 10:55:59 +0200 Subject: [PATCH] Loop new implementation test@4 --- feature/rfid-read/source/loop.php | 20 +++++++++++++++----- feature/rfid-read/source/read.py | 7 ++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/feature/rfid-read/source/loop.php b/feature/rfid-read/source/loop.php index 52a980d..f6f91f0 100755 --- a/feature/rfid-read/source/loop.php +++ b/feature/rfid-read/source/loop.php @@ -11,6 +11,7 @@ $actions = []; $last_user = null; + $last_to = null; // last action timeout processed $timeout = 0; $FEATURE = basename(dirname(__DIR__)); @@ -106,7 +107,7 @@ /* [1] Export global caches + variables =========================================================*/ /* (1) Variables */ - global $timeout; + global $timeout, $last_to; /* (2) Caches */ global $actions; @@ -128,11 +129,15 @@ /* [2] Manage timeout =========================================================*/ - /* (1) If no action for this @cur_timeout -> reset to 0 */ + /* (1) If already acted for this timeout -> abort */ + if( $last_to == $cur_timeout ) + return false; + + /* (2) If no action for this @cur_timeout -> reset to 0 */ if( !isset($actions[$cur_timeout]) || !is_array($actions[$cur_timeout]) ) return false; - /* (2) fetch actions for the current @cur_timeout */ + /* (3) fetch actions for the current @cur_timeout */ $actionlist = $actions[floor($cur_timeout)]; @@ -235,7 +240,10 @@ $toPerform ]).PHP_EOL ); - /* (2) Return status */ + /* (2) Store @cur_timeout not to repeat it */ + $last_to = $cur_timeout; + + /* (3) Return status */ return true; } @@ -339,7 +347,7 @@ =========================================================*/ /* (1) Persistent variabes */ global $last_user; - global $timeout; + global $timeout, $last_to; /* (2) Caches */ global $actions; @@ -364,6 +372,7 @@ $last_user = null; $timeout = 0; + $last_to = -1; return false; } @@ -385,6 +394,7 @@ slog("Unknown user", "rfid-read:loop"); $last_user = null; $timeout = 0; + $last_to = -1; return false; } diff --git a/feature/rfid-read/source/read.py b/feature/rfid-read/source/read.py index c02ed3a..c69c5b0 100644 --- a/feature/rfid-read/source/read.py +++ b/feature/rfid-read/source/read.py @@ -15,14 +15,16 @@ MIFAREReader = MFRC522.MFRC522() # [3] If no card found -> exit 1 if status != MIFAREReader.MI_OK: - exit(1); + print 127; + exit(127); # [4] Get the UID of the card (status,uid) = MIFAREReader.MFRC522_Anticoll() # [5] If no UID read -> exit 1 if status != MIFAREReader.MI_OK: - exit(1); + print 127; + exit(127); # [6] Print UID suid = str(hex(uid[0]))[2:]; @@ -31,5 +33,4 @@ suid += '-' + str(hex(uid[2]))[2:]; suid += '-' + str(hex(uid[3]))[2:]; print suid; - exit(0);