
#include "opora.h"
#include "config.h"
#include "LCD.h"
#include "LCD_b.h"
#include "keyboard.h"
#include "menu.h"

extern _Menu *CurrentMenu;
extern _Menu TopMenu;
extern _Menu Submenu1;
extern _Menu Submenu2;
uint32_t Temp;

int main()
{
	ClkConfig();
	LCDInit();
	KeysInit();
	CurrentMenu = &TopMenu;
	DrawMenu(CurrentMenu);	
	while(1)
	{
		switch(PressKey())
		{
			case TOP:
				if(CurrentMenu->CurrentAssignSubMenu < 2) CurrentMenu->CurrentAssignSubMenu = CurrentMenu->NumberOfSubMenu;
				else CurrentMenu->CurrentAssignSubMenu--;
				ClearLCD();
				DrawMenu(CurrentMenu);
				WaitUntilPress(TOP);
				break;

			case BOTTOM:
				if(CurrentMenu->CurrentAssignSubMenu == CurrentMenu->NumberOfSubMenu) CurrentMenu->CurrentAssignSubMenu = 1;
				else CurrentMenu->CurrentAssignSubMenu++;
				ClearLCD();
				DrawMenu(CurrentMenu);
				WaitUntilPress(BOTTOM);
				break;

			case BACK:
				if(CurrentMenu->MenuLevel != 0)
				{
					CurrentMenu = &TopMenu;
					ClearLCD();
					DrawMenu(CurrentMenu);
				}
				WaitUntilPress(BACK);
				break;
				
			case SELECT:
				if(CurrentMenu->BottomMenu != 1)
				{
					switch(CurrentMenu->CurrentAssignSubMenu)
					{
						case 1:
							CurrentMenu = &Submenu1;
							break;
						case 2:
							CurrentMenu = &Submenu2;
							break;
					}
					ClearLCD();
					DrawMenu(CurrentMenu);
					if(CurrentMenu->BottomMenu == 1)
					{
						DrawFunction(CurrentMenu);
						WaitUntilNotPress(BACK);
					}
				}
				WaitUntilPress(SELECT);
				break;
		}
	}	
}



