MyTetra Share
Делитесь знаниями!
Menu v.2
Время создания: 19.12.2018 13:38
Раздел: Computer - Programming - C

//_____ I N C L U D E S ___________________________________________________

#include "stdio.h"

#include "stdint.h"


//_____ D E F I N I T I O N S ______________________________________________

#define BOARD_VER 1

#define BOARD_VER_INDEX 0

#define PROG_VER 1

#define PROG_VER_INDEX 0


#define MENU_MAIN 0

#define MENU_CONCT 1

#define MENU_CONF 2

#define MENU_STATS 3

#define MENU_UPDATE 4

#define MENU_REBOOT 5


#define MENU_MAIN_LVL 0

#define MENU_CONCT_LVL 10

#define MENU_CONF_LVL 20

#define MENU_STATS_LVL 30

#define MENU_UPDATE_LVL 40

#define MENU_REBOOT_LVL 50

#define MENU_CONF_SYS_LVL 100

#define MENU_CONF_IP_LVL 110

#define MENU_CONF_TIME_LVL 120

#define MENU_LOGS_LVL 220


#define MENU_STATS_INFO MENU_STATS_LVL+1

#define MENU_STATS_ETH MENU_STATS_LVL+2

#define MENU_STATS_LOGS MENU_STATS_LVL+3

#define MENU_CONF_SYS MENU_CONF_LVL+1

#define MENU_CONF_IP MENU_CONF_LVL+2

#define MENU_CONF_TIME MENU_CONF_LVL+3


#define MENU_NO_CHOISE 255


void menuShowReturnToMain(void);

void menuShowTipItem(void);

void menuMainList(void);

void menuConnectList(void);

void menuConfigList(void);

void menuConfigSysList(void);

void menuConfigIpList(void);

void menuConfigTimeList(void);

void menuStatusList(void);

void menuLogsList(void);

void menuUpdateList(void);

void menuRebootList(void);


struct Menu

{

const uint8_t items;

const uint8_t level;

void (*show) (void);

void (*interaction) (void);

};


int main(void)

{

/*

enum MenuPage {

MENU_MAIN,

MENU_STATS,

MENU_CONF,

MENU_LOGS,

MENU_UPDATE,

MENU_REBOOT

};


enum MenuPage menuPage = MENU_MAIN;

*/

uint8_t menuPage = MENU_MAIN;

uint8_t lastPage = MENU_MAIN;

uint8_t menuChoise;


struct Menu menuMain = {5, MENU_MAIN_LVL, menuMainList, NULL};

struct Menu menuConnect = {2, MENU_CONCT_LVL, menuConnectList, NULL};

struct Menu menuConfig = {3, MENU_CONF_LVL, menuConfigList, NULL};

struct Menu menuConfigSys = {1, MENU_CONF_SYS_LVL, menuConfigSysList, NULL};

struct Menu menuConfigIp = {7, MENU_CONF_IP_LVL, menuConfigIpList, NULL};

struct Menu menuConfigTime = {3, MENU_CONF_TIME_LVL, menuConfigTimeList, NULL};

struct Menu menuStatus = {3, MENU_STATS_LVL, menuStatusList, NULL};

struct Menu menuLogs = {1, MENU_LOGS_LVL, menuLogsList, NULL};

struct Menu menuUpdate = {1, MENU_UPDATE_LVL, menuUpdateList, NULL};

struct Menu menuReboot = {2, MENU_REBOOT_LVL, menuRebootList, NULL};



struct Menu *currentMenu;

currentMenu = NULL;


while(1)

{

switch(menuPage)

{

case MENU_MAIN:

currentMenu = &menuMain;

//currentMenu->items = 5; //stupid killing a bug with zero items

break;

case MENU_CONCT:

currentMenu = &menuConnect;

break;

case MENU_CONF:

currentMenu = &menuConfig;

break;

case MENU_STATS:

currentMenu = &menuStatus;

break;

case MENU_UPDATE:

currentMenu = &menuUpdate;

break;

case MENU_REBOOT:

currentMenu = &menuReboot;

break;

case MENU_CONF_SYS:

currentMenu = &menuConfigSys;

break;

case MENU_CONF_IP:

currentMenu = &menuConfigIp;

break;

case MENU_CONF_TIME:

currentMenu = &menuConfigTime;

break;

case MENU_STATS_LOGS:

currentMenu = &menuLogs;

break;

default:

//currentMenu = &menuMain;

break;

}


currentMenu->show();

if(currentMenu->level != MENU_MAIN) {

menuShowReturnToMain(); }

menuShowTipItem();


menuChoise = MENU_NO_CHOISE;

// scanf("%u", &menuChoise);

// while(menuChoise > (currentMenu->items))

do {

scanf("%u", &menuChoise);

}

while(menuChoise > (currentMenu->items));


if(menuChoise == 0 && currentMenu->level == MENU_MAIN_LVL)

{

printf("Logging out...\n");

getchar();

getchar();

return 0;

}

else if(menuChoise == 0 && menuPage < 10)

{

menuPage = MENU_MAIN;

}

else if(menuChoise == 0)

{

menuPage = lastPage;

}

else

{

if(currentMenu->level == 0)

lastPage = menuChoise;

menuPage = currentMenu->level + menuChoise;

}

}


return 0;

}


void menuShowReturnToMain(void)

{

printf("0. Back...\n\r");

}


void menuShowTipItem(void)

{

printf("\nTo select menu item, press item number, or highlight item and press <Enter>.\n\n\n\r");

}


void menuMainList(void)

{

printf("\tMain Menu\n\n\r");

printf("1. Connect to...\n\r");

printf("2. Configuration...\n\r");

printf("3. Status and Counters...\n\r");

printf("4. Update Firmware\n\r");

printf("5. Reboot...\n\r");

printf("0. Logout\n\r");

}


void menuConnectList(void)

{

printf("\tConnection Settings\n\n\r");

printf("1. Host IP:\n\r");

printf("2. Port:\n\r");

}


void menuConfigList(void)

{

printf("\tConfiguration\n\n\r");

printf("1. General System\n\r");

printf("2. IP Configuration\n\r");

printf("3. Time Configuration\n\r");

}

void menuConfigSysList(void)

{

printf("\tSystem Configuration\n\n\r");

printf("1. Logging Events: \tEnabled\n\r");

}


void menuConfigIpList(void)

{

printf("\tIP Configuration\n\n\r");

printf("1. IP Address: \t10.124.4.55\n\r");

printf("2. Network Mask: \t255.255.255.0\n\r");

printf("3. Default Gateway: \t10.124.4.126\n\r");

printf("4. Management Connections Limit: \t4\n\r");

printf("5. Management Port: \t23\n\r");

printf("6. Database IP Address: \t\n\r");

printf("7. Startup Connection: \t Enabled\n\r");

}


void menuConfigTimeList(void)

{

printf("\tTime Configuration\n\n\r");

printf("1. Time: \t17:05\n\r");

printf("2. Date: \t29.11.2018\n\r");

printf("3. SNTP: \tDisable\n\r");

}


void menuStatusList(void)

{

printf("\tStatus and Counters\n\n\r");

printf("1. General System Information\n\r");

printf("2. Ethernet Statistics\n\r");

printf("3. Event Logs\n\r");

}

void menuStatusSystem(void)

{

printf("\tSystem Information\n\n\r");

printf("STM32F407 chip. Board Version: %u.%u\n\r", BOARD_VER, BOARD_VER_INDEX);

printf("Firmware Version: %u.%u\n\r", PROG_VER, PROG_VER_INDEX);

printf("\n\r");

}


void menuLogsList(void)

{

printf("\tLogs\n\n\r");

printf("System works fine\n");

}


void menuUpdateList(void)

{

printf("\tUpdate Firmware\n\n\r");

printf("Firmware Version: %u.%u\n", PROG_VER, PROG_VER_INDEX);

}


void menuRebootList(void)

{

printf("\tReboot\n\n\r");

printf("1. After...\n\r");

printf("2. Now\n\r");

}






 
MyTetra Share v.0.53
Яндекс индекс цитирования