SATS/lib/mfrc522/source/loop.php

58 lines
1.0 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;
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, ..]
=========================================================*/
}
function mfrc522_loop(){
/* [1] Wait for rfid card
=========================================================*/
while( !($code=syscall(SOURCE_DIR.'/lib/mfrc522/read')) );
$start_ts = microtime(true);
/* [2] Check for user in auth list
=========================================================*/
/* [n] Wait for 0.5 s before reading again
=========================================================*/
while( microtime(true)-$start_ts < 0.5 );
}
slog('daemon started (loop)', 'mfrc522:loop');
while( true )
echo mfrc522_loop();
?>