Advertisement
Guest User

Untitled

a guest
May 3rd, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.25 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #rfid.pl
  4. #Copyright (c) 2012 Ben S. Eishen
  5. #This library is free software; you can redistribute it and/or
  6. #modify it under the terms of the GNU Lesser General Public
  7. #License as published by the Free Software Foundation; either
  8. #version 2.1 of the License, or (at your option) any later version.
  9.  
  10. #This library is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. #Lesser General Public License for more details.
  14.  
  15. use constant DOOR_GPIO      => 66; #output to relay
  16. use constant GARAGE_GPIO    => 67; #output to relay
  17. use constant WIEGAND_D0_GPIO    => 68; #open collector
  18. use constant WIEGAND_D1_GPIO    => 69; #open collector
  19. use constant STATUS_LED_GPIO    => 45; #pull to ground for Green, floating is RED
  20. use constant BUZZER_GPIO    => 44; #pull to ground to activate buzzer on keypad
  21.  
  22. use gpio;
  23. use IO::Poll qw(POLLRDNORM POLLWRNORM POLLIN POLLHUP);
  24.  
  25. init();
  26. scan_wiegand();
  27.  
  28. sub init{
  29.     gpio::export(DOOR_GPIO);
  30.     gpio::export(GARAGE_GPIO); 
  31.     gpio::export(WIEGAND_D0_GPIO);
  32.     gpio::export(WIEGAND_D1_GPIO);
  33.     gpio::export(STATUS_LED_GPIO);
  34.     gpio::export(BUZZER_GPIO);
  35.  
  36.     gpio::set_dir(DOOR_GPIO,1);
  37.     gpio::set_dir(GARAGE_GPIO,1);
  38.     gpio::set_dir(WIEGAND_D0_GPIO,0);
  39.     gpio::set_dir(WIEGAND_D1_GPIO,0);
  40.     gpio::set_dir(STATUS_LED_GPIO,1);
  41.     gpio::set_dir(BUZZER_GPIO);
  42.  
  43.     gpio::set_value(DOOR_GPIO,0);
  44.     gpio::set_value(GARAGE_GPIO,0);
  45.     gpio::set_value(STATUS_LED_GPIO,0);
  46.     gpio::set_value(BUZZER_GPIO,0);
  47.    
  48.     gpio::set_edge(WIEGAND_D0_GPIO,"falling");
  49.     gpio::set_edge(WIEGAND_D1_GPIO,"falling");
  50. }
  51.  
  52. sub unlock_door{
  53.     gpio::set_value(DOOR_GPIO,1);
  54.     gpio::set_value(STATUS_LED_GPIO,1);
  55.     sleep 3;
  56.     gpio::set_value(DOOR_GPIO,0);
  57.     gpio::set_value(STATUS_LED_GPIO,0);
  58. }
  59.  
  60. sub scan_wiegand{
  61.     my $d0 = gpio::fd_open(WIEGAND_D0_GPIO);
  62.     my $d1 = gpio::fd_open(WIEGAND_D1_GPIO);
  63.         $poll = IO::Poll->new();
  64.         $poll->mask($d0=>POLLPRI);
  65.         $poll->mask($d1=>POLLPRI);
  66.     while(1){
  67.         $poll->poll(500000);
  68.         if($poll->events($d0)){
  69.             print "Event on D0!!"
  70.         }
  71.         if($poll->events($d1)){
  72.             print "Event on D1!!"
  73.         }
  74.         print gpio::get_value(WIEGAND_D0_GPIO)."\t".gpio::get_value(WIEGAND_D1_GPIO)."\n";
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement