Copied from upstream v1.32
This commit is contained in:
commit
5f5ccf8e03
118
DS1307/DS1307.cpp
Normal file
118
DS1307/DS1307.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Maurice Ribble
|
||||
* 4-17-2008
|
||||
* http://www.glacialwanderer.com/hobbyrobotics
|
||||
* This code tests the DS1307 Real Time clock on the Arduino board.
|
||||
* The ds1307 works in binary coded decimal or BCD. You can look up
|
||||
* bcd in google if you aren't familior with it. There can output
|
||||
* a square wave, but I don't expose that in this code. See the
|
||||
* ds1307 for it's full capabilities.
|
||||
*
|
||||
* Add Wire.begin(); to main setup function when ready to use.
|
||||
*
|
||||
* Modified 9/12/2009 by Arclight for C library use.
|
||||
* arclight@gmail.com
|
||||
*/
|
||||
|
||||
#include <DS1307.h>
|
||||
#include <Wire.h>
|
||||
|
||||
|
||||
DS1307::DS1307(){
|
||||
|
||||
}
|
||||
|
||||
DS1307::~DS1307(){
|
||||
}
|
||||
|
||||
|
||||
// Convert normal decimal numbers to binary coded decimal
|
||||
byte DS1307::decToBcd(byte val)
|
||||
{
|
||||
return ( (val/10*16) + (val%10) );
|
||||
}
|
||||
|
||||
// Convert binary coded decimal to normal decimal numbers
|
||||
byte DS1307::bcdToDec(byte val)
|
||||
{
|
||||
return ( (val/16*10) + (val%16) );
|
||||
}
|
||||
|
||||
// Stops the DS1307, but it has the side effect of setting seconds to 0
|
||||
// Probably only want to use this for testing
|
||||
|
||||
/*
|
||||
void DS1307::stopDs1307()
|
||||
{
|
||||
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
||||
Wire.send(0);
|
||||
Wire.send(0x80);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
*/
|
||||
|
||||
// 1) Sets the date and time on the ds1307
|
||||
// 2) Starts the clock
|
||||
// 3) Sets hour mode to 24 hour clock
|
||||
// Assumes you're passing in valid numbers
|
||||
|
||||
void DS1307::setDateDs1307(byte second, // 0-59
|
||||
byte minute, // 0-59
|
||||
byte hour, // 1-23
|
||||
byte dayOfWeek, // 1-7
|
||||
byte dayOfMonth, // 1-28/29/30/31
|
||||
byte month, // 1-12
|
||||
byte year) // 0-99
|
||||
{
|
||||
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
||||
Wire.send(0);
|
||||
Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
|
||||
Wire.send(decToBcd(minute));
|
||||
Wire.send(decToBcd(hour)); // If you want 12 hour am/pm you need to set
|
||||
// bit 6 (also need to change readDateDs1307)
|
||||
Wire.send(decToBcd(dayOfWeek));
|
||||
Wire.send(decToBcd(dayOfMonth));
|
||||
Wire.send(decToBcd(month));
|
||||
Wire.send(decToBcd(year));
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
// Gets the date and time from the ds1307
|
||||
void DS1307::getDateDs1307(byte *second,
|
||||
byte *minute,
|
||||
byte *hour,
|
||||
byte *dayOfWeek,
|
||||
byte *dayOfMonth,
|
||||
byte *month,
|
||||
byte *year)
|
||||
{
|
||||
// Reset the register pointer
|
||||
Wire.beginTransmission(DS1307_I2C_ADDRESS);
|
||||
Wire.send(0);
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
|
||||
|
||||
// A few of these need masks because certain bits are control bits
|
||||
*second = bcdToDec(Wire.receive() & 0x7f);
|
||||
*minute = bcdToDec(Wire.receive());
|
||||
*hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
|
||||
*dayOfWeek = bcdToDec(Wire.receive());
|
||||
*dayOfMonth = bcdToDec(Wire.receive());
|
||||
*month = bcdToDec(Wire.receive());
|
||||
*year = bcdToDec(Wire.receive());
|
||||
}
|
||||
|
||||
/*
|
||||
// Change these values to what you want to set your clock to.
|
||||
// You probably only want to set your clock once and then remove
|
||||
// the setDateDs1307 call.
|
||||
byte second = 20;
|
||||
byte minute = 9;
|
||||
byte hour = 19;
|
||||
byte dayOfWeek = 6;
|
||||
byte dayOfMonth = 12;
|
||||
byte month = 9;
|
||||
byte year = 9;
|
||||
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
|
||||
*/
|
44
DS1307/DS1307.h
Normal file
44
DS1307/DS1307.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* Adds support for the DS1307 real-time clock chip (RTC)
|
||||
*/
|
||||
|
||||
#ifndef _DS1307_H_
|
||||
#define _DS1307_H_
|
||||
#endif
|
||||
|
||||
#ifndef _Wire_H_
|
||||
#define _Wire_H_
|
||||
#endif
|
||||
|
||||
#include <WProgram.h>
|
||||
|
||||
#define DS1307_I2C_ADDRESS 0x68
|
||||
|
||||
|
||||
extern byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
|
||||
|
||||
class DS1307 {
|
||||
public:
|
||||
DS1307();
|
||||
~DS1307();
|
||||
|
||||
void setDateDs1307(byte second, // 0-59
|
||||
byte minute, // 0-59
|
||||
byte hour, // 1-23
|
||||
byte dayOfWeek, // 1-7
|
||||
byte dayOfMonth, // 1-28/29/30/31
|
||||
byte month, // 1-12
|
||||
byte year); // 0-99
|
||||
|
||||
void getDateDs1307(byte *second,
|
||||
byte *minute,
|
||||
byte *hour,
|
||||
byte *dayOfWeek,
|
||||
byte *dayOfMonth,
|
||||
byte *month,
|
||||
byte *year);
|
||||
|
||||
private:
|
||||
byte decToBcd(byte val);
|
||||
byte bcdToDec(byte val);
|
||||
|
||||
};
|
4
DS1307/keywords.txt
Normal file
4
DS1307/keywords.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
decToBcd KEYWORD2
|
||||
bcdToDec KEYWORD2
|
||||
setDateDs1307 KEYWORD2
|
||||
getDateDs1307 KEYWORD2
|
1544
Open_Access_Control.pde
Normal file
1544
Open_Access_Control.pde
Normal file
File diff suppressed because it is too large
Load Diff
138
PCATTACH/PCATTACH.cpp
Normal file
138
PCATTACH/PCATTACH.cpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
#include "pins_arduino.h"
|
||||
#include "PCATTACH.h"
|
||||
|
||||
/*
|
||||
* an extension to the interrupt support for arduino.
|
||||
* add pin change interrupts to the external interrupts, giving a way
|
||||
* for users to have interrupts drive off of any pin.
|
||||
* Refer to avr-gcc header files, arduino source and atmega datasheet.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Theory: all IO pins on Atmega168 are covered by Pin Change Interrupts.
|
||||
* The PCINT corresponding to the pin must be enabled and masked, and
|
||||
* an ISR routine provided. Since PCINTs are per port, not per pin, the ISR
|
||||
* must use some logic to actually implement a per-pin interrupt service.
|
||||
*/
|
||||
|
||||
PCATTACH::PCATTACH(){
|
||||
|
||||
}
|
||||
|
||||
PCATTACH::~PCATTACH(){
|
||||
}
|
||||
|
||||
PCATTACH pc1;
|
||||
|
||||
/* Pin to interrupt map:
|
||||
* D0-D7 = PCINT 16-23 = PCIR2 = PD = PCIE2 = pcmsk2
|
||||
* D8-D13 = PCINT 0-5 = PCIR0 = PB = PCIE0 = pcmsk0
|
||||
* A0-A5 (D14-D19) = PCINT 8-13 = PCIR1 = PC = PCIE1 = pcmsk1
|
||||
*/
|
||||
|
||||
volatile uint8_t *port_to_pcmask[] = {
|
||||
&PCMSK0,
|
||||
&PCMSK1,
|
||||
&PCMSK2
|
||||
};
|
||||
|
||||
typedef void (*voidFuncPtr)(void);
|
||||
|
||||
volatile static voidFuncPtr PCintFunc[24] = {
|
||||
NULL };
|
||||
|
||||
volatile static uint8_t PCintLast[3];
|
||||
|
||||
/*
|
||||
* attach an interrupt to a specific pin using pin change interrupts.
|
||||
* First version only supports CHANGE mode.
|
||||
*/
|
||||
void PCATTACH::PCattachInterrupt(uint8_t pin, void (*userFunc)(void), int mode) {
|
||||
uint8_t bit = digitalPinToBitMask(pin);
|
||||
uint8_t port = digitalPinToPort(pin);
|
||||
uint8_t slot;
|
||||
volatile uint8_t *pcmask;
|
||||
|
||||
if (mode != CHANGE) {
|
||||
return;
|
||||
}
|
||||
// map pin to PCIR register
|
||||
if (port == NOT_A_PORT) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
port -= 2;
|
||||
pcmask = port_to_pcmask[port];
|
||||
}
|
||||
slot = port * 8 + (pin % 8);
|
||||
PCintFunc[slot] = userFunc;
|
||||
// set the mask
|
||||
*pcmask |= bit;
|
||||
// enable the interrupt
|
||||
PCICR |= 0x01 << port;
|
||||
}
|
||||
|
||||
void PCATTACH::PCdetachInterrupt(uint8_t pin) {
|
||||
uint8_t bit = digitalPinToBitMask(pin);
|
||||
uint8_t port = digitalPinToPort(pin);
|
||||
volatile uint8_t *pcmask;
|
||||
|
||||
// map pin to PCIR register
|
||||
if (port == NOT_A_PORT) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
port -= 2;
|
||||
pcmask = port_to_pcmask[port];
|
||||
}
|
||||
|
||||
// disable the mask.
|
||||
*pcmask &= ~bit;
|
||||
// if that's the last one, disable the interrupt.
|
||||
if (*pcmask == 0) {
|
||||
PCICR &= ~(0x01 << port);
|
||||
}
|
||||
}
|
||||
|
||||
// common code for isr handler. "port" is the PCINT number.
|
||||
// there isn't really a good way to back-map ports and masks to pins.
|
||||
|
||||
void PCATTACH::PCint(uint8_t port) {
|
||||
uint8_t bit;
|
||||
uint8_t curr;
|
||||
uint8_t mask;
|
||||
uint8_t pin;
|
||||
|
||||
// get the pin states for the indicated port.
|
||||
curr = *portInputRegister(port+2);
|
||||
mask = curr ^ PCintLast[port];
|
||||
PCintLast[port] = curr;
|
||||
// mask is pins that have changed. screen out non pcint pins.
|
||||
if ((mask &= *port_to_pcmask[port]) == 0) {
|
||||
return;
|
||||
}
|
||||
// mask is pcint pins that have changed.
|
||||
for (uint8_t i=0; i < 8; i++) {
|
||||
bit = 0x01 << i;
|
||||
if (bit & mask) {
|
||||
pin = port * 8 + i;
|
||||
if (PCintFunc[pin] != NULL) {
|
||||
PCintFunc[pin]();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SIGNAL (PCINT0_vect) {
|
||||
pc1.PCint(0);
|
||||
}
|
||||
SIGNAL (PCINT1_vect) {
|
||||
pc1.PCint(1);
|
||||
}
|
||||
SIGNAL (PCINT2_vect) {
|
||||
pc1.PCint(2);
|
||||
}
|
||||
|
||||
|
||||
|
31
PCATTACH/PCATTACH.h
Normal file
31
PCATTACH/PCATTACH.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef _PCATTACH_H_
|
||||
#define _PCATTACH_H_
|
||||
#endif
|
||||
|
||||
#include <WProgram.h>
|
||||
#define uint_8 byte
|
||||
|
||||
class PCATTACH {
|
||||
|
||||
public:
|
||||
PCATTACH();
|
||||
~PCATTACH();
|
||||
|
||||
|
||||
|
||||
void PCattachInterrupt(byte pin, void (*userFunc)(void), int mode);
|
||||
void PCdetachInterrupt(byte pin);
|
||||
|
||||
|
||||
static void PCint(uint8_t);
|
||||
|
||||
/*
|
||||
volatile uint8_t *port_to_pcmask[];
|
||||
typedef void (*voidFuncPtr)(void);
|
||||
volatile static voidFuncPtr PCintFunc[];
|
||||
volatile static uint8_t PCintLast[];
|
||||
*/
|
||||
|
||||
|
||||
};
|
||||
|
2
PCATTACH/keywords.txt
Normal file
2
PCATTACH/keywords.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
PCattachInterrupt KEYWORD2
|
||||
PCdetachInterrupt KEYWORD2
|
45
README.txt
Normal file
45
README.txt
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* Open Access Control for Hacker Spaces
|
||||
* Created by 23B Shop Hacker Space
|
||||
* http://blog.shop.23b.org
|
||||
* by John Norman and Dan Lozano
|
||||
* Readme updated 4/3/2011
|
||||
*/
|
||||
|
||||
For the latest version of this software, visit:
|
||||
http://code.google.com/p/open-access-control/
|
||||
|
||||
New features in v1.32:
|
||||
-Serial console password with bad attempts lockout
|
||||
-Fixed minor bugs, remove some unused functions
|
||||
|
||||
Note: Unpack the libraries (WIEGAND26, DS1307, PCATTACH) into your arduino
|
||||
libraries directory. This is usually:
|
||||
|
||||
~/arduino/hardware/libraries/
|
||||
|
||||
|
||||
|
||||
The hardware design for the Open Access Control for Hacker Spaces uses the Arduino
|
||||
board with Atmega 328. It has been tested with:
|
||||
|
||||
-Arduino Uno
|
||||
-Arduino Duemilanove
|
||||
-Freeduino through hole (NKC)
|
||||
|
||||
The software has the following features:
|
||||
-Shield compatible with Arduino
|
||||
-Designed for use with Wiegand26 format readers (up to 3 support in software)
|
||||
-DS1307 Real-time clock support
|
||||
-(2) Wiegand26 reader inputs (optoisolated)
|
||||
-(4) Alarm zone monitor ports using Analog0..3
|
||||
-(4) Relay outputs
|
||||
|
||||
|
||||
The following pin assignments are assumed by this software:
|
||||
|
||||
-Pins 2,3 for Reader 1
|
||||
-Pins 4,5 for Reader 2
|
||||
-Pins 5,6,7,8 for Relays
|
||||
-Pins A0,A1,A2,A3 for alarm sensors
|
||||
-Pins A4,A5 for SDA,SCL (I2C)
|
||||
|
118
Wiegand26/WIEGAND26.cpp
Normal file
118
Wiegand26/WIEGAND26.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
#include <WIEGAND26.h>
|
||||
|
||||
extern byte reader1Pins[]; // Reader 1 connected to pins 4,5
|
||||
extern byte reader2Pins[]; // Reader2 connected to pins 6,7
|
||||
extern byte reader3Pins[]; // Reader3 connected to pins X,Y
|
||||
extern long reader1;
|
||||
extern int reader1Count;
|
||||
extern long reader2;
|
||||
extern int reader2Count;
|
||||
extern long reader3;
|
||||
extern int reader3Count;
|
||||
|
||||
|
||||
WIEGAND26::WIEGAND26(){
|
||||
}
|
||||
|
||||
WIEGAND26::~WIEGAND26(){
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Wiegand Reader code. Modify as needed or comment out unused readers.
|
||||
* system supports up to 3 independent readers.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
void WIEGAND26::initReaderOne(void) {
|
||||
for(byte i=0; i<2; i++){
|
||||
pinMode(reader1Pins[i], OUTPUT);
|
||||
digitalWrite(reader1Pins[i], HIGH); // enable internal pull up causing a one
|
||||
digitalWrite(reader1Pins[i], LOW); // disable internal pull up causing zero and thus an interrupt
|
||||
pinMode(reader1Pins[i], INPUT);
|
||||
digitalWrite(reader1Pins[i], HIGH); // enable internal pull up
|
||||
}
|
||||
delay(10);
|
||||
reader1Count=0;
|
||||
reader1=0;
|
||||
}
|
||||
|
||||
|
||||
void WIEGAND26::initReaderTwo(void) {
|
||||
for(byte i=0; i<2; i++){
|
||||
pinMode(reader2Pins[i], OUTPUT);
|
||||
digitalWrite(reader2Pins[i], HIGH); // enable internal pull up causing a one
|
||||
digitalWrite(reader2Pins[i], LOW); // disable internal pull up causing zero and thus an interrupt
|
||||
pinMode(reader2Pins[i], INPUT);
|
||||
digitalWrite(reader2Pins[i], HIGH); // enable internal pull up
|
||||
}
|
||||
delay(10);
|
||||
reader2Count=0;
|
||||
reader2=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WIEGAND26::reader1One() {
|
||||
if(digitalRead(reader1Pins[1]) == LOW){
|
||||
reader1Count++;
|
||||
reader1 = reader1 << 1;
|
||||
reader1 |= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void WIEGAND26::reader1Zero() {
|
||||
if(digitalRead(reader1Pins[0]) == LOW){
|
||||
reader1Count++;
|
||||
reader1 = reader1 << 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WIEGAND26::reader2One() {
|
||||
if(digitalRead(reader2Pins[1]) == LOW){
|
||||
reader2Count++;
|
||||
reader2 = reader2 << 1;
|
||||
reader2 |= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void WIEGAND26::reader2Zero(void) {
|
||||
if(digitalRead(reader2Pins[0]) == LOW){
|
||||
reader2Count++;
|
||||
reader2 = reader2 << 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WIEGAND26::initReaderThree(void) {
|
||||
for(byte i=0; i<2; i++){
|
||||
pinMode(reader3Pins[i], OUTPUT);
|
||||
digitalWrite(reader3Pins[i], HIGH); // enable internal pull up causing a one
|
||||
digitalWrite(reader3Pins[i], LOW); // disable internal pull up causing zero and thus an interrupt
|
||||
pinMode(reader3Pins[i], INPUT);
|
||||
digitalWrite(reader3Pins[i], HIGH); // enable internal pull up
|
||||
}
|
||||
delay(10);
|
||||
reader3Count=0;
|
||||
reader3=0;
|
||||
}
|
||||
|
||||
void WIEGAND26::reader3One(void) {
|
||||
if(digitalRead(reader3Pins[1]) == LOW){
|
||||
reader3Count++;
|
||||
reader3 = reader3 << 1;
|
||||
reader3 |= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void WIEGAND26::reader3Zero(void) {
|
||||
if(digitalRead(reader3Pins[0]) == LOW){
|
||||
reader3Count++;
|
||||
reader3 = reader3 << 1;
|
||||
}
|
||||
}
|
||||
|
36
Wiegand26/WIEGAND26.h
Normal file
36
Wiegand26/WIEGAND26.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef _WIEGAND26_H_
|
||||
#define _WIEGAND26_H_
|
||||
#endif
|
||||
|
||||
#include <WProgram.h>
|
||||
|
||||
class WIEGAND26 {
|
||||
public:
|
||||
WIEGAND26();
|
||||
~WIEGAND26();
|
||||
|
||||
|
||||
//const byte reader1Pins[]; // Reader 1 connected to pins 4,5
|
||||
//const byte reader2Pins[]; // Reader2 connected to pins 6,7
|
||||
//const byte reader3Pins[]; // Reader3 connected to pins X,Y
|
||||
|
||||
//volatile long reader1;
|
||||
//volatile int reader1Count;
|
||||
//volatile long reader2;
|
||||
//volatile int reader2Count;
|
||||
//volatile long reader3;
|
||||
//volatile int reader3Count;
|
||||
|
||||
void initReaderOne(void);
|
||||
void initReaderTwo(void);
|
||||
void reader1One(void);
|
||||
void reader1Zero(void);
|
||||
void reader2One(void);
|
||||
void reader2Zero(void);
|
||||
void initReaderThree(void);
|
||||
void reader3One(void);
|
||||
void reader3Zero(void);
|
||||
|
||||
private:
|
||||
|
||||
};
|
9
Wiegand26/keywords.txt
Normal file
9
Wiegand26/keywords.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
initReaderOne KEYWORD2
|
||||
initReaderTwo KEYWORD2
|
||||
reader1One KEYWORD2
|
||||
reader1Zero KEYWORD2
|
||||
reader2One KEYWORD2
|
||||
reader2Zero KEYWORD2
|
||||
initReaderThree KEYWORD2
|
||||
reader3One KEYWORD2
|
||||
reader3Zero KEYWORD2
|
Loading…
Reference in New Issue
Block a user