Move all strings to hmi_msg

This commit is contained in:
Arti Zirk 2016-12-18 22:19:53 +02:00
parent fdfeabbcaa
commit 6a271e8f48
5 changed files with 42 additions and 30 deletions

View File

@ -49,7 +49,6 @@ char cli_get_char(void)
void cli_print_help(const char *const *argv) void cli_print_help(const char *const *argv)
{ {
(void) argv; (void) argv;
putc('\n', stdout);
printf_P(PSTR(CLI_HELP_MSG "\n")); printf_P(PSTR(CLI_HELP_MSG "\n"));
for (uint8_t i = 0; i < NUM_ELEMS(cli_cmds); i++) { for (uint8_t i = 0; i < NUM_ELEMS(cli_cmds); i++) {
@ -75,7 +74,6 @@ void print_version(FILE *stream)
void cli_print_ver(const char *const *argv) void cli_print_ver(const char *const *argv)
{ {
(void) argv; (void) argv;
putc('\n', stdout);
print_version(stdout); print_version(stdout);
} }
@ -83,7 +81,6 @@ 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) argv; (void) argv;
putc('\n', stdout);
// ASCII table print // ASCII table print
print_ascii_tbl(stdout); print_ascii_tbl(stdout);
unsigned char ascii[128]; unsigned char ascii[128];
@ -96,7 +93,6 @@ 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)
{ {
putc('\n', stdout);
lcd_goto(0x40); // Got to the beginning of the next line lcd_goto(0x40); // Got to the beginning of the next line
char spaces_to_print = 16; char spaces_to_print = 16;
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
@ -123,26 +119,24 @@ void cli_rfid_read(const char *const *argv)
(void) argv; (void) argv;
Uid uid; Uid uid;
Uid *uid_ptr = &uid; Uid *uid_ptr = &uid;
putc('\n', stdout);
if (PICC_IsNewCardPresent()) { if (PICC_IsNewCardPresent()) {
printf("Card selected!\n"); printf(CARD_SELECTED_MSG "\n");
PICC_ReadCardSerial(uid_ptr); PICC_ReadCardSerial(uid_ptr);
printf("UID size: 0x%02X\n", uid.size); printf_P(PSTR(UID_SIZE_MSG "\n"), uid.size);
printf("UID sak: 0x%02X\n", uid.sak); printf_P(PSTR(UID_SAK_MSG"\n"), uid.sak);
printf("Card UID: "); printf_P(PSTR(CARD_UID_MSG));
for (byte i = 0; i < uid.size; i++) { for (byte i = 0; i < uid.size; i++) {
printf("%02X", uid.uidByte[i]); printf("%02X", uid.uidByte[i]);
} }
printf_P(PSTR("\n")); putc('\n', stdout);
} else { } else {
printf_P((PSTR("Unable to select card.\n"))); printf_P((PSTR(CARD_NOT_SELECTED)));
} }
} }
void cli_rfid_add(const char *const *argv) { void cli_rfid_add(const char *const *argv) {
(void) argv; (void) argv;
putc('\n', stdout);
Uid uid; Uid uid;
card_t card; card_t card;
if (PICC_IsNewCardPresent()) { if (PICC_IsNewCardPresent()) {
@ -155,34 +149,30 @@ void cli_rfid_add(const char *const *argv) {
rfid_add_card(&card); rfid_add_card(&card);
free(user); // card user has ben copied to the linked list free(user); // card user has ben copied to the linked list
} else { } else {
printf_P(PSTR("Unable to detect card.\n")); 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; (void) argv;
putc('\n', stdout);
rfid_remove_card_by_user(argv[1]); 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; (void) argv;
putc('\n', stdout);
rfid_list_cards(); rfid_list_cards();
} }
void cli_print_cmd_error(void) void cli_print_cmd_error(void)
{ {
putc('\n', stdout);
printf_P(PSTR(CLI_NO_CMD "\n")); printf_P(PSTR(CLI_NO_CMD "\n"));
} }
void cli_print_cmd_arg_error(void) void cli_print_cmd_arg_error(void)
{ {
putc('\n', stdout);
printf_P(PSTR(CLI_ARGS_MSG "\n")); printf_P(PSTR(CLI_ARGS_MSG "\n"));
} }
@ -191,6 +181,7 @@ int cli_execute(int argc, const char *const *argv)
{ {
for (uint8_t i = 0; i < NUM_ELEMS(cli_cmds); i++) { for (uint8_t i = 0; i < NUM_ELEMS(cli_cmds); i++) {
if (!strcmp_P(argv[0], cli_cmds[i].cmd)) { if (!strcmp_P(argv[0], cli_cmds[i].cmd)) {
putc('\n', stdout);
// Test do we have correct arguments to run command // Test do we have correct arguments to run command
// Function arguments count shall be defined in struct // Function arguments count shall be defined in struct
if ((argc - 1) != cli_cmds[i].func_argc) { if ((argc - 1) != cli_cmds[i].func_argc) {
@ -204,7 +195,7 @@ int cli_execute(int argc, const char *const *argv)
return 0; return 0;
} }
} }
putc('\n', stdout);
cli_print_cmd_error(); cli_print_cmd_error();
return 0; return 0;
} }

View File

@ -26,3 +26,5 @@ const char remove_cmd[] PROGMEM = REMOVE_CMD;
const char remove_help[] PROGMEM = REMOVE_HELP; const char remove_help[] PROGMEM = REMOVE_HELP;
const char list_cmd[] PROGMEM = LIST_CMD; const char list_cmd[] PROGMEM = LIST_CMD;
const char list_help[] PROGMEM = LIST_HELP; const char list_help[] PROGMEM = LIST_HELP;
const char access_denied_msg[] PROGMEM = ACCESS_DENIED_MSG;

View File

@ -11,22 +11,41 @@
#define HELP_HELP "Get help" #define HELP_HELP "Get help"
#define VER_CMD "version" #define VER_CMD "version"
#define VER_HELP "Print FW version" #define VER_HELP "Print FW version"
#define ASCII_CMD "ascii" #define ASCII_CMD "ascii"
#define ASCII_HELP "print ASCII tables" #define ASCII_HELP "print ASCII tables"
#define MONTH_CMD "month" #define MONTH_CMD "month"
#define MONTH_HELP "Find matching month from lookup list. Usage: month <string>" #define MONTH_HELP "Find matching month from lookup list. Usage: month <string>"
#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_CMD "read"
#define READ_HELP "Read and print out card info that is currently in proximity of the reader" #define READ_HELP "Read and print out card info that is currently in proximity of the reader"
#define ADD_CMD "add" #define ADD_CMD "add"
#define ADD_HELP "Add a new card to the system. Usage: add <username>" #define ADD_HELP "Add a new card to the system. Usage: add <username>"
#define REMOVE_CMD "remove" #define REMOVE_CMD "remove"
#define REMOVE_HELP "Remove a card from the system. Usage: remove <username>" #define REMOVE_HELP "Remove a card from the system. Usage: remove <username>"
#define LIST_CMD "list" #define LIST_CMD "list"
#define LIST_HELP "List all added cards" #define LIST_HELP "List all added cards"
#define ACCESS_DENIED_MSG "Access denied!"
#define NOT_ADDING_CARD_MSG1 "Found card \""
#define NOT_ADDING_CARD_MSG2 "\", not adding it again."
#define OUT_OF_MEMORY_MSG "Out of memory. Please remove cards."
#define NO_CARDS_ADDED_MSG "No cards added"
#define CARD_NOT_FOUND_MSG "Card not found"
#define LINKED_LIST_ERROR_MSG "Invalid situation when removing card"
#define UNABLE_TO_DETECT_CARD_MSG "Unable to detect card."
#define CARD_SELECTED_MSG "Card selected!"
#define UID_SIZE_MSG "UID size: 0x%02X"
#define UID_SAK_MSG "UID sak: 0x%02X"
extern PGM_P const months[]; extern PGM_P const months[];

View File

@ -141,8 +141,8 @@ static inline void handle_door() {
} else { } else {
DOOR_CLOSE; DOOR_CLOSE;
lcd_goto(0x40); lcd_goto(0x40);
lcd_puts("Access denied!"); lcd_puts_P(access_denied_msg);
for (int8_t i=4; i > -1; i--) { for (int8_t i=16-strlen_P(access_denied_msg); i > -1; i--) {
lcd_putc(' '); lcd_putc(' ');
} }
} }
@ -151,6 +151,7 @@ static inline void handle_door() {
} }
if ((message_start+5) < time_cur) { if ((message_start+5) < time_cur) {
message_start = time_cur+5;
lcd_goto(0x40); lcd_goto(0x40);
for (int8_t i=16; i > -1; i--) { for (int8_t i=16; i > -1; i--) {
lcd_putc(' '); lcd_putc(' ');

View File

@ -36,9 +36,9 @@ void rfid_add_card(const card_t *card)
{ {
card_t *found_card = rfid_find_card(card); card_t *found_card = rfid_find_card(card);
if (found_card) { if (found_card) {
printf("Found card \""); printf_P(PSTR(NOT_ADDING_CARD_MSG1));
rfid_print_card(found_card); rfid_print_card(found_card);
printf("\", not adding it again.\n"); printf_P(PSTR(NOT_ADDING_CARD_MSG2 "\n"));
return; return;
} }
@ -48,7 +48,7 @@ void rfid_add_card(const card_t *card)
new_card = malloc(sizeof(card_t)); 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) { if (!new_card || !new_card_user) {
printf_P(PSTR("Out of memory. Please remove cards.\n")); printf_P(PSTR(OUT_OF_MEMORY_MSG "\n"));
return; return;
} }
@ -75,17 +75,17 @@ void rfid_add_card(const card_t *card)
void rfid_list_cards(void) { void rfid_list_cards(void) {
if (head == NULL) { if (head == NULL) {
printf_P(PSTR("No cards added\n")); printf_P(PSTR(NO_CARDS_ADDED_MSG "\n"));
} else { } else {
card_t *current; card_t *current;
current = head; current = head;
while (current->next != NULL) { while (current->next != NULL) {
rfid_print_card(current); rfid_print_card(current);
printf("\n"); putc('\n', stdout);
current = current->next; current = current->next;
} }
rfid_print_card(current); rfid_print_card(current);
printf("\n"); putc('\n', stdout);
} }
} }
@ -95,7 +95,7 @@ void rfid_remove_card_by_user(const char *user) {
curr = head; curr = head;
prev = NULL; prev = NULL;
if (head == NULL) { if (head == NULL) {
printf_P(PSTR("No cards added\n")); printf_P(PSTR(NO_CARDS_ADDED_MSG "\n"));
return; return;
} else { } else {
while (curr->next != NULL) { while (curr->next != NULL) {
@ -128,10 +128,9 @@ void rfid_remove_card_by_user(const char *user) {
free(curr->user); free(curr->user);
free(curr); free(curr);
} else { } else {
fprintf_P(stderr, PSTR("Invalid situation when removing card\n")); printf_P(PSTR(LINKED_LIST_ERROR_MSG "\n"));
} }
} else { } else {
printf_P(PSTR(CARD_NOT_FOUND_MSG));
printf_P(PSTR("Card not found\n"));
} }
} }