// Console initiation
#include <stdio.h>
#include <string.h>
#include "esp_system.h"
#include "esp_console.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "prplfetch.h"
#include "pinout.h"
#define PROMPT_STR CONFIG_IDF_TARGET
bool dev_login = false;
char password[20] = "PrPlSocKS@WB!1226:3!"; // If you know how to access this, you deserve to know the password
int nah(int argc, char **argv)
{
printf("Not Implemented\n");
if (!dev_login)
{
printf("You aren't logged in! You wont be able to use dev commands\n");
}
return 0;
}
int login(int argc, char **argv)
{
char chr[20];
if (dev_login)
{
printf("You are already logged in!\n");
return 0;
}
printf("Enter Password: ");
scanf("%20s", chr); // thanks ekawahyu!
if (strcmp(chr, password) == 0)
{
printf("\nSUCCESS :3\n");
dev_login = true;
return 0;
}
else
{
printf("\nWRONG PASSWORD\n");
return 0;
}
}
int logout(int argc, char **argv)
{
dev_login = false;
printf("Logged Out\n");
return 0;
}
int change_password(int argc, char **argv)
{
if (!dev_login)
{
printf("You aren't logged in!\n");
return 1;
}
char chr[20];
printf("Enter Old Password: ");
scanf("%20s", chr); // thanks ekawahyu!
if (strcmp(chr, password) == 0)
{
printf("\nSUCCESS :3\n");
printf("Enter New Password: ");
scanf("%20s", chr); // thanks ekawahyu!
strcpy(password, chr);
printf("\nPassword Changed\n");
return 0;
}
else
{
printf("\nWRONG PASSWORD\n");
return 0;
}
}
static void register_logout(void)
{
const esp_console_cmd_t cmd = {
.command = "logout",
.help = "Disable Dev Console Commands",
.hint = NULL,
.func = &logout,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
static void register_set_name(void)
{
const esp_console_cmd_t cmd = {
.command = "setname",
.help = "(DEV) Sets the name of the WarriorAttend Terminal",
.hint = NULL,
.func = &nah,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
static void register_pn532_proto(void)
{
const esp_console_cmd_t cmd = {
.command = "pn532proto",
.help = "(DEV) Sets the PN532 Protocol (SPI, I2C, UART)",
.hint = NULL,
.func = &nah,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
static void register_login(void)
{
const esp_console_cmd_t cmd = {
.command = "login",
.help = "Enable Dev Console Commands",
.hint = NULL,
.func = &login,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
static void register_change_password(void)
{
const esp_console_cmd_t cmd = {
.command = "changepassword",
.help = "(DEV) Change the Dev Console Password",
.hint = NULL,
.func = &change_password,
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
void app_main(void)
{
nvs_flash_init();
esp_console_register_help_command();
register_set_name();
register_pn532_proto();
register_login();
register_logout();
register_change_password();
register_prplfetch();
register_pinout();
// REPL (Read-Evaluate-Print-Loop) environment
esp_console_repl_t *repl = NULL;
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
repl_config.prompt = PROMPT_STR ">";
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
esp_console_new_repl_uart(&hw_config, &repl_config, &repl);
esp_console_start_repl(repl);
}