Loop new implementation test@4
This commit is contained in:
parent
7240fc87c2
commit
ac2f5929d3
|
@ -11,6 +11,7 @@
|
||||||
$actions = [];
|
$actions = [];
|
||||||
|
|
||||||
$last_user = null;
|
$last_user = null;
|
||||||
|
$last_to = null; // last action timeout processed
|
||||||
$timeout = 0;
|
$timeout = 0;
|
||||||
|
|
||||||
$FEATURE = basename(dirname(__DIR__));
|
$FEATURE = basename(dirname(__DIR__));
|
||||||
|
@ -106,7 +107,7 @@
|
||||||
/* [1] Export global caches + variables
|
/* [1] Export global caches + variables
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Variables */
|
/* (1) Variables */
|
||||||
global $timeout;
|
global $timeout, $last_to;
|
||||||
|
|
||||||
/* (2) Caches */
|
/* (2) Caches */
|
||||||
global $actions;
|
global $actions;
|
||||||
|
@ -128,11 +129,15 @@
|
||||||
|
|
||||||
/* [2] Manage timeout
|
/* [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]) )
|
if( !isset($actions[$cur_timeout]) || !is_array($actions[$cur_timeout]) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* (2) fetch actions for the current @cur_timeout */
|
/* (3) fetch actions for the current @cur_timeout */
|
||||||
$actionlist = $actions[floor($cur_timeout)];
|
$actionlist = $actions[floor($cur_timeout)];
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,7 +240,10 @@
|
||||||
$toPerform
|
$toPerform
|
||||||
]).PHP_EOL );
|
]).PHP_EOL );
|
||||||
|
|
||||||
/* (2) Return status */
|
/* (2) Store @cur_timeout not to repeat it */
|
||||||
|
$last_to = $cur_timeout;
|
||||||
|
|
||||||
|
/* (3) Return status */
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -339,7 +347,7 @@
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Persistent variabes */
|
/* (1) Persistent variabes */
|
||||||
global $last_user;
|
global $last_user;
|
||||||
global $timeout;
|
global $timeout, $last_to;
|
||||||
|
|
||||||
/* (2) Caches */
|
/* (2) Caches */
|
||||||
global $actions;
|
global $actions;
|
||||||
|
@ -364,6 +372,7 @@
|
||||||
|
|
||||||
$last_user = null;
|
$last_user = null;
|
||||||
$timeout = 0;
|
$timeout = 0;
|
||||||
|
$last_to = -1;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -385,6 +394,7 @@
|
||||||
slog("Unknown user", "rfid-read:loop");
|
slog("Unknown user", "rfid-read:loop");
|
||||||
$last_user = null;
|
$last_user = null;
|
||||||
$timeout = 0;
|
$timeout = 0;
|
||||||
|
$last_to = -1;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,14 +15,16 @@ MIFAREReader = MFRC522.MFRC522()
|
||||||
|
|
||||||
# [3] If no card found -> exit 1
|
# [3] If no card found -> exit 1
|
||||||
if status != MIFAREReader.MI_OK:
|
if status != MIFAREReader.MI_OK:
|
||||||
exit(1);
|
print 127;
|
||||||
|
exit(127);
|
||||||
|
|
||||||
# [4] Get the UID of the card
|
# [4] Get the UID of the card
|
||||||
(status,uid) = MIFAREReader.MFRC522_Anticoll()
|
(status,uid) = MIFAREReader.MFRC522_Anticoll()
|
||||||
|
|
||||||
# [5] If no UID read -> exit 1
|
# [5] If no UID read -> exit 1
|
||||||
if status != MIFAREReader.MI_OK:
|
if status != MIFAREReader.MI_OK:
|
||||||
exit(1);
|
print 127;
|
||||||
|
exit(127);
|
||||||
|
|
||||||
# [6] Print UID
|
# [6] Print UID
|
||||||
suid = str(hex(uid[0]))[2:];
|
suid = str(hex(uid[0]))[2:];
|
||||||
|
@ -31,5 +33,4 @@ suid += '-' + str(hex(uid[2]))[2:];
|
||||||
suid += '-' + str(hex(uid[3]))[2:];
|
suid += '-' + str(hex(uid[3]))[2:];
|
||||||
|
|
||||||
print suid;
|
print suid;
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
Loading…
Reference in New Issue