Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #rfid.pl
- #Copyright (c) 2012 Ben S. Eishen
- #This library is free software; you can redistribute it and/or
- #modify it under the terms of the GNU Lesser General Public
- #License as published by the Free Software Foundation; either
- #version 2.1 of the License, or (at your option) any later version.
- #This library is distributed in the hope that it will be useful,
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- #Lesser General Public License for more details.
- use constant DOOR_GPIO => 66; #output to relay
- use constant GARAGE_GPIO => 67; #output to relay
- use constant WIEGAND_D0_GPIO => 68; #open collector
- use constant WIEGAND_D1_GPIO => 69; #open collector
- use constant STATUS_LED_GPIO => 45; #pull to ground for Green, floating is RED
- use constant BUZZER_GPIO => 44; #pull to ground to activate buzzer on keypad
- use gpio;
- use IO::Poll qw(POLLRDNORM POLLWRNORM POLLIN POLLHUP);
- init();
- scan_wiegand();
- sub init{
- gpio::export(DOOR_GPIO);
- gpio::export(GARAGE_GPIO);
- gpio::export(WIEGAND_D0_GPIO);
- gpio::export(WIEGAND_D1_GPIO);
- gpio::export(STATUS_LED_GPIO);
- gpio::export(BUZZER_GPIO);
- gpio::set_dir(DOOR_GPIO,1);
- gpio::set_dir(GARAGE_GPIO,1);
- gpio::set_dir(WIEGAND_D0_GPIO,0);
- gpio::set_dir(WIEGAND_D1_GPIO,0);
- gpio::set_dir(STATUS_LED_GPIO,1);
- gpio::set_dir(BUZZER_GPIO);
- gpio::set_value(DOOR_GPIO,0);
- gpio::set_value(GARAGE_GPIO,0);
- gpio::set_value(STATUS_LED_GPIO,0);
- gpio::set_value(BUZZER_GPIO,0);
- gpio::set_edge(WIEGAND_D0_GPIO,"falling");
- gpio::set_edge(WIEGAND_D1_GPIO,"falling");
- }
- sub unlock_door{
- gpio::set_value(DOOR_GPIO,1);
- gpio::set_value(STATUS_LED_GPIO,1);
- sleep 3;
- gpio::set_value(DOOR_GPIO,0);
- gpio::set_value(STATUS_LED_GPIO,0);
- }
- sub scan_wiegand{
- my $d0 = gpio::fd_open(WIEGAND_D0_GPIO);
- my $d1 = gpio::fd_open(WIEGAND_D1_GPIO);
- $poll = IO::Poll->new();
- $poll->mask($d0=>POLLPRI);
- $poll->mask($d1=>POLLPRI);
- while(1){
- $poll->poll(500000);
- if($poll->events($d0)){
- print "Event on D0!!"
- }
- if($poll->events($d1)){
- print "Event on D1!!"
- }
- print gpio::get_value(WIEGAND_D0_GPIO)."\t".gpio::get_value(WIEGAND_D1_GPIO)."\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement