Added working rfid card read command
This commit is contained in:
parent
6cb4dd0157
commit
111699cae1
@ -6,6 +6,7 @@
|
|||||||
#include "hmi_msg.h"
|
#include "hmi_msg.h"
|
||||||
#include "print_helper.h"
|
#include "print_helper.h"
|
||||||
#include "cli_microrl.h"
|
#include "cli_microrl.h"
|
||||||
|
#include "../lib/matejx_avr_lib/mfrc522.h"
|
||||||
|
|
||||||
typedef struct cli_cmd {
|
typedef struct cli_cmd {
|
||||||
PGM_P cmd;
|
PGM_P cmd;
|
||||||
@ -19,7 +20,8 @@ const cli_cmd_t cli_cmds[] = {
|
|||||||
{help_cmd, help_help, cli_print_help, 0},
|
{help_cmd, help_help, cli_print_help, 0},
|
||||||
{ver_cmd, ver_help, cli_print_ver, 0},
|
{ver_cmd, ver_help, cli_print_ver, 0},
|
||||||
{ascii_cmd, ascii_help, cli_print_ascii_tbls, 0},
|
{ascii_cmd, ascii_help, cli_print_ascii_tbls, 0},
|
||||||
{month_cmd, month_help, cli_handle_month, 1}
|
{month_cmd, month_help, cli_handle_month, 1},
|
||||||
|
{read_cmd, read_help, cli_rfid_read, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -111,6 +113,28 @@ void cli_handle_month(const char *const *argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cli_rfid_read(const char *const *argv)
|
||||||
|
{
|
||||||
|
(void) argv;
|
||||||
|
Uid uid;
|
||||||
|
Uid *uid_ptr = &uid;
|
||||||
|
printf_P(PSTR("\n"));
|
||||||
|
if (PICC_IsNewCardPresent()) {
|
||||||
|
printf("Card selected!\n");
|
||||||
|
PICC_ReadCardSerial(uid_ptr);
|
||||||
|
printf("UID size: 0x%02X\n", uid.size);
|
||||||
|
printf("UID sak: 0x%02X\n", uid.sak);
|
||||||
|
printf("Card UID: ");
|
||||||
|
for (byte i = 0; i < uid.size; i++) {
|
||||||
|
printf("%02X", uid.uidByte[i]);
|
||||||
|
}
|
||||||
|
printf_P(PSTR("\n"));
|
||||||
|
} else {
|
||||||
|
printf_P((PSTR("Unable to select card.\n")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void cli_print_cmd_error(void)
|
void cli_print_cmd_error(void)
|
||||||
{
|
{
|
||||||
putc('\n', stdout);
|
putc('\n', stdout);
|
||||||
|
@ -11,6 +11,7 @@ void print_version(FILE *stream);
|
|||||||
void cli_print_ver(const char *const *argv);
|
void cli_print_ver(const char *const *argv);
|
||||||
void cli_print_ascii_tbls(const char *const *argv);
|
void cli_print_ascii_tbls(const char *const *argv);
|
||||||
void cli_handle_month(const char *const *argv);
|
void cli_handle_month(const char *const *argv);
|
||||||
|
void cli_rfid_read(const char *const *argv);
|
||||||
void cli_print_cmd_error(void);
|
void cli_print_cmd_error(void);
|
||||||
void cli_print_cmd_arg_error(void);
|
void cli_print_cmd_arg_error(void);
|
||||||
int cli_execute(int argc, const char *const *argv);
|
int cli_execute(int argc, const char *const *argv);
|
||||||
|
@ -18,3 +18,5 @@ const char ascii_cmd[] PROGMEM = ASCII_CMD;
|
|||||||
const char ascii_help[] PROGMEM = ASCII_HELP;
|
const char ascii_help[] PROGMEM = ASCII_HELP;
|
||||||
const char month_cmd[] PROGMEM = MONTH_CMD;
|
const char month_cmd[] PROGMEM = MONTH_CMD;
|
||||||
const char month_help[] PROGMEM = MONTH_HELP;
|
const char month_help[] PROGMEM = MONTH_HELP;
|
||||||
|
const char read_cmd[] PROGMEM = READ_CMD;
|
||||||
|
const char read_help[] PROGMEM = READ_HELP;
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
#define CLI_HELP_MSG "Implemented commands:"
|
#define CLI_HELP_MSG "Implemented commands:"
|
||||||
#define CLI_NO_CMD "Command not implemented.\n Use <help> to get help."
|
#define CLI_NO_CMD "Command not implemented.\n Use <help> to get help."
|
||||||
#define CLI_ARGS_MSG "To few or to many arguments for this command\nUse <help>"
|
#define CLI_ARGS_MSG "To few or to many arguments for this command\nUse <help>"
|
||||||
|
#define READ_CMD "read"
|
||||||
|
#define READ_HELP "Read and print out card info that is currently\nin proximity of the reader"
|
||||||
|
|
||||||
|
|
||||||
extern PGM_P const months[];
|
extern PGM_P const months[];
|
||||||
|
|
||||||
@ -29,5 +32,7 @@ extern const char ascii_cmd[];
|
|||||||
extern const char ascii_help[];
|
extern const char ascii_help[];
|
||||||
extern const char month_cmd[];
|
extern const char month_cmd[];
|
||||||
extern const char month_help[];
|
extern const char month_help[];
|
||||||
|
extern const char read_cmd[];
|
||||||
|
extern const char read_help[];
|
||||||
|
|
||||||
#endif /* _HMI_MSG_H_ */
|
#endif /* _HMI_MSG_H_ */
|
||||||
|
32
src/main.c
32
src/main.c
@ -1,6 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <util/atomic.h>
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
@ -12,6 +12,7 @@
|
|||||||
#include "../lib/hd44780_111/hd44780.h"
|
#include "../lib/hd44780_111/hd44780.h"
|
||||||
#include "../lib/helius_microrl/microrl.h"
|
#include "../lib/helius_microrl/microrl.h"
|
||||||
#include "cli_microrl.h"
|
#include "cli_microrl.h"
|
||||||
|
#include "../lib/matejx_avr_lib/mfrc522.h"
|
||||||
|
|
||||||
|
|
||||||
#define BAUDRATE 9600
|
#define BAUDRATE 9600
|
||||||
@ -21,10 +22,14 @@
|
|||||||
#define LED_TOGGLE PORTA ^= _BV(PORTA3)
|
#define LED_TOGGLE PORTA ^= _BV(PORTA3)
|
||||||
#define UART_STATUS_MASK 0x00FF
|
#define UART_STATUS_MASK 0x00FF
|
||||||
|
|
||||||
|
// Current system time
|
||||||
|
volatile uint32_t system_time;
|
||||||
|
|
||||||
// Create microrl object and pointer on it
|
// Create microrl object and pointer on it
|
||||||
static microrl_t rl;
|
static microrl_t rl;
|
||||||
static microrl_t *prl = &rl;
|
static microrl_t *prl = &rl;
|
||||||
|
|
||||||
|
|
||||||
static inline void init_system_clock(void)
|
static inline void init_system_clock(void)
|
||||||
{
|
{
|
||||||
TCCR5A = 0; // Clear control register A
|
TCCR5A = 0; // Clear control register A
|
||||||
@ -34,6 +39,22 @@ static inline void init_system_clock(void)
|
|||||||
TIMSK5 |= _BV(OCIE5A); // Output Compare A Match Interrupt Enable
|
TIMSK5 |= _BV(OCIE5A); // Output Compare A Match Interrupt Enable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint32_t time(void)
|
||||||
|
{
|
||||||
|
uint32_t cur_time;
|
||||||
|
ATOMIC_BLOCK(ATOMIC_FORCEON) {
|
||||||
|
cur_time = system_time;
|
||||||
|
}
|
||||||
|
return cur_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void init_rfid_reader(void)
|
||||||
|
{
|
||||||
|
MFRC522_init();
|
||||||
|
PCD_Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void init_hw (void)
|
static inline void init_hw (void)
|
||||||
{
|
{
|
||||||
@ -53,6 +74,9 @@ static inline void init_hw (void)
|
|||||||
// LCD init
|
// LCD init
|
||||||
lcd_init();
|
lcd_init();
|
||||||
lcd_clrscr();
|
lcd_clrscr();
|
||||||
|
|
||||||
|
// Init RFID-RC522
|
||||||
|
init_rfid_reader();
|
||||||
|
|
||||||
// Enable interupts
|
// Enable interupts
|
||||||
sei();
|
sei();
|
||||||
@ -78,8 +102,8 @@ static inline void start_cli(void)
|
|||||||
|
|
||||||
static inline void heartbeat (void)
|
static inline void heartbeat (void)
|
||||||
{
|
{
|
||||||
static time_t time_prev;
|
static uint32_t time_prev;
|
||||||
time_t time_cur = time(NULL);
|
uint32_t time_cur = time();
|
||||||
if (time_cur <= time_prev) {
|
if (time_cur <= time_prev) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -106,5 +130,5 @@ int main (void)
|
|||||||
// System clock
|
// System clock
|
||||||
ISR(TIMER5_COMPA_vect)
|
ISR(TIMER5_COMPA_vect)
|
||||||
{
|
{
|
||||||
system_tick();
|
system_time++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user