SATS/lib/mfrc522/source/loop.php

73 lines
1.4 KiB
PHP
Raw Normal View History

2017-01-30 10:41:25 +00:00
#!/usr/bin/php
<?php
require_once __DIR__.'/../../include/php/const';
$f_authlist;
$f_accesslog;
2017-02-18 10:09:49 +00:00
$last_card;
$times;
2017-01-30 10:41:25 +00:00
function mfrc522_setup(){
/* [1] Open file descriptors on useful files
=========================================================*/
$f_authlist = new SplFileObject(AUTH_LIST, 'r');
$f_accesslog = new SplFileObject(ACCESS_LOG, 'a');
/* [2] Parse @authlist to cache [action]=>[rfid1, rfid2, ..]
=========================================================*/
2017-02-18 10:09:49 +00:00
/* [3] Initialize global variables
=========================================================*/
$last_card = null;
$times = 0;
2017-01-30 10:41:25 +00:00
}
function mfrc522_loop(){
/* [1] Wait for rfid card
=========================================================*/
2017-02-18 10:09:49 +00:00
while( ($code=syscall(SOURCE_DIR.'/lib/mfrc522/read')) === false );
$code = strtoupper($code);
slog("card '$code' read", 'mfrc522:read');
2017-01-30 10:41:25 +00:00
$start_ts = microtime(true);
/* [2] Check for user in auth list
=========================================================*/
/* [3] Manage action (states)
=========================================================*/
2017-01-30 10:41:25 +00:00
/* [n] Wait for 0.5 s before reading again
=========================================================*/
while( microtime(true)-$start_ts < 0.5 );
}
slog('daemon started (loop)', 'mfrc522:loop');
while( true )
2017-02-18 10:09:49 +00:00
mfrc522_loop();
2017-01-30 10:41:25 +00:00
?>