use enter and leave to display tags
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 9 Aug 2010 16:38:39 +0000 (18:38 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 9 Aug 2010 16:38:39 +0000 (18:38 +0200)
scripts/scan.pl

index f4ec02a..8a460b2 100755 (executable)
@@ -22,15 +22,30 @@ GetOptions(
 my $rfid = RFID::Biblio::Reader->new( $reader );
 $RFID::Biblio::debug = $debug;
 
+sub tag {
+       my $tag = shift;
+       return $tag
+               , " AFI: "
+               , uc unpack('H2', $rfid->afi($tag))
+               , " "
+               , dump( RFID::Biblio::RFID501->to_hash( $rfid->blocks($tag) ) )
+               , $/
+               ;
+}
+
 do {
-       my @visible = $rfid->tags;
-       foreach my $tag ( @visible ) {
-               print $tag
-                       , " AFI: "
-                       , uc unpack('H2', $rfid->afi($tag))
-                       , " "
-                       , dump( RFID::Biblio::RFID501->to_hash( $rfid->blocks($tag) ) )
-                       , $/
-                       ;
-       }
+       my @visible = $rfid->tags(
+               enter => sub {
+                       my $tag = shift;
+                       print "enter $tag ", tag($tag);
+
+               },
+               leave => sub {
+                       my $tag = shift;
+                       print "leave $tag ", tag($tag);
+               },
+       );
+
+       warn scalar localtime, " visible: ",join(' ',@visible),"\n";
+
 } while $loop;