diff --git a/README.md b/README.md index a791728..24a1db5 100644 --- a/README.md +++ b/README.md @@ -42,20 +42,21 @@ Don't forget to `make clean` after each checkout! # License - Copyright (C) 2016 Arti Zirk +```Text +Copyright (C) 2016 Arti Zirk - This file is part of I237 Door Access program. +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 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 . +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 . +``` diff --git a/src/cli_microrl.c b/src/cli_microrl.c index 9ba5e62..7d0de7e 100644 --- a/src/cli_microrl.c +++ b/src/cli_microrl.c @@ -27,6 +27,7 @@ #include "../lib/matejx_avr_lib/mfrc522.h" #include "rfid.h" + typedef struct cli_cmd { PGM_P cmd; PGM_P help; @@ -178,6 +179,7 @@ void cli_rfid_remove(const char *const *argv) rfid_remove_card_by_user(argv[1]); } + void cli_rfid_list(const char *const *argv) { (void) argv; diff --git a/src/cli_microrl.h b/src/cli_microrl.h index 1d9d481..352c8d5 100644 --- a/src/cli_microrl.h +++ b/src/cli_microrl.h @@ -21,6 +21,7 @@ #define NUM_ELEMS(x) (sizeof(x) / sizeof((x)[0])) #define UART_STATUS_MASK 0x00FF + void cli_print(const char * str); char cli_get_char(void); void cli_print_help(const char *const *argv); diff --git a/src/hmi_msg.c b/src/hmi_msg.c index 3bf74d9..46422f7 100644 --- a/src/hmi_msg.c +++ b/src/hmi_msg.c @@ -18,6 +18,7 @@ #include #include "hmi_msg.h" + static const char m1[] PROGMEM = "January"; static const char m2[] PROGMEM = "February"; static const char m3[] PROGMEM = "March"; @@ -43,5 +44,4 @@ const char remove_cmd[] PROGMEM = REMOVE_CMD; const char remove_help[] PROGMEM = REMOVE_HELP; const char list_cmd[] PROGMEM = LIST_CMD; const char list_help[] PROGMEM = LIST_HELP; - const char access_denied_msg[] PROGMEM = ACCESS_DENIED_MSG; diff --git a/src/hmi_msg.h b/src/hmi_msg.h index 15118ec..ef21990 100644 --- a/src/hmi_msg.h +++ b/src/hmi_msg.h @@ -18,14 +18,20 @@ #ifndef _HMI_MSG_H_ #define _HMI_MSG_H_ + #define PROG_VERSION "Version: %S built on: %S %S" #define LIBC_VERSION "avr-libc version: %S avr-gcc version: %S" #define STUD_NAME "Arti Zirk" #define GET_MONTH_MSG "Enter Month name first letter >" #define UPTIME_MSG "Uptime: %lu s" +#define CLI_HELP_MSG "Implemented commands:" +#define CLI_NO_CMD "Command not implemented.\n Use to get help." +#define CLI_ARGS_MSG "To few or to many arguments for this command\nUse " + #define HELP_CMD "help" #define HELP_HELP "Get help" + #define VER_CMD "version" #define VER_HELP "Print FW version" @@ -35,10 +41,6 @@ #define MONTH_CMD "month" #define MONTH_HELP "Find matching month from lookup list. Usage: month " -#define CLI_HELP_MSG "Implemented commands:" -#define CLI_NO_CMD "Command not implemented.\n Use to get help." -#define CLI_ARGS_MSG "To few or to many arguments for this command\nUse " - #define READ_CMD "read" #define READ_HELP "Read and print out card info that is currently in proximity of the reader" @@ -65,6 +67,7 @@ #define CARD_UID_MSG "Card UID: " #define CARD_NOT_SELECTED "Unable to select card.\n" + extern PGM_P const months[]; extern const char help_cmd[]; @@ -85,4 +88,5 @@ extern const char list_cmd[]; extern const char list_help[]; extern const char access_denied_msg[]; + #endif /* _HMI_MSG_H_ */ diff --git a/src/main.c b/src/main.c index 8a5b65a..91f6db7 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,7 @@ #include "rfid.h" +// uart0 and uart3 will run at this speed #define BAUDRATE 9600 // For configuring arduino mega pin 25 @@ -60,6 +61,7 @@ static inline void init_system_clock(void) TIMSK5 |= _BV(OCIE5A); // Output Compare A Match Interrupt Enable } + static inline uint32_t time(void) { uint32_t cur_time; @@ -106,6 +108,7 @@ static inline void init_hw (void) sei(); } + static inline void start_ui (void) { print_version(stderr); @@ -116,6 +119,7 @@ static inline void start_ui (void) lcd_puts_P(PSTR(STUD_NAME)); } + static inline void start_cli(void) { // Call init with ptr to microrl instance and print callback @@ -124,6 +128,7 @@ static inline void start_cli(void) microrl_set_execute_callback (prl, cli_execute); } + static inline void heartbeat (void) { static uint32_t time_prev; @@ -136,6 +141,7 @@ static inline void heartbeat (void) LED_TOGGLE; } + static inline void handle_door() { Uid uid; @@ -169,6 +175,8 @@ static inline void handle_door() } if ((message_start + 5) < time_cur) { + // clean the screen once again in 10 secconds so that cli command + // `month` could show found months for some time message_start = time_cur + 5; lcd_goto(0x40); for (int8_t i = 16; i > -1; i--) { @@ -181,6 +189,7 @@ static inline void handle_door() } } + int main (void) { init_hw(); diff --git a/src/print_helper.c b/src/print_helper.c index e1304d2..6421f74 100644 --- a/src/print_helper.c +++ b/src/print_helper.c @@ -19,6 +19,7 @@ #include #include "print_helper.h" + int print_ascii_tbl (FILE *stream) { for (char c = ' '; c <= '~'; c++) { diff --git a/src/rfid.c b/src/rfid.c index a191326..2735632 100644 --- a/src/rfid.c +++ b/src/rfid.c @@ -23,8 +23,10 @@ #include "rfid.h" #include "hmi_msg.h" + card_t *head = NULL; + void rfid_print_card(const card_t *card) { for (uint8_t i = 0; i < card->uid_size; i++) { @@ -33,6 +35,7 @@ void rfid_print_card(const card_t *card) printf(": %s", card->user); } + card_t* rfid_find_card(const card_t *card) { if (head != NULL) { @@ -51,6 +54,7 @@ card_t* rfid_find_card(const card_t *card) return NULL; } + void rfid_add_card(const card_t *card) { card_t *found_card = rfid_find_card(card); @@ -92,6 +96,7 @@ void rfid_add_card(const card_t *card) return; } + void rfid_list_cards(void) { if (head == NULL) { @@ -109,6 +114,7 @@ void rfid_list_cards(void) } } + void rfid_remove_card_by_user(const char *user) { card_t *curr; diff --git a/src/uart_wrap.c b/src/uart_wrap.c index 6572de3..f336552 100644 --- a/src/uart_wrap.c +++ b/src/uart_wrap.c @@ -19,8 +19,10 @@ #include #include "../lib/andygock_avr-uart/uart.h" + #define UART_STATUS_MASK 0x00FF + int uart0_putc_wrap(char c, FILE *stream) { (void) stream; @@ -33,6 +35,7 @@ int uart0_putc_wrap(char c, FILE *stream) return 0; } + int uart0_getc_wrap(FILE *stream) { (void) stream; @@ -43,6 +46,7 @@ int uart0_getc_wrap(FILE *stream) return uart0_getc() & UART_STATUS_MASK; } + int uart3_putc_wrap(char c, FILE *stream) { (void) stream;