Add license
This commit is contained in:
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -135,7 +152,8 @@ void cli_rfid_read(const char *const *argv)
|
||||
}
|
||||
|
||||
|
||||
void cli_rfid_add(const char *const *argv) {
|
||||
void cli_rfid_add(const char *const *argv)
|
||||
{
|
||||
(void) argv;
|
||||
Uid uid;
|
||||
card_t card;
|
||||
@@ -143,23 +161,25 @@ void cli_rfid_add(const char *const *argv) {
|
||||
PICC_ReadCardSerial(&uid);
|
||||
card.uid_size = uid.size;
|
||||
memcpy(&card.uid, &uid.uidByte, uid.size);
|
||||
char *user = malloc(strlen(argv[1])+1);
|
||||
char *user = malloc(strlen(argv[1]) + 1);
|
||||
strcpy(user, argv[1]);
|
||||
card.user = user;
|
||||
rfid_add_card(&card);
|
||||
free(user); // card user has ben copied to the linked list
|
||||
} else {
|
||||
printf_P(PSTR(UNABLE_TO_DETECT_CARD_MSG "\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cli_rfid_remove(const char *const *argv) {
|
||||
void cli_rfid_remove(const char *const *argv)
|
||||
{
|
||||
(void) argv;
|
||||
rfid_remove_card_by_user(argv[1]);
|
||||
}
|
||||
|
||||
void cli_rfid_list(const char *const *argv) {
|
||||
void cli_rfid_list(const char *const *argv)
|
||||
{
|
||||
(void) argv;
|
||||
rfid_list_cards();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef _CLI_MICRORL_H_
|
||||
#define _CLI_MICRORL_H_
|
||||
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <avr/pgmspace.h>
|
||||
#include "hmi_msg.h"
|
||||
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef _HMI_MSG_H_
|
||||
#define _HMI_MSG_H_
|
||||
|
||||
|
||||
42
src/main.c
42
src/main.c
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <util/atomic.h>
|
||||
@@ -55,7 +72,7 @@ static inline uint32_t time(void)
|
||||
|
||||
static inline void init_rfid_reader(void)
|
||||
{
|
||||
MFRC522_init();
|
||||
MFRC522_init();
|
||||
PCD_Init();
|
||||
}
|
||||
|
||||
@@ -65,7 +82,7 @@ static inline void init_hw (void)
|
||||
// IO init
|
||||
// Set arduino pin 25 as output
|
||||
LED_INIT;
|
||||
|
||||
|
||||
// Set Arduino pin 23 as output
|
||||
DOOR_INIT;
|
||||
|
||||
@@ -81,7 +98,7 @@ static inline void init_hw (void)
|
||||
// LCD init
|
||||
lcd_init();
|
||||
lcd_clrscr();
|
||||
|
||||
|
||||
// Init RFID-RC522
|
||||
init_rfid_reader();
|
||||
|
||||
@@ -119,7 +136,8 @@ static inline void heartbeat (void)
|
||||
LED_TOGGLE;
|
||||
}
|
||||
|
||||
static inline void handle_door() {
|
||||
static inline void handle_door()
|
||||
{
|
||||
Uid uid;
|
||||
card_t card;
|
||||
uint32_t time_cur = time();
|
||||
@@ -134,7 +152,7 @@ static inline void handle_door() {
|
||||
if (found_card) {
|
||||
lcd_goto(0x40);
|
||||
lcd_puts(found_card->user);
|
||||
for (int8_t i=16-strlen(found_card->user); i > -1; i--) {
|
||||
for (int8_t i = 16 - strlen(found_card->user); i > -1; i--) {
|
||||
lcd_putc(' ');
|
||||
}
|
||||
DOOR_OPEN;
|
||||
@@ -142,23 +160,23 @@ static inline void handle_door() {
|
||||
DOOR_CLOSE;
|
||||
lcd_goto(0x40);
|
||||
lcd_puts_P(access_denied_msg);
|
||||
for (int8_t i=16-strlen_P(access_denied_msg); i > -1; i--) {
|
||||
for (int8_t i = 16 - strlen_P(access_denied_msg); i > -1; i--) {
|
||||
lcd_putc(' ');
|
||||
}
|
||||
}
|
||||
door_open_start = time_cur;
|
||||
message_start = time_cur;
|
||||
}
|
||||
|
||||
if ((message_start+5) < time_cur) {
|
||||
message_start = time_cur+5;
|
||||
|
||||
if ((message_start + 5) < time_cur) {
|
||||
message_start = time_cur + 5;
|
||||
lcd_goto(0x40);
|
||||
for (int8_t i=16; i > -1; i--) {
|
||||
for (int8_t i = 16; i > -1; i--) {
|
||||
lcd_putc(' ');
|
||||
}
|
||||
}
|
||||
|
||||
if ((door_open_start+2) < time_cur) {
|
||||
|
||||
if ((door_open_start + 2) < time_cur) {
|
||||
DOOR_CLOSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include "print_helper.h"
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef _PRINT_HELPER_H_
|
||||
#define _PRINT_HELPER_H_
|
||||
|
||||
|
||||
42
src/rfid.c
42
src/rfid.c
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -8,7 +25,8 @@
|
||||
|
||||
card_t *head = NULL;
|
||||
|
||||
void rfid_print_card(const card_t *card) {
|
||||
void rfid_print_card(const card_t *card)
|
||||
{
|
||||
for (uint8_t i = 0; i < card->uid_size; i++) {
|
||||
printf("%02X", card->uid[i]);
|
||||
}
|
||||
@@ -22,9 +40,9 @@ card_t* rfid_find_card(const card_t *card)
|
||||
current = head;
|
||||
while (current != NULL) {
|
||||
if ((current->uid_size != card->uid_size) ||
|
||||
!memcmp(current->uid, card->uid, current->uid_size) ||
|
||||
((card->user != NULL) && !strcmp(current->user, card->user))) {
|
||||
|
||||
!memcmp(current->uid, card->uid, current->uid_size) ||
|
||||
((card->user != NULL) && !strcmp(current->user, card->user))) {
|
||||
|
||||
return current;
|
||||
}
|
||||
current = current->next;
|
||||
@@ -42,18 +60,18 @@ void rfid_add_card(const card_t *card)
|
||||
printf_P(PSTR(NOT_ADDING_CARD_MSG2 "\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Card doesn't exist, add it
|
||||
card_t *new_card;
|
||||
char *new_card_user;
|
||||
new_card = malloc(sizeof(card_t));
|
||||
new_card_user = malloc(strlen(card->user)+1);
|
||||
new_card_user = malloc(strlen(card->user) + 1);
|
||||
if (!new_card || !new_card_user) {
|
||||
printf_P(PSTR(OUT_OF_MEMORY_MSG "\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy card data
|
||||
|
||||
// Copy card data
|
||||
new_card->uid_size = card->uid_size;
|
||||
memcpy(new_card->uid, card->uid, card->uid_size);
|
||||
strcpy(new_card_user, card->user);
|
||||
@@ -74,7 +92,8 @@ void rfid_add_card(const card_t *card)
|
||||
return;
|
||||
}
|
||||
|
||||
void rfid_list_cards(void) {
|
||||
void rfid_list_cards(void)
|
||||
{
|
||||
if (head == NULL) {
|
||||
printf_P(PSTR(NO_CARDS_ADDED_MSG "\n"));
|
||||
} else {
|
||||
@@ -90,7 +109,8 @@ void rfid_list_cards(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void rfid_remove_card_by_user(const char *user) {
|
||||
void rfid_remove_card_by_user(const char *user)
|
||||
{
|
||||
card_t *curr;
|
||||
card_t *prev;
|
||||
curr = head;
|
||||
@@ -123,7 +143,7 @@ void rfid_remove_card_by_user(const char *user) {
|
||||
prev->next = curr->next;
|
||||
free(curr->user);
|
||||
free(curr);
|
||||
} else if(prev != NULL && curr->next == NULL) {
|
||||
} else if (prev != NULL && curr->next == NULL) {
|
||||
// this is the last card in the list
|
||||
prev->next = NULL;
|
||||
free(curr->user);
|
||||
|
||||
17
src/rfid.h
17
src/rfid.h
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef _RFID_H_
|
||||
#define _RFID_H_
|
||||
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <avr/io.h>
|
||||
#include <stdio.h>
|
||||
#include "../lib/andygock_avr-uart/uart.h"
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
||||
*
|
||||
* This file is part of I237 Door Access program.
|
||||
*
|
||||
* I237 Door Access is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* I237 Door Access 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef _UART_WRAP_H_
|
||||
#define _UART_WRAP_H_
|
||||
|
||||
|
||||
Reference in New Issue
Block a user