//------------------------------< Menu.c >------------------------------
#include "tables.h"
#include "menu.h"
#include "graphics.h"
#include "globvar.h"
#include "gpla.h"
#include "math.h"
#include "menu_function.h"
#include "iodefine.h"

//----------------------< Glob. Var. pro menu.c >-----------------------
volatile unsigned char OldItem = 0;
//---< Menu >---
volatile unsigned char menu_index[5];  // Sem si ulozim cestu do submenu
volatile unsigned char zanoreni = 0;      // Jak hluboko jsem v menu vyuziti u index_menu
volatile unsigned char menu_actual = 1;   // Kde jsem aktualne v menu. Po stisknuti talcita set se mi hodnota nakopiruje do pole menu_index a inkrementuje se mi zanoreni
volatile unsigned int  menu_from = 0;     // Odkud mi v tabulce Menu zacina dane submenu
volatile unsigned char menu_number;   // Kolik polozek dane sub menu ma

//---< Param >---
volatile float ParamMin;  // Minimalni hodnota param  
volatile float ParamMax;  // Maximalni hodnota param
volatile float ParamAct;  // Aktualni hodnota param
volatile float ParamStep; // Krok param.
volatile unsigned int ParamTextFrom;
volatile unsigned char IdxParamTable;
volatile unsigned char ParamPoloz;  // Rika kolik polozek v poli ma dana polozka menu  
//---< Kalibrace >---
volatile float kalibr; // Pomocna pri kalibraci
//---< Overeni hesla >------
volatile unsigned int heslo[4];
volatile unsigned char heslo_ukaz=0;

void MenuDef(void){
	Key = 0;
  menu_index[0] = 0;
  menu_index[1] = 0;
  menu_index[2] = 0;
  menu_index[3] = 0;
  menu_index[4] = 0;
	menu_actual = 1;
}
/*********************************************************************************************
*                                  ---< Settings >---                                        *
*                             Zalozka nastaveni pristroje                                    *
*********************************************************************************************/
void Settings(void)
{
  unsigned int i,TextEnd;
	unsigned char To,Vykres;
  static unsigned char FirstLine = 0, ActualLine = 1,OldActualLine = 1;

//---------------< Posun v menu >-------------------------
  if(flag.NewScreen){
	  CleanScreen(white);
		OldItem = 0;
		FirstLine =0;
		ActualLine = menu_actual;
		OldActualLine = menu_actual;
  }
 	if(menu_number > 11){  // Menu ma moc polozek a nevejdou se na obrazovku
	  ScrollH2(menu_number,menu_actual,1);	
    To = 11;
		// Dolu
    if((OldItem < menu_actual) && (OldItem !=0)){
      if(ActualLine<11){
	  	  ActualLine++;	    // Nese informaci na kterem radku mam mit prouzku s aktualnim menu 
			}
			else{
			  FirstLine++;	    // Jsem na poslednim radku obrazovky posouvam text
		  } 
		}
		// Hore 
		if(OldItem > menu_actual){
		  if(ActualLine>1){
		    ActualLine--;	
			}
			else{
				FirstLine--;
			} 
		}
		// Pretoceni menu v obou smerech
		if((menu_actual == 1) && (OldItem > menu_actual)){
      ActualLine = 1;
	    FirstLine = 0;	
		} 		
		if((menu_actual == menu_number) && (OldItem < menu_actual)){
      ActualLine= 11;
	    FirstLine = menu_number-11;	
		 }
	  }
	else{  // Menu ma mene polozek nez co se vejdou na obrazovku
    if((OldItem < menu_actual) && (OldItem !=0)){
      ActualLine++;	    // Nese informaci na kterem radku mam mit prouzku s aktualnim menu 
		}
		if(OldItem > menu_actual){ 
	    ActualLine--;	
		}
		if((menu_actual == 1) && (OldItem > menu_actual)){
      ActualLine = 1;
	    FirstLine = 0;	
		} 		
		if((menu_actual == menu_number) && (OldItem < menu_actual)){
      ActualLine= menu_number;
	    FirstLine = 0;	
		 }		
		To = menu_number;
	}
//---< Zobrazeni menu a obsluha tlacitek >---	
	if(OldItem != menu_actual){
    // Aktualni menu
    DrawBox(5,36*ActualLine+30,601,36,blue2);    // Modra prouzka
    Troj(8,36*ActualLine+31,10,31,blue1);        // Trojuhelnik
    ZobrazParametr(menu_from+FirstLine+ActualLine,36*ActualLine+30,blue2,1);		
	  if(ActualLine != OldActualLine){
      DrawBox(5,36*OldActualLine+30,601,36,white);    // smazu modrou prouzku s trojuhelnikem
      ZobrazParametr(menu_from+FirstLine+OldActualLine,36*OldActualLine+30,white,1);		
		}
	  for(i=1;i<=To;i++){
      if(i!=ActualLine){
        ZobrazParametr(menu_from+FirstLine+i,36*i+30,white,1);
	    }
	  }
		  OldItem = menu_actual;
  	  OldActualLine = ActualLine;
  }
 	else{
	  ZobrazParametr(menu_from+FirstLine+ActualLine,36*ActualLine+30,blue2,0);  // Polozka se nezmenila mrknu jesti neni param		
    if(flag.ParamEnd){  // Byla dokoncela param. Obnovim menu kdyby nastavena hodnota ovlivnovala jinou
			for(i=1;i<=To;i++){
        if(i!=ActualLine){ 	  
   		    ZobrazParametr(menu_from+FirstLine+i,36*i+30,white,1);
				}
				else{
   		    ZobrazParametr(menu_from+FirstLine+i,36*i+30,blue2,1);
				} 
			}
	  }
  }
}

/************************************************************************
*                         ---< ZobrazParametr >---                      *
************************************************************************/
void ZobrazParametr(unsigned int PolozkaMenu,unsigned int PositionY,unsigned int color_screen,unsigned char ChangeItem)
{
	unsigned char *ee_adr,i;
	unsigned int IdxParamTable,NumberShow;
	unsigned int TextFrom,color;
	float Hodnota;



  IdxParamTable = (10*(Menu[PolozkaMenu][6]-0x30)+(Menu[PolozkaMenu][7]-0x30));	
  if('~' == Menu[PolozkaMenu][10]){  // polozka ma submenu
	  if(ChangeItem){
	    TextFrom = WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,blue1,color_screen,0);
      DrawBox(TextFrom,PositionY,601-TextFrom,36,color_screen);
	    WriteText("->",520,PositionY,blue1,color_screen,0);
		}
  }
	else{
		   //---< Polozka ma parametr  >---
//--- Zobrazeni specialnich parametru (cas, prevod...)
    switch(menu_index[1]){
		  case MERENI:  // Polozka mereni
        switch(PolozkaMenu-menu_from){
					case 3: if(flag.ParamEnd){          // Nap Trafa Ano/Ne
						        if(!ParamChar[5]){
                      ParamFloat[0]=0;
                      ParamFloat[1]=0;
      								ee_adr = (unsigned char*)&ParamFloat[0];    // Sec
				     					eep_another_write(ee_nap_TrSec,4,ee_adr);	 
						    			ee_adr = (unsigned char*)&ParamFloat[1];  // Pri
								    	eep_another_write(ee_nap_TrPri,4,ee_adr);											
                      for(i=0;i<4;i++){
											  ee_adr= (unsigned char *)&Kalibr_array[i];
	                      eep_another_read(ee_kal_U0+(4*i),4,ee_adr);	
											}
										}
					        }
									break;
					case 4: if(flag.ParamEnd){       // Proud Trafa ano/ne
						        if(!ParamChar[6]){
                      ParamFloat[2]=0;
                      ParamFloat[3]=0;
      								ee_adr = (unsigned char*)&ParamFloat[2];    // Sec
				     					eep_another_write(ee_pro_TrSec,4,ee_adr);	 
						    			ee_adr = (unsigned char*)&ParamFloat[3];  // Pri
								    	eep_another_write(ee_pro_TrPri,4,ee_adr);											
                      for(i=0;i<4;i++){
											  ee_adr= (unsigned char *)&Kalibr_array[i+4];
	                      eep_another_read(ee_kal_I0+(4*i),4,ee_adr);	
											}
										}
					        }
									break;
 					case 5:	PrevodNapTraf(PolozkaMenu,PositionY,color_screen);  // Prevod nap traf
								  return;
 					case 6:	PrevodProudTraf(PolozkaMenu,PositionY,color_screen);  // Prevod proud traf
								  return;
                  break;	
				}
			break; 	
		}
 	  if(ChangeItem){
	    TextFrom = WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,blue1,color_screen,0);
      DrawBox(TextFrom,PositionY,601-TextFrom,36,color_screen);
		}
//--- Je param------------------------ 
    if(flag.Param){  // Je param
 	    TlacitkaParam(); // Je Param jdu na obsluha tlacitek pri param
      color = red1;
			Hodnota = ParamAct;
//---< Zobrazeni sipek pri param>---
	    HorizontalLine(562,PositionY+16,21,4,blue1);
	    if(ParamAct == ParamMin)TrojB(560,PositionY+22,11,24,grey1);
	    else TrojB(560,PositionY+22,11,24,blue1);
 	    if(ParamAct == ParamMax)TrojB(560,PositionY+14,-11,24,grey1);
	    else TrojB(560,PositionY+14,-11,24,blue1);			
		}
		else{  // Neni param
		  color = blue1;
	    switch(tab_adr[IdxParamTable][1]){
	      case 1: Hodnota = (unsigned char)(ParamChar[tab_adr[IdxParamTable][0]]);
				        break;
		    case 2: Hodnota = (unsigned int)(ParamInt[tab_adr[IdxParamTable][0]]);
				  			break;
			  case 3: Hodnota = (float)(ParamFloat[tab_adr[IdxParamTable][0]]);
				  			break;
      }
		}
//---< Zobrazeni parametru >---
    if(!tab_param[IdxParamTable][1]){  // zobrazuju cislo
		  NumToStr(Hodnota,tab_param[IdxParamTable][2],tab_param[IdxParamTable][3],tab_param[IdxParamTable][5]&0b00000010,tab_param[IdxParamTable][5]&0b00000100,1);
      if(tab_param[IdxParamTable][4]){
			  JoinText(&cislo[0],(unsigned char*)&tab_jednotky[tab_param[IdxParamTable][4]]);	
			}
      WriteTextAligR(&cislo[0],545,PositionY,color,color_screen,0);
		}
		else{  // misto cisel je text
      TextFrom = WriteTextAligR((unsigned char*)&(tab_text[(unsigned char)Hodnota+tab_param[IdxParamTable][1]][0]),545,PositionY,color,color_screen,0);
      if(flag.Param){  // Jenom pri param se meni delka textu proto budu mazat to co mi zustane po prepsani
        DrawBox(320,PositionY,TextFrom-320,36,blue2);
			}		 
		} 
		if(flag.ParamEnd)DrawBox(560,PositionY,26,36,color_screen); // smazu sipky   	
	}
}
/******************************************************************************************
*                             ---<PrevodNapTraf >---                                      *
******************************************************************************************/
void PrevodNapTraf(unsigned int PolozkaMenu,unsigned int PositionY,unsigned int color_screen)
{
  unsigned char polozka = 0,End_set=0,i;
  unsigned char *ee_adr;
	unsigned int IdxParamTable,TextFrom,TextEnd;
	float NumberShow,PrevodSec;

  IdxParamTable = (10*(Menu[PolozkaMenu][6]-0x30)+(Menu[PolozkaMenu][7]-0x30));
  if(ParamChar[5]){  // Jsou povolena trafa??
	  if(flag.Param){
	    while(!End_set){				
		    if(Key){  // Bylo neco stisknuto
	        switch(Key){
	          case KEY_SET:  if(!polozka){
                             PrevodSec =ParamAct;  // Ulozim si sec
														 ParamAct = ParamFloat[tab_adr[IdxParamTable][0]+1];
					                   polozka++;  
					                 }
							             else{
							               if(polozka == 1){
															ParamFloat[tab_adr[IdxParamTable][0]] = PrevodSec;
	                            ParamFloat[tab_adr[IdxParamTable][0]+1] =ParamAct;  // Ulozim si pri
      											  ee_adr = (unsigned char*)&ParamFloat[tab_adr[IdxParamTable][0]];    // Sec
				     								  eep_another_write(ee_nap_TrSec,4,ee_adr);	 
						    						  ee_adr = (unsigned char*)&ParamFloat[tab_adr[IdxParamTable][0]+1];  // Pri
								    				  eep_another_write(ee_nap_TrPri,4,ee_adr);
  									          for(i=0;i<4;i++){
															  ee_adr= (unsigned char *)&Kalibr_array[i];
	                              eep_another_read(ee_kal_U0+(4*i),4,ee_adr);	
															  Kalibr_array[i]*=(ParamFloat[tab_adr[IdxParamTable][0]+1]/ParamFloat[tab_adr[IdxParamTable][0]]);	
															}
														  flag.Param = 0;  // Jdu z param.
			                        flag.ParamEnd = 1; // Skoncila param. Slouzi k naprave skod na LCD po param.
					  					        flag.Repeat = 0;
						  				        flag.FastRepeat = 0;
													    End_set = 1;
													  }
	  											} 
		  		                break;
		        case KEY_ESC: flag.Param = 0;  // Jdu z param.
			                    flag.ParamEnd = 1; // Skoncila param. Slouzi k naprave skod na LCD po param.
					  					    flag.Repeat = 0;
						  				    flag.FastRepeat = 0;
											    End_set = 1;
											    break;
		        case KEY_UP:  if(ParamAct+ParamStep*estep < ParamMax)ParamAct+=ParamStep*estep;
						  					  else ParamAct = ParamMax;
			                    break;
		        case KEY_DOWN: if(ParamAct-ParamStep*estep > ParamMin)ParamAct-=ParamStep*estep;
						  					   else ParamAct = ParamMin;
      			               break;
		      }
				  Key = 0;  // Obsluha byla provedena smazu 	
 			  }
	      if(!polozka){
  				ParamMax = 500;
					ParamStep = 10;
					ParamMin = 10;
    		  TextEnd=WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,blue1,color_screen,0);
			  //---Sec
				  TextFrom = ShowJednotky(545,PositionY,"V",ParamAct,red1,color_screen,0,3);    // Napisu jednotky
	        NumberShow = ShowJednotky(TextFrom,PositionY,"V",ParamAct,red1,color_screen,0,2);  // Vratim si cislo v radu
          if(ParamAct>1000)NumToStr(NumberShow,4,1,0,0,0);
          else NumToStr(NumberShow,2,0,0,0,0);
	        TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,red1,color_screen,0);
	        TextFrom = WriteTextAligR(":",TextFrom,PositionY,blue1,color_screen,0);
          //---Pri
		      TextFrom = ShowJednotky(TextFrom,PositionY,"V",ParamFloat[tab_adr[IdxParamTable][0]+1],blue1,color_screen,0,3);    // Napisu jednotky
	        NumberShow = ShowJednotky(TextFrom,PositionY,"V",ParamFloat[tab_adr[IdxParamTable][0]+1],blue1,color_screen,0,2);  // Vratim si cislo v radu
          if(ParamFloat[tab_adr[IdxParamTable][0]+1]>1000)NumToStr(NumberShow,4,1,0,0,0);
          else NumToStr(NumberShow,2,0,0,0,0);
	        TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,blue1,color_screen,0);
    	    DrawBox(TextEnd,PositionY,TextFrom-TextEnd,36,color_screen);
			  }
			  else{
					ParamMax = 750000;
					ParamStep = 100;
					ParamMin = 100; 
    		  TextEnd=WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,blue1,color_screen,0);
					//--Sec
				  TextFrom = ShowJednotky(545,PositionY,"V",PrevodSec,blue1,color_screen,0,3);    // Napisu jednotky
	        NumberShow = ShowJednotky(TextFrom,PositionY,"V",PrevodSec,blue1,color_screen,0,2);  // Vratim si cislo v radu
          if(PrevodSec>1000)NumToStr(NumberShow,4,1,0,0,0);
          else NumToStr(NumberShow,2,0,0,0,0);
	        TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,blue1,color_screen,0);
	        TextFrom = WriteTextAligR(":",TextFrom,PositionY,blue1,color_screen,0);
          //---Pri
		      TextFrom = ShowJednotky(TextFrom,PositionY,"V",ParamAct,red1,color_screen,0,3);    // Napisu jednotky
	        NumberShow = ShowJednotky(TextFrom,PositionY,"V",ParamAct,red1,color_screen,0,2);  // Vratim si cislo v radu
          if(ParamAct>1000)NumToStr(NumberShow,4,1,0,0,0);
          else NumToStr(NumberShow,2,0,0,0,0);
	        TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,red1,color_screen,0);
    	    DrawBox(TextEnd,PositionY,TextFrom-TextEnd,36,color_screen);
			  }
		  }
	  } 	
		else{ 
		  TextEnd=WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,blue1,color_screen,0);
	  //--- Sec 
	    TextFrom = ShowJednotky(545,PositionY,"V",ParamFloat[tab_adr[IdxParamTable][0]],blue1,color_screen,0,3);    // Napisu jednotky
	    NumberShow = ShowJednotky(TextFrom,PositionY,"V",ParamFloat[tab_adr[IdxParamTable][0]],blue1,color_screen,0,2);  // Vratim si cislo v radu
      if(ParamFloat[tab_adr[IdxParamTable][0]]>1000)NumToStr(NumberShow,4,1,0,0,0);
      else NumToStr(NumberShow,2,0,0,0,0);
	    TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,blue1,color_screen,0);
	    TextFrom = WriteTextAligR(":",TextFrom,PositionY,blue1,color_screen,0);
	  //--- Pri
	    TextFrom = ShowJednotky(TextFrom,PositionY,"V",ParamFloat[tab_adr[IdxParamTable][0]+1],blue1,color_screen,0,3);    // Napisu jednotky
	    NumberShow = ShowJednotky(TextFrom,PositionY,"V",ParamFloat[tab_adr[IdxParamTable][0]+1],blue1,color_screen,0,2);  // Vratim si cislo v radu
      if(ParamFloat[tab_adr[IdxParamTable][0]+1]>1000)NumToStr(NumberShow,4,1,0,0,0);
      else NumToStr(NumberShow,2,0,0,0,0);
	    TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,blue1,color_screen,0);
	    DrawBox(TextEnd,PositionY,TextFrom-TextEnd,36,color_screen);
	  }
	}
	else{  // Nejsou
	  if(flag.Param)flag.Param = 0;  // Nejsou povolena trafa neni povolena ani editace
		TextEnd = WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,grey1,color_screen,0);
		TextFrom = WriteTextAligR("---:---",545,PositionY,grey1,color_screen,0);
    DrawBox(TextEnd,PositionY,TextFrom-TextEnd,36,color_screen);
	}	
}
/******************************************************************************************
*                             ---< PrevodProudTraf >---                                      *
******************************************************************************************/
void PrevodProudTraf(unsigned int PolozkaMenu,unsigned int PositionY,unsigned int color_screen)
{
  unsigned char polozka = 0,End_set=0,i;
  unsigned char *ee_adr;
	unsigned int IdxParamTable,TextFrom,TextEnd;
	float NumberShow,PrevodSec;

  IdxParamTable = (10*(Menu[PolozkaMenu][6]-0x30)+(Menu[PolozkaMenu][7]-0x30));
  if(ParamChar[6]){  // Jsou povolena trafa??
	  if(flag.Param){
	    while(!End_set){				
		    if(Key){  // Bylo neco stisknuto
	        switch(Key){
	          case KEY_SET:  if(!polozka){
                             PrevodSec =ParamAct;  // Ulozim si sec
														 ParamAct = ParamFloat[tab_adr[IdxParamTable][0]+1];
					                   polozka++;  
					                 }
							             else{
							               if(polozka == 1){
															ParamFloat[tab_adr[IdxParamTable][0]] = PrevodSec;
	                            ParamFloat[tab_adr[IdxParamTable][0]+1] =ParamAct;  // Ulozim si pri
      											  ee_adr = (unsigned char*)&ParamFloat[tab_adr[IdxParamTable][0]];    // Sec
				     								  eep_another_write(ee_pro_TrSec,4,ee_adr);	 
						    						  ee_adr = (unsigned char*)&ParamFloat[tab_adr[IdxParamTable][0]+1];  // Pri
								    				  eep_another_write(ee_pro_TrPri,4,ee_adr);
														  for(i=0;i<4;i++){
															  ee_adr= (unsigned char *)&Kalibr_array[i+4];
	                              eep_another_read(ee_kal_I0+(4*i),4,ee_adr);	
															  Kalibr_array[i+4]*=(ParamFloat[tab_adr[IdxParamTable][0]+1]/ParamFloat[tab_adr[IdxParamTable][0]]);	
															}
														  flag.Param = 0;  // Jdu z param.
			                        flag.ParamEnd = 1; // Skoncila param. Slouzi k naprave skod na LCD po param.
					  					        flag.Repeat = 0;
						  				        flag.FastRepeat = 0;
													    End_set = 1;
													  }
	  											} 
		  		                break;
		        case KEY_ESC: flag.Param = 0;  // Jdu z param.
			                    flag.ParamEnd = 1; // Skoncila param. Slouzi k naprave skod na LCD po param.
					  					    flag.Repeat = 0;
						  				    flag.FastRepeat = 0;
											    End_set = 1;
											    break;
		        case KEY_UP:  if(ParamAct+ParamStep*estep < ParamMax)ParamAct+=ParamStep*estep;
						  					  else ParamAct = ParamMax;
			                    break;
		        case KEY_DOWN: if(ParamAct-ParamStep*estep > ParamMin)ParamAct-=ParamStep*estep;
						  					   else ParamAct = ParamMin;
      			               break;
		      }
				  Key = 0;  // Obsluha byla provedena smazu 	
 			  }
	      if(!polozka){
  				ParamMax = 5;
					ParamStep = 5;
					ParamMin = 1;
    		  TextEnd=WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,blue1,color_screen,0);
			  //---Sec
				  TextFrom = ShowJednotky(545,PositionY,"A",ParamAct,red1,color_screen,0,3);    // Napisu jednotky
	        NumberShow = ShowJednotky(TextFrom,PositionY,"A",ParamAct,red1,color_screen,0,2);  // Vratim si cislo v radu
          NumToStr(NumberShow,2,0,0,0,0);
	        TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,red1,color_screen,0);
	        TextFrom = WriteTextAligR(":",TextFrom,PositionY,blue1,color_screen,0);
          //---Pri
		      TextFrom = ShowJednotky(TextFrom,PositionY,"A",ParamFloat[tab_adr[IdxParamTable][0]+1],blue1,color_screen,0,3);    // Napisu jednotky
	        NumberShow = ShowJednotky(TextFrom,PositionY,"A",ParamFloat[tab_adr[IdxParamTable][0]+1],blue1,color_screen,0,2);  // Vratim si cislo v radu
          if(ParamAct>1000)NumToStr(NumberShow,7,3,0,0,0);
          else NumToStr(NumberShow,2,0,0,0,0);
	        TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,blue1,color_screen,0);
    	    DrawBox(TextEnd,PositionY,TextFrom-TextEnd,36,color_screen);
			  }
			  else{
					ParamMax = 7500;
					ParamStep = 1;
					ParamMin = 1; 
    		  TextEnd=WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,blue1,color_screen,0);
					//--Sec
				  TextFrom = ShowJednotky(545,PositionY,"A",PrevodSec,blue1,color_screen,0,3);    // Napisu jednotky
	        NumberShow = ShowJednotky(TextFrom,PositionY,"A",PrevodSec,blue1,color_screen,0,2);  // Vratim si cislo v radu
          NumToStr(NumberShow,2,0,0,0,0);
	        TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,blue1,color_screen,0);
	        TextFrom = WriteTextAligR(":",TextFrom,PositionY,blue1,color_screen,0);
          //---Pri
		      TextFrom = ShowJednotky(TextFrom,PositionY,"A",ParamAct,red1,color_screen,0,3);    // Napisu jednotky
	        NumberShow = ShowJednotky(TextFrom,PositionY,"A",ParamAct,red1,color_screen,0,2);  // Vratim si cislo v radu
          if(ParamAct>1000)NumToStr(NumberShow,7,3,0,0,0);
          else NumToStr(NumberShow,2,0,0,0,0);
	        TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,red1,color_screen,0);
    	    DrawBox(TextEnd,PositionY,TextFrom-TextEnd,36,color_screen);
			  }
		  }
	  } 	
		else{ 
		  TextEnd=WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,blue1,color_screen,0);
	  //--- Sec 
	    TextFrom = ShowJednotky(545,PositionY,"A",ParamFloat[tab_adr[IdxParamTable][0]],blue1,color_screen,0,3);    // Napisu jednotky
	    NumberShow = ShowJednotky(TextFrom,PositionY,"A",ParamFloat[tab_adr[IdxParamTable][0]],blue1,color_screen,0,2);  // Vratim si cislo v radu
      NumToStr(NumberShow,2,0,0,0,0);
	    TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,blue1,color_screen,0);
	    TextFrom = WriteTextAligR(":",TextFrom,PositionY,blue1,color_screen,0);
	  //--- Pri
	    TextFrom = ShowJednotky(TextFrom,PositionY,"A",ParamFloat[tab_adr[IdxParamTable][0]+1],blue1,color_screen,0,3);    // Napisu jednotky
	    NumberShow = ShowJednotky(TextFrom,PositionY,"A",ParamFloat[tab_adr[IdxParamTable][0]+1],blue1,color_screen,0,2);  // Vratim si cislo v radu
      if(ParamFloat[tab_adr[IdxParamTable][0]+1]>1000)NumToStr(NumberShow,7,3,0,0,0);
      else NumToStr(NumberShow,2,0,0,0,0);
	    TextFrom = WriteTextAligR(&cislo[0],TextFrom,PositionY,blue1,color_screen,0);
	    DrawBox(TextEnd,PositionY,TextFrom-TextEnd,36,color_screen);
	  }
	}
	else{  // Nejsou
	  if(flag.Param)flag.Param = 0;  // Nejsou povolena trafa neni povolena ani editace
		TextEnd = WriteTextMenuB(&Menu[PolozkaMenu][0],80,PositionY,grey1,color_screen,0);
		TextFrom = WriteTextAligR("---:---",545,PositionY,grey1,color_screen,0);
    DrawBox(TextEnd,PositionY,TextFrom-TextEnd,36,color_screen);
	}	
}
/************************************************************************
*                             ---< FindMenu>---                         *
*        Najde odkud dane submenu zacina v poli Menu (menu_from)        *
*        a kolik polozek submenu ma (menu_number)                       *
************************************************************************/        
void FindMenu(void){
	
	unsigned int number, idx = 0;
	unsigned char i,m=0;
 
  for(i=0;i<3;i++){  // Prevedu si pole indexu v menu na format pro porovnani
    idx += menu_index[i];
	  idx <<= 2;
	}
  do{  // Najdu odkud mi zacina menu
		number = 0; 	
    for(i=1; i <= 5; i+=2){
      number = number + (10*(Menu[m][i-1]-0x30)+(Menu[m][i]-0x30));
		  number <<=2;
 	  }
		m++;    // V m budu mit odkud mi menu zacina
	}while(idx != number);
	menu_from = m-1;
	m = 0;
	while(idx == number){  // Najdu kolik ma menu polozek
		number = 0; 	
  	m++;    // V m budu mit kolik ma menu polozek
	  for(i=1; i <= 5; i+=2){
      number = number + (10*(Menu[menu_from + m][i-1]-0x30)+(Menu[menu_from+m][i]-0x30));
		  number <<=2;
 	  }
	}
	menu_number = m;
	if(menu_from)menu_from-=1;
}
/************************************************************************
*                             ---< FindItem>---                         *
*                             Najdu polozku menu                        *
*                   Vyuzito pro zobrayeni cesty v horni liste           *
************************************************************************/        
unsigned int MenuItem(unsigned char cesta){
	
	unsigned int number;
	unsigned char m=0,i;
 
  do{  // Najdu kde je polozka v menu
		number = 0; 	
    for(i=1; i <= 5; i+=2){
      number = number + (10*(Menu[m][i-1]-0x30)+(Menu[m][i]-0x30));
		  number <<=2;
 	  }
		m++;    // V m budu mit odkud mi menu zacina
	}while(cesta != number);
  return(m-1);
}
/***************************************************
*                ---< WriteWayMenu >---            *
*             Napise cestu do horni listy          *
*        Vstup: line - slovo Pr. "ahoj. jak je"    *
***************************************************/
void WriteWayMenu(void)
{
	unsigned int dx = 5;
  unsigned char i,help1,help2 = 0,*text;
	unsigned int MenuId;

	if(zanoreni){                                     
		text =((unsigned char*)&Menu[menu_index[0]-1])+12;  // Napisu prvni text (Numeric, Harmonic ..) 
		while(*text){
		  dx+=WriteCharacter(*text,dx,5,white,blue1,0);
		  text++;
	  }
    for(i=0;i<(zanoreni-1);i++){                 // Napisu cestu
	    dx+=WriteCharacter('-',dx,5,white,blue1,0);
		  dx+=WriteCharacter('>',dx,7,white,blue1,0);
			help1 = 0;
			help1 = menu_index[i] << 6-(i*2);
			help2 |= help1; 
		  MenuId = MenuItem(help2);
   	  text =((unsigned char*)&Menu[MenuId])+11; 
		  while(*text){
		    dx+=WriteCharacter(*text,dx,5,white,blue1,0);
		    text++;
	    }
	  }
		dx+=WriteCharacter('-',dx,5,white,blue1,0);  // Napisu aktualni polozku menu
		dx+=WriteCharacter('>',dx,7,white,blue1,0); 
		text =((unsigned char*)&Menu[menu_from+menu_actual])+12; 
		while(*text){
		  dx+=WriteCharacter(*text,dx,5,white,blue1,0);
		  text++;
	  }
 		DrawBox(dx,0,555-dx,45,blue1);                //Smazu cestu
  }
}
/***********************************************************************
*                              ---< TypSubMenu >---                    *
*                   Zjisti zda aktualni polozka ma submenu             *
*                    Vraci:  0 - Neni submenu                          *
*                            1 - Je submenu                            *
*                            2 - Je param.                             *
***********************************************************************/
unsigned char TypSubMenu(void)
{
   if(!menu_from)return(1);  // Pokud je MainMenu je sub menu vzdy
	 if(' ' == Menu[menu_from+menu_actual][10])return(0);
	 if('~' == Menu[menu_from+menu_actual][10])return(1);
	 if('-' == Menu[menu_from+menu_actual][10])return(2);
	 if('%' == Menu[menu_from+menu_actual][10])return(3);
}
/*************************************************************************
*                           ---< Tlacitaka >---                          *
*                     Obsluha tlacitek pokud neni param.                 *
*************************************************************************/
void Tlacitka(void)
{
	unsigned char IsSubMenu,TypParam;
	
  if(Key){  // Bylo neco stisknuto
	  if(!flag.Param){
	    switch(Key){
	      case KEY_SET:
				  if(!flag.Zoom){
				    if(!flag.Scroll){
			        IsSubMenu = TypSubMenu();  // Zjsitim zda je submenu, neni submenu nebo jestli je parame.
			        if(IsSubMenu == 1){
							  flag.Change = 1;
								menu_index[zanoreni] = menu_actual;
								zanoreni++;
								FindMenu();              // Najdu nove meze menu
								menu_actual = 1;
								flag.NewScreen = 1;
							}
							if(IsSubMenu == 2){        // Je param.
							  flag.Param = 1;
								IdxParamTable = (10*(Menu[menu_from + menu_actual][6]-0x30)+(Menu[menu_from+menu_actual][7]-0x30));	
                if(tab_param[IdxParamTable][5]&0b00010000){  // Je repeat??
									flag.Repeat = 1;
									if(tab_param[IdxParamTable][5]&0b00100000)flag.FastRepeat = 1;  // Je fast repeat???
								}
								ParamMin = tab_edit[tab_param[IdxParamTable][0]][0];
								ParamMax = tab_edit[tab_param[IdxParamTable][0]][1];
								ParamStep= tab_edit[tab_param[IdxParamTable][0]][2];
								if(!tab_param[IdxParamTable][1]) ParamTextFrom = tab_param[IdxParamTable][1]; // Pokud je text tak si ulozim odkud zacina v tabulce param_text
                TypParam = tab_param[IdxParamTable][5];
                if(!(TypParam&0x80)){  // Normalni menu
								  ParamPoloz = tab_adr[IdxParamTable][1];  // ulozim si kolik ma dana polozka polozek v poli
                  switch(tab_adr[IdxParamTable][2]){
									  case 1:ParamAct = (float)(ParamChar[tab_adr[IdxParamTable][0]]); 
										       break;
										case 2:ParamAct = (float)(ParamInt[tab_adr[IdxParamTable][0]]); 
										       break;
										case 3:ParamAct = (float)(ParamFloat[tab_adr[IdxParamTable][0]]); 
										       break;

									}
								}
								else{ // RadioButton menu
								  ParamAct = ParamMin;
								}	
							}
							if(IsSubMenu == 3){        // Scroll
							  max_scroll = (10*(Menu[menu_from + menu_actual][8]-0x30)+(Menu[menu_from+menu_actual][9]-0x30));	
                flag.Scroll = 1; // Scroluju
								menu_index[zanoreni] = menu_actual;
								zanoreni++;
							}
						}
			    }
		      break;
	      case KEY_ESC:
				  if(!flag.Zoom){
			      if(!flag.Scroll){
			        if(zanoreni > 1){
				        flag.Change = 1;
				        zanoreni--;
					  		menu_actual = menu_index[zanoreni];
				        menu_index[zanoreni] = 0;
								FindMenu();              // Najdu nove meze menu
								flag.NewScreen = 1;											
			        }
			        else{
						    if(zanoreni){                     // Je hlavni menu
                  flag.Change = 1;
									zanoreni = 0;
									menu_actual = menu_index[zanoreni];
									menu_index[zanoreni] = 0;
									FindMenu();
									flag.NewScreen = 1;	
								}
							}
			      }
			      else{
						  zanoreni--;
							menu_actual = menu_index[zanoreni];
							menu_index[zanoreni] = 0;
							FindMenu();              // Najdu nove meze menu
							flag.Scroll = 0;         // Scroluju
						}
			    }
					break;
 		    case KEY_UP:
				  if(!flag.Zoom){
			      if(!flag.Scroll){
			        flag.Change = 1;
			        if(menu_actual > 1){
				        menu_actual--;
							}
			        else{
							  menu_actual = menu_number;
							}
			      }
			      else{
						  if(menu_scroll > 0){
							  menu_scroll--;
							}											
						}
			    }
			    else{
					  if(Screen_Zoom <15){
						  Screen_Zoom++;
						}
					}
			  	break;
		    case KEY_DOWN:
				  if(!flag.Zoom){
			      if(!flag.Scroll){
			        flag.Change = 1;
			        if(menu_actual < menu_number){
							  menu_actual++;
							}
		          else menu_actual = 1;
			      }
			      else{
						  if(menu_scroll< max_scroll){
							  menu_scroll++;
							}
						}
		      }
			    else{
					  if(Screen_Zoom > 0){
						  Screen_Zoom--;
						}
					}
				  break;
			  case KEY_ZOOM:
				  if(Menu[menu_from + menu_actual][11] == '#'){ // Je povolen pro polozku zoom??
            flag.Zoom ^=1;
			    }
			    break;							 
			}
		  if(!flag.Scroll){
		    if('%' == Menu[menu_from+menu_actual][10]){
			    max_scroll = (10*(Menu[menu_from + menu_actual][8]-0x30)+(Menu[menu_from+menu_actual][9]-0x30));	
			  }
		  } 
		  Key = 0;  // Obsluha byla provedena smazu 	
	  }
	}
}
/*************************************************************************
*                           ---< KalibrTlacitka >---                     *
*                      Obsluha tlacitek pri kalibraci                    *
*************************************************************************/
void Kalibrace(void)
{
	float mer_val[4];
	float NumberShow;
	unsigned char i,CountCal = 0;
  unsigned char *ee_adr;
	
  Kalibr_array[0] = 1;      
  Kalibr_array[1] = 1;
  Kalibr_array[2] = 1;
  Kalibr_array[3] = 1;
  Kalibr_array[4] = 1;
  Kalibr_array[5] = 1;

  while (flag.Kalibr) {
	  if(Key){
	    switch(Key){
			  case KEY_SET:  CountCal++;
				               if(CountCal>2){  // Posledni cast dokalibrovana konec kalibru
											   flag.Kalibr = 0;
			                   flag.NewScreen = 1;
					  					   flag.Unlock = 0;
												 ee_adr = (unsigned char*)&Kalibr_array[0];
												 eep_another_write(ee_kal_U0,4,ee_adr);	 
												 ee_adr = (unsigned char*)&Kalibr_array[1];
												 eep_another_write(ee_kal_U1,4,ee_adr);
		                 		 ee_adr = (unsigned char*)&Kalibr_array[2];
												 eep_another_write(ee_kal_U2,4,ee_adr);	 
												 ee_adr = (unsigned char*)&Kalibr_array[3];
												 eep_another_write(ee_kal_U3,4,ee_adr);	 
                         //Do eeprom proud
												 ee_adr = (unsigned char*)&Kalibr_array[4];
												 eep_another_write(ee_kal_I0,4,ee_adr);	 
												 ee_adr = (unsigned char*)&Kalibr_array[5];
												 eep_another_write(ee_kal_I1,4,ee_adr);	 
												 ee_adr = (unsigned char*)&Kalibr_array[6];
												 eep_another_write(ee_kal_I2,4,ee_adr);	 
												 ee_adr = (unsigned char*)&Kalibr_array[7];
												 eep_another_write(ee_kal_I3,4,ee_adr);
												 P0_kalibr = Kalibr_array[0]*Kalibr_array[4];
												 P1_kalibr = Kalibr_array[1]*Kalibr_array[5];
												 P2_kalibr = Kalibr_array[2]*Kalibr_array[6];

											 }
											 else{	
				                 CleanScreen(white);
											 }
											 break;
        case KEY_UP:   if(!CountCal){  // Napeti
				                 mer_val[0] = ShowVal[0][0]/Kalibr_array[0];
                         mer_val[1] = ShowVal[0][1]/Kalibr_array[1];
                         mer_val[2] = ShowVal[0][2]/Kalibr_array[2];
							  			   mer_val[3] = ShowVal[0][2]/Kalibr_array[3];
                         ShowVal[0][0] += 0.1;
                         Kalibr_array[0] = ShowVal[0][0]/mer_val[0];
                         Kalibr_array[1] = ShowVal[0][0]/mer_val[1];
                         Kalibr_array[2] = ShowVal[0][0]/mer_val[2];  
                         Kalibr_array[3] = ShowVal[0][0]/mer_val[3];
				               }
						           else{
												 if(CountCal==1){  // Proud
											     mer_val[0] = ShowVal[3][0]/Kalibr_array[0];
                           mer_val[1] = ShowVal[3][1]/Kalibr_array[1];
                           mer_val[2] = ShowVal[3][2]/Kalibr_array[2];
							  			     mer_val[3] = ShowVal[3][2]/Kalibr_array[3];
                           ShowVal[3][0] += 0.1;
                           Kalibr_array[4] = ShowVal[3][0]/mer_val[0];
                           Kalibr_array[5] = ShowVal[3][0]/mer_val[1];
                           Kalibr_array[6] = ShowVal[3][0]/mer_val[2];  
                           Kalibr_array[7] = ShowVal[3][0]/mer_val[3];
												 }
												 else{  // Typ pristroje 
												 }	 
											 }   
			               break;
			  case KEY_DOWN: if(!CountCal){  // Napeti
				                 mer_val[0] = ShowVal[0][0]/Kalibr_array[0];
                         mer_val[1] = ShowVal[0][1]/Kalibr_array[1];
                         mer_val[2] = ShowVal[0][2]/Kalibr_array[2];
							  			   mer_val[3] = ShowVal[0][2]/Kalibr_array[3];
                         ShowVal[0][0] -= 0.1;
                         Kalibr_array[0] = ShowVal[0][0]/mer_val[0];
                         Kalibr_array[1] = ShowVal[0][0]/mer_val[1];
                         Kalibr_array[2] = ShowVal[0][0]/mer_val[2];  
                         Kalibr_array[3] = ShowVal[0][0]/mer_val[3];
				               }
				               else{
												 if(CountCal==1){  // proud
												   mer_val[0] = ShowVal[3][0]/Kalibr_array[0];
                           mer_val[1] = ShowVal[3][1]/Kalibr_array[1];
                           mer_val[2] = ShowVal[3][2]/Kalibr_array[2];
							  			     mer_val[3] = ShowVal[3][2]/Kalibr_array[3];
                           ShowVal[0][0] -= 0.1;
                           Kalibr_array[0] = ShowVal[3][0]/mer_val[0];
                           Kalibr_array[1] = ShowVal[3][0]/mer_val[1];
                           Kalibr_array[2] = ShowVal[3][0]/mer_val[2];  
                           Kalibr_array[3] = ShowVal[3][0]/mer_val[3];
												 }
												 else{  // typ pristroje
												 }
											 }
			                 break;
			  case KEY_ESC:  flag.Kalibr = 0;
			                 flag.NewScreen = 1;
					  					 flag.Unlock = 0;
			                 break;			
		  }
		  Key = 0;  	
	  }
		if(!CountCal){  // napeti
		  for(i=0;i<4;i++){
		    WriteText("U",170,90+i*90,black,white,2);
		    WriteCharacter((unsigned char)i+0x31,218,123+i*90,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
		    WriteCharacter(':',240,90+i*90,black,white,2);  // 0x31 Abych z i dostal cislo ve string  	
        NumberShow = ShowJednotky(500,90+i*90,"V",ShowVal[0][i],black,white,2,0);
		    NumToStr(NumberShow,4,1,0,0,1);
		    WriteText(&cislo[0],280,90+i*90,black,white,2); 
	    }
		}
		else{
			if(CountCal==1){  // Proud
		    for(i=0;i<4;i++){
		      WriteText("I",170,90+i*90,black,white,2);
		      WriteCharacter((unsigned char)i+0x31,200,123+i*90,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
		      WriteCharacter(':',220,90+i*90,black,white,2);  // 0x31 Abych z i dostal cislo ve string  	
          NumberShow = ShowJednotky(500,90+i*90,"A",ShowVal[3][i],black,white,2,0);
		      NumToStr(NumberShow,4,3,0,0,1);
		      WriteText(&cislo[0],280,90+i*90,black,white,2); 
	      }
			}
			else{  // Typ pristroje
			}
		}
	}
}
/************************************************************************
*                           ---< VerifyPassword >---                    *
*                       Kalibrace napeti a proudu                       *
*                 Vstup: password - heslo k overeni                     *
************************************************************************/
void VerifyPassword(unsigned int password)
{
	unsigned char i;
	unsigned int pomocna = 0;
	
  if(Key){  // Bylo neco stisknuto??
    switch(Key){
       case KEY_SET: heslo_ukaz++;
			               if(heslo_ukaz>3){
		  						     for(i=0;i<4;i++){  // Po zadani overim zda jsou stejna hesla
		                     pomocna*=10;
		                   	 pomocna+=heslo[i];
		                   }
									     for(i=0;i<4;i++){  // Jsou zadany 4 cislice pripravim pro dalsi zadavani
                         heslo[i]=0;
	                     }
		                   heslo_ukaz = 0;
											 if(pomocna == password){
			                   CleanScreen(white);
			                   flag.Unlock = 1;
		                   }	 	 
										 }
  		               break;
	  	 case KEY_UP:  if(heslo[heslo_ukaz]<9)heslo[heslo_ukaz]++;
			               else heslo[heslo_ukaz] = 0;
			               break;
			 case KEY_DOWN:if(heslo[heslo_ukaz]>0)heslo[heslo_ukaz]--;
			               else heslo[heslo_ukaz] = 9;
			               break;
			 case KEY_ESC: flag.Kalibr=0;  // Ukonceni zadani vratim se do menu(je jedno jestli ukoncuju pri kalibraci nebo jinde)
			               flag.NewScreen = 1;
										 for(i=0;i<4;i++){ // Pripravim pro pristi zadavani
                       heslo[i]=0;
	                   }
		                 heslo_ukaz = 0;	 
			               break;
		}
		Key = 0;  // obsluha byla provedena
	}
	if(!flag.Unlock){
  	WriteText("Code:",100,200,black,white,2);
	  for(i=0;i<4;i++){
	    if(i == heslo_ukaz){
        WriteCharacter(heslo[i]+0x30,350+40*i,200,red1,white,2);
	    }
	    else{
        WriteCharacter(heslo[i]+0x30,350+40*i,200,black,white,2);
	    }
	  }			
	} 	
}                          	
/*************************************************************************
*                           ---< TlacitkaParam >---                      *
*                     Obsluha tlacitek pokud je param.                   *
*************************************************************************/
void TlacitkaParam(void)
{

  unsigned char *ee_adr;

  if(Key){  // Bylo neco stisknuto
	  switch(Key){
	    case KEY_SET: if(!(tab_param[IdxParamTable][5]&0x80)){  // Normalni menu
			                switch(tab_adr[IdxParamTable][1]){
											  case 1:ParamChar[tab_adr[IdxParamTable][0]]= (unsigned char)ParamAct;
												       ee_adr = (unsigned char*)&ParamChar[tab_adr[IdxParamTable][0]];
												       eep_another_write(tab_adr[IdxParamTable][3],1,ee_adr);
															 break;
											  case 2:ParamInt[tab_adr[IdxParamTable][0]] = (unsigned int)ParamAct; 
												       ee_adr = (unsigned char*)&ParamInt[tab_adr[IdxParamTable][0]];
												       eep_another_write(tab_adr[IdxParamTable][3],2,ee_adr);	 
															 break;
												case 3:ParamFloat[tab_adr[IdxParamTable][0]]= ParamAct; 
												       ee_adr = (unsigned char*)&ParamFloat[tab_adr[IdxParamTable][0]];
												       eep_another_write(tab_adr[IdxParamTable][3],4,ee_adr);	 
													     break;
											}
											flag.Param = 0;
  			              flag.ParamEnd = 1; // Skoncila param. Slouzi k naprave skod na LCD po param.
											flag.Repeat = 0;
  										flag.FastRepeat = 0;
			              }
										else{
											if(!(tab_param[IdxParamTable][5]&0x40)){
                        ParamChar[tab_adr[IdxParamTable][0]] ^= 0x80>>(char)(ParamAct);
  										}
											else{
												ParamChar[tab_adr[IdxParamTable][0]] = 0;
                        ParamChar[tab_adr[IdxParamTable][0]] ^= 0x80>>(char)(ParamAct);
											} 
									  }
				            break;
		  case KEY_ESC: flag.Param = 0;  // Jdu z param.
			              flag.ParamEnd = 1; // Skoncila param. Slouzi k naprave skod na LCD po param.
										flag.Repeat = 0;
										flag.FastRepeat = 0;
			          	  break;
		  case KEY_UP:  if(!(tab_param[IdxParamTable][5]&0x80)){
			                if(ParamAct+ParamStep*estep < ParamMax)ParamAct+=ParamStep*estep;
											else ParamAct = ParamMax;
			              }
			              else{
										  if(ParamAct > ParamMin)ParamAct-=ParamStep;	
										}  
			              break;
		  case KEY_DOWN: if(!(tab_param[IdxParamTable][5]&0x80)){
			                 if(ParamAct-ParamStep*estep > ParamMin)ParamAct-=ParamStep*estep;
											 else ParamAct = ParamMin;
			               }
			               else{
											 if(ParamAct < ParamMax)ParamAct+=ParamStep;
										 } 
			              break;
		}
		Key = 0;  // Obsluha byla provedena smazu 	
	}
}
/************************************************************************
*                         ---< Zobraz >---                              *
*              Zobrazeni menu a jednotlivych obrazovek                  *
************************************************************************/
void Zobraz(void)
{
	unsigned char i,m=0,j;     // pocet fazi pro vykreslovani
	unsigned int Delka,BeginRozsah,TextFrom,color;   
  float NumberShow,Zoom,Step_Zoom,HranaRoz;
	float hodnota,MaxVol=0,MaxCur=0;
  

  if(flag.Change){  // Cesta v horni liste
	  menu_scroll = 0;  // pro nvou obrazovku nastavim def. hodnotu scroolu
	  Screen_Zoom = 0;  // pro nvou obrazovku nastavim def. hodnotu zoomu
    WriteWayMenu();
		flag.Scope = 0;
		for(i=0;i<8;i++){
			PoleRozsahu[i] = 0;
		}
	}
  switch(menu_index[0]){
    case 0:
		  if(flag.NewScreen){  // Main Menu
			  CleanScreen(white);
			  DrawBox(0,0,555,45,blue1);  //Smazu cestu
				WriteText("MainMenu",5,5,white,blue1,0);
				LoadMainMenu(menu_actual);  // Nahraju ikony menu
		  }
		  if(flag.Change){
		    ChangeMenu(menu_actual);    // Change menu
			}
    break;                 
		case NUMERIC:          // Numeric
		 	  switch(menu_actual){
					case 1:if(flag.Change){  // Prehled
								   CleanScreen(white);
									 DrawBox(0,45,640,55,blue2);
									 DrawBox(0,100,110,380,blue2);
									 for(i=0;i<3;i++){
									   WriteText("L ",190+i*170,55,black,blue2,0);
										 WriteCharacter((unsigned char)i+0x31,210+i*170,60,black,blue2,0);  // 0x31 Abych z i dostal cislo ve string 
          				 }
	                 WriteText("L-N",15,105,black,blue2,0);  
									 WriteText("L-L",15,140,black,blue2,0);  
									 WriteText("Proud",15,175,black,blue2,0);  
									 WriteText("THDU",15,210,black,blue2,0);
									 WriteText("THDI",15,245,black,blue2,0);
									 WriteText("Cosõ",15,280,black,blue2,0);
									 WriteText("P",15,315,black,blue2,0);
									 WriteText("Q",15,350,black,blue2,0);
									 WriteText("S",15,385,black,blue2,0);
									 WriteText("Freq",15,435,black,blue2,0);
								 } 
								 for(i = 0; i < 3;i++){
								   NumberShow = ShowJednotky(225+i*170,105,"V",ShowVal[0][i],black,white,0,0);  //L-N
									 NumToStr(NumberShow,3,0,0,0,1);
									 WriteText(&cislo[0],155+i*170,105,black,white,0);
											
									 NumberShow = ShowJednotky(225+i*170,140,"V",ShowVal[1][i],black,white,0,0);  //L-L
									 NumToStr(NumberShow,3,0,0,0,1);
									 WriteText(&cislo[0],155+i*170,140,black,white,0);
	
									 NumberShow = ShowJednotky(225+i*170,175,"A",ShowVal[3][i],black,white,0,0);  //Proud                    //Proud
									 if(NumberShow >= 100){
									   NumToStr(NumberShow,2,0,0,0,1);
										 WriteText(&cislo[0],173+i*170,175,black,white,0);
									 }
									 else{
									   NumToStr(NumberShow,3,1,0,0,1);
										 WriteText(&cislo[0],163+i*170,175,black,white,0);
									 }

									 WriteCharacter('%',225+i*170,210,black,white,0);                    // THDU
  								 NumToStr(ShowVal[2][i],3,1,0,0,1);                                     
									 WriteText(&cislo[0],163+i*170,210,black,white,0);
										
									 WriteCharacter('%',225+i*170,245,black,white,0);                    // THDI
									 NumToStr(ShowVal[5][i],3,1,0,0,1);                                     
									 WriteText(&cislo[0],163+i*170,245,black,white,0);

                   if(ShowVal[3][i]!= 0){                                              // cos(fi) 
									   NumToStr(ShowVal[6][i],3,2,0,0,1);
										 WriteText(&cislo[0],180+i*170,280,black,white,0);
									 }
									 else{
									   WriteText("  -,--  ",165+i*170,280,black,white,0);
									 }
											
									 NumberShow = ShowJednotky(225+i*170,315,"W",ShowVal[110][i],black,white,0,0);  // P
									 if(fabs(NumberShow) >= 100){
									   NumToStr(NumberShow,2,0,0,0,1);
										 WriteText(&cislo[0],173+i*170,315,black,white,0);
									 }
									 else{
									   NumToStr(NumberShow,3,1,0,0,1);
										 WriteText(&cislo[0],163+i*170,315,black,white,0);
									 }
											
									 NumberShow = ShowJednotky(225+i*170,350,"VAr",ShowVal[111][i],black,white,0,0); // Q
									 if(NumberShow != 0){  // Pokud je 0 nic nezobrazuju
									   if(fabs(NumberShow) >= 100){
										   NumToStr(NumberShow,3,0,0,0,1);
											 if(NumberShow > 0){
											   cislo[0]='ã';
											 }
											 else{
											   cislo[0]='â';
											 }
											 WriteText(&cislo[0],155+i*170,350,black,white,0);
										 }
										 else{
										   NumToStr(NumberShow,4,1,0,0,1);
											 if(NumberShow > 0){
											   cislo[0]='ã';
											 }
											 else{
											   cislo[0]='â';
											 }
											 DrawBox(145+i*170,350,10,20,white); // znak pro rozsah >=100;
											 WriteText(&cislo[0],145+i*170,350,black,white,0);
										 } 
									 }
									 else{
									   WriteText("    0,0",145+i*170,350,black,white,0);
									 }
											
									 NumberShow = ShowJednotky(225+i*170,385,"VA",ShowVal[109][i],black,white,0,0);  // S
									 if(NumberShow >= 100){
									   NumToStr(NumberShow,3,0,0,0,1);
										 WriteText(&cislo[0],155+i*170,385,black,white,0);
									 }
									 else{
									   NumToStr(NumberShow,3,1,0,0,1);
										 WriteText(&cislo[0],163+i*170,385,black,white,0);
									 } 
								 }
								 WriteText("Hz",225,435,black,white,0);                                 // Frekvence
								 NumToStr(frekvence,3,1,0,0,1);
								 WriteText(&cislo[0],163,435,black,white,0);
  				       break;
					
					 
				  case 2: if(flag.Change){  // L-N
									   CleanScreen(white);
										 for(i=0;i<4;i++){
										   TextFrom = WriteTextB("U",50,90+i*90,black,white,2);
											 TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,123+i*90,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*90,black,white,2); 
                       WriteText("Max:",425,91+i*90,black,white,4);
                       WriteText("Min:",425,113+i*90,black,white,4);
                       WriteText("Avg:",425,135+i*90,black,white,4);

										 }	
  								 }
									 m=0;
									 if(ParamChar[Typ_U]!=4){
									   for(i = 0; i <PocFazU[ParamChar[Typ_U]];i++){
										   NumberShow = ShowJednotky(0,0,"V",ShowVal[0][i],0,0,2,2);  // Vrati cislo v radu
                       ShowNumber(311,90+i*90,134,NumberShow,0,black,white,2,0,4);
  								     TextFrom = ShowJednotky(311,90+i*90,"V",ShowVal[0][i],black,white,2,1);    // Zobrazi jednotky a rekne odkud psat
  								     DrawBox(TextFrom,100+i*90,415-TextFrom,72,white);
	                     //---<Min,Max, Avg >---
										   // Max
  								    MaxMinAvg(490,91+i*90,"V",ShowVal[0][i],black,white,0,4);
                       // Min
  								     MaxMinAvg(490,113+i*90,"V",MinVal[0][i],black,white,0,4);
                       // AVG
  								     MaxMinAvg(490,135+i*90,"V",MinVal[0][i],black,white,0,4);
										   m++;
										 }
									 }
									 for(i = m; i < 4;i++){
                     ShowNumber(311,90+i*90,134,NumberShow,0,black,white,2,1,4);
  								   TextFrom = WriteTextB("V",311,90+i*90,black,white,2);    // Zobrazi jednotky a rekne odkud psat
  								   DrawBox(TextFrom,90+i*90,415-TextFrom,72,white);
	                   //---<Min,Max, Avg >---
										 // Max
    								 MaxMinAvg(490,91+i*90,"V",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(490,113+i*90,"V",MinVal[0][i],black,white,1,4);
                     // AVG
  								   MaxMinAvg(490,135+i*90,"V",MinVal[0][i],black,white,1,4);
									 }
	                 break; 
				  case 3:  if(flag.Change){  // L-L
									   CleanScreen(white);
									   for(i=0;i<3;i++){
									     TextFrom = WriteTextB("U",50,90+i*90,black,white,2);
										   TextFrom = WriteTextB((unsigned char *)&Ozn_USdruz[i][0],TextFrom,123+i*90,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*90,black,white,2); 
                       WriteText("Max:",460,91+i*90,black,white,4);
                       WriteText("Min:",460,113+i*90,black,white,4);
                       WriteText("Avg:",460,135+i*90,black,white,4);
									   }
									   TextFrom = WriteTextB("Fr:",78,90+3*90,black,white,2);
									   WriteText("Hz",342,90+3*90,black,white,2);  // Jednotky se nemeni proto je napisu uz zde
  								 }
									 m=0;
								   for(i = 0; i <	PocFazUSd[ParamChar[Typ_U]];i++){
									   NumberShow = ShowJednotky(0,0,"V",ShowVal[0][i],0,0,2,2);  // Vrati cislo v radu
                     ShowNumber(342,90+i*90,165,NumberShow,0,black,white,2,0,4);
 								     TextFrom = ShowJednotky(342,90+i*90,"V",ShowVal[0][i],black,white,2,1);    // Zobrazi jednotky a rekne odkud psat
 								     DrawBox(TextFrom,100+i*90,446-TextFrom,72,white);
                     //---<Min,Max, Avg >---
  									 // Max
  								   MaxMinAvg(525,91+i*90,"V",ShowVal[0][i],black,white,0,4);
                     // Min
  								   MaxMinAvg(525,113+i*90,"V",MinVal[0][i],black,white,0,4);
                     // AVG
  								   MaxMinAvg(525,135+i*90,"V",MinVal[0][i],black,white,0,4);
										 m++;
									 }
									 //---< Frekvence >---	
									 NumToStr(ShowVal[8][1],3,1,0,0,1);
									 TextFrom = WriteTextAligR(&cislo[0],342,90+3*90,black,white,2);
									 DrawBox(160,90+3*90,TextFrom-160,72,white);	
									 for(i = m; i < 3;i++){
                     ShowNumber(342,90+i*90,165,NumberShow,0,black,white,2,1,4);
  								   TextFrom = WriteTextB("V",342,90+i*90,black,white,2);    // Zobrazi jednotky a rekne odkud psat
  								   DrawBox(TextFrom,90+i*90,446-TextFrom,72,white);
	                   //---<Min,Max, Avg >---
										 // Max
    								 MaxMinAvg(525,91+i*90,"V",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(525,113+i*90,"V",MinVal[0][i],black,white,1,4);
                     // AVG
  								   MaxMinAvg(525,135+i*90,"V",MinVal[0][i],black,white,1,4);
									 }
					         break;
					case 4:  if(flag.Change){  // THDU ShowVal[2][0]
									   CleanScreen(white);
										 for(i=0;i<3;i++){
										   TextFrom = WriteTextB("L",70,90+i*125,black,white,2);
											 TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,123+i*125,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*125,black,white,2); 
                       WriteText("Max:",450,101+i*125,black,white,4);
                       WriteText("Avg:",450,123+i*125,black,white,4);
										 }	
  								 }
								   for(i = 0; i <PocFazU[ParamChar[Typ_U]];i++){
									   NumberShow = ShowJednotky(0,0,"%",ShowVal[0][i],0,0,2,2);  // Vrati cislo v radu
                     ShowNumber(317,90+i*125,144,NumberShow,0,black,white,2,0,4);
 								     TextFrom = ShowJednotky(317,90+i*125,"%",ShowVal[0][i],black,white,2,1);    // Zobrazi jednotky a rekne odkud psat
 								     DrawBox(TextFrom,100+i*125,440-TextFrom,72,white);
                     //---<Max, Avg >---
									   // Max
  							     MaxMinAvg(515,101+i*125,"%",ShowVal[0][i],black,white,0,4);
                     // Min
  							     MaxMinAvg(515,123+i*125,"%",MinVal[0][i],black,white,0,4);
										 m++;
									 }
									 for(i = m; i < 3;i++){
                     ShowNumber(317,90+i*125,144,NumberShow,0,black,white,2,1,4);
  								   TextFrom = WriteTextB("%",317,90+i*125,black,white,2);    // Zobrazi jednotky a rekne odkud psat
  								   DrawBox(TextFrom,90+i*125,440-TextFrom,72,white);
	                   //---<Max, Avg >---
										 // Max
    								 MaxMinAvg(515,101+i*125,"%",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(515,123+i*125,"%",MinVal[0][i],black,white,1,4);
									 }
					         break;
					case 5:  if(flag.Change){  // Proud // ShowVal[3][0]
									   CleanScreen(white);
										 for(i=0;i<4;i++){
										   TextFrom = WriteTextB("I",50,90+i*90,black,white,2);
											 TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,123+i*90,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*90,black,white,2); 
                       WriteText("Max:",425,101+i*90,black,white,4);
                       WriteText("Avg:",425,123+i*90,black,white,4);

										 }	
  								 }
									 m=0;
								   for(i = 0; i <PocFazI[ParamChar[Typ_I]];i++){
									   NumberShow = ShowJednotky(0,0,"A",ShowVal[0][i],0,0,2,2);  // Vrati cislo v radu
                     ShowNumber(282,90+i*90,105,NumberShow,0,black,white,2,0,4);
 								     TextFrom = ShowJednotky(282,90+i*90,"A",ShowVal[0][i],black,white,2,1);    // Zobrazi jednotky a rekne odkud psat
 								     DrawBox(TextFrom,100+i*90,386-TextFrom,72,white);
                     //---<Max, Avg >---
									   // Max
  							     MaxMinAvg(490,101+i*90,"A",ShowVal[0][i],black,white,0,4);
                     // Min
  							     MaxMinAvg(490,123+i*90,"A",MinVal[0][i],black,white,0,4);
									   m++;
									 }
									 for(i = m; i < 4;i++){
                     ShowNumber(282,90+i*90,134,NumberShow,0,black,white,2,1,4);
  								   TextFrom = WriteTextB("A",282,90+i*90,black,white,2);    // Zobrazi jednotky a rekne odkud psat
  								   DrawBox(TextFrom,90+i*90,386-TextFrom,72,white);
	                   //---<Max, Avg >---
										 // Max
    								 MaxMinAvg(490,101+i*90,"A",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(490,123+i*90,"A",MinVal[0][i],black,white,1,4);
									 }
	                 break; 
					case 6:  if(flag.Change){  // THDI ShowVal[5][0]
									   CleanScreen(white);
										 for(i=0;i<3;i++){
										   TextFrom = WriteTextB("L",70,90+i*125,black,white,2);
											 TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,123+i*125,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*125,black,white,2); 
                       WriteText("Max:",450,101+i*125,black,white,4);
                       WriteText("Avg:",450,123+i*125,black,white,4);
										 }	
  								 }
								   for(i = 0; i <PocFazI[ParamChar[Typ_I]];i++){
									   NumberShow = ShowJednotky(0,0,"%",ShowVal[0][i],0,0,2,2);  // Vrati cislo v radu
                     ShowNumber(317,90+i*125,144,NumberShow,0,black,white,2,0,4);
 								     TextFrom = ShowJednotky(317,90+i*125,"%",ShowVal[0][i],black,white,2,1);    // Zobrazi jednotky a rekne odkud psat
 								     DrawBox(TextFrom,100+i*125,440-TextFrom,72,white);
                     //---<Max, Avg >---
									   // Max
  							     MaxMinAvg(515,101+i*125,"%",ShowVal[0][i],black,white,0,4);
                     // Min
  							     MaxMinAvg(515,123+i*125,"%",MinVal[0][i],black,white,0,4);
										 m++;
									 }
									 for(i = m; i < 3;i++){
                     ShowNumber(317,90+i*125,144,NumberShow,0,black,white,2,1,4);
  								   TextFrom = WriteTextB("%",317,90+i*125,black,white,2);    // Zobrazi jednotky a rekne odkud psat
  								   DrawBox(TextFrom,90+i*125,440-TextFrom,72,white);
	                   //---<Max, Avg >---
										 // Max
    								 MaxMinAvg(515,101+i*125,"%",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(515,123+i*125,"%",MinVal[0][i],black,white,1,4);
									 }
					         break;
					case 7:  if(flag.Change){  // CosFi ShowVal[6][0]
									   CleanScreen(white);
										 for(i=0;i<3;i++){
										   TextFrom = WriteTextB("Cos¬",30,90+i*125,black,white,2);
											 TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,123+i*125,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*125,black,white,2); 
                       WriteText("Max:",450,91+i*125,black,white,4);
                       WriteText("Mix:",450,113+i*125,black,white,4);
                       WriteText("Avg:",450,135+i*125,black,white,4);
										 }	
  								 }
								   for(i = 0; i <PocFazU[ParamChar[Typ_U]];i++){
										 if(ShowVal[3][i]!= 0){  // Pokud se proud nerovna 0 zobrazim cos 
                       ShowNumber(408,90+i*125,225,NumberShow,0,black,white,2,0,4);
										 }
										 else{
                       ShowNumber(408,90+i*125,225,NumberShow,0,black,white,2,1,4);  // jinak zobrazim -,--
										 }
                     //---<Max,Min,Avg >---
									   // Max
  							     MaxMinAvg(515,91+i*125,"%",ShowVal[0][i],black,white,0,4);
                     // Min
  							     MaxMinAvg(515,113+i*125,"%",MinVal[0][i],black,white,0,4);
                     // AVG
  							     MaxMinAvg(515,135+i*125,"%",MinVal[0][i],black,white,0,4);
										 m++;
									 }
									 for(i = m; i < 3;i++){
                     ShowNumber(408,90+i*125,225,NumberShow,0,black,white,2,1,4);
	                   //---<Max,Min, Avg >---
										 // Max
    								 MaxMinAvg(515,91+i*125,"%",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(515,113+i*125,"%",MinVal[0][i],black,white,1,4);
                     // AVG
  								   MaxMinAvg(515,135+i*125,"%",MinVal[0][i],black,white,1,4);

									 }
					         break;
					case 8:  if(flag.Change){  // cinny vykon ShowVal[110][0]
									   CleanScreen(white);
										 for(i=0;i<3;i++){
										   TextFrom = WriteTextB("P",50,90+i*125,black,white,2);
											 TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,123+i*125,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*125,black,white,2); 
                       WriteText("Max:",430,101+i*125,black,white,4);
                       WriteText("Avg:",430,123+i*125,black,white,4);
										 }	
  								 }
									 if(PocFazI[ParamChar[Typ_I]]<PocFazU[ParamChar[Typ_U]])m=PocFazI[ParamChar[Typ_I]];  // zjistim kolik mohu zobrazit proudu podle zapojeni napetove a proudove casi
									 else m=PocFazU[ParamChar[Typ_U]];
								   for(i = 0; i < m ;i++){
									   NumberShow = ShowJednotky(0,0,"W",ShowVal[0][i],0,0,2,2);  // Vrati cislo v radu
                     ShowNumber(307,90+i*125,134,NumberShow,0,black,white,2,0,4);
 								     TextFrom = ShowJednotky(307,90+i*125,"W",ShowVal[0][i],black,white,2,1);    // Zobrazi jednotky a rekne odkud psat
 								     DrawBox(TextFrom,100+i*125,430-TextFrom,72,white);
                     //---<Max, Avg >---
									   // Max
  							     MaxMinAvg(495,101+i*125,"W",ShowVal[0][i],black,white,0,4);
                     // Min
  							     MaxMinAvg(495,123+i*125,"W",MinVal[0][i],black,white,0,4);
									 }
									 for(i = m; i < 3;i++){
                     ShowNumber(307,90+i*125,134,NumberShow,0,black,white,2,1,4);
  								   TextFrom = WriteTextB("W",307,90+i*125,black,white,2);    // Zobrazi jednotky a rekne odkud psat
  								   DrawBox(TextFrom,90+i*125,430-TextFrom,72,white);
	                   //---<Max, Avg >---
										 // Max
    								 MaxMinAvg(495,101+i*125,"W",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(495,123+i*125,"W",MinVal[0][i],black,white,1,4);
									 }
					         break;
					case 9:  if(flag.Change){  // zdanlivy vykon ShowVal[109][0]
									   CleanScreen(white);
										 for(i=0;i<3;i++){
										   TextFrom = WriteTextB("S",30,90+i*125,black,white,2);
											 TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,123+i*125,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*125,black,white,2); 
                       WriteText("Max:",440,101+i*125,black,white,4);
                       WriteText("Avg:",440,123+i*125,black,white,4);
										 }	
  								 }
									 if(PocFazI[ParamChar[Typ_I]]<PocFazU[ParamChar[Typ_U]])m=PocFazI[ParamChar[Typ_I]];  // zjistim kolik mohu zobrazit proudu podle zapojeni napetove a proudove casi
									 else m=PocFazU[ParamChar[Typ_U]];
								   for(i = 0; i < m ;i++){
									   NumberShow = ShowJednotky(0,0,"VA",ShowVal[0][i],0,0,2,2);  // Vrati cislo v radu
                     ShowNumber(287,90+i*125,114,NumberShow,0,black,white,2,0,4);
 								     TextFrom = ShowJednotky(287,90+i*125,"VA",ShowVal[0][i],black,white,2,1);    // Zobrazi jednotky a rekne odkud psat
 								     DrawBox(TextFrom,100+i*125,440-TextFrom,72,white);
                     //---<Max, Avg >---
									   // Max
  							     MaxMinAvg(505,101+i*125,"VA",ShowVal[0][i],black,white,0,4);
                     // Min
  							     MaxMinAvg(505,123+i*125,"VA",MinVal[0][i],black,white,0,4);
									 }
									 for(i = m; i < 3;i++){
                     ShowNumber(287,90+i*125,104,NumberShow,0,black,white,2,1,4);
  								   TextFrom = WriteTextB("VA",287,90+i*125,black,white,2);    // Zobrazi jednotky a rekne odkud psat
  								   DrawBox(TextFrom,90+i*125,440-TextFrom,72,white);
	                   //---<Max, Avg >---
										 // Max
    								 MaxMinAvg(505,101+i*125,"VA",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(505,123+i*125,"VA",MinVal[0][i],black,white,1,4);
									 }
					         break;	
					case 10:/* if(flag.Change){  // jal vykon ShowVal[111][0]
									   CleanScreen(white);
										 for(i=0;i<3;i++){
										   TextFrom = WriteTextB("Q",10,90+i*125,black,white,2);
											 TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,123+i*125,black,white,0);  // 0x31 Abych z i dostal cislo ve string  	
                       TextFrom = WriteCharacterB(':',TextFrom,90+i*125,black,white,2); 
                       WriteText("Max:",505,101+i*125,black,white,4);
                       TextFrom = WriteTextB("Avg:",505,123+i*125,black,white,4);
										 }	
  								 }
									 if(PocFazI[ParamChar[Typ_I]]<PocFazU[ParamChar[Typ_U]])m=PocFazI[ParamChar[Typ_I]];  // zjistim kolik mohu zobrazit proudu podle zapojeni napetove a proudove casi
									 else m=PocFazU[ParamChar[Typ_U]];
								   for(i = 0; i < m ;i++){
									   NumberShow = ShowJednotky(0,0,"VA",ShowVal[0][i],0,0,2,2);  // Vrati cislo v radu
                     ShowNumber(337,90+i*125,154,NumberShow,0,black,white,2,0,4);
 								     TextFrom = ShowJednotky(337,90+i*125,"VAr",ShowVal[0][i],black,white,2,1);    // Zobrazi jednotky a rekne odkud psat
 								     DrawBox(TextFrom,100+i*125,502-TextFrom,72,white);
                     //---< Kapacita,Indukce, nic >---
										 if(ShowVal[111][i] != 0){  // Pokud je 0 nic nezobrazuju
										   if(ShowVal[111][i] > 0){ // Je odber nebo dodavka
											   WriteCharacter('â',117,90+i*125,black,white,2);  // kondik
										   }
										   else{
											   WriteCharacter('ã',117,90+i*125,black,white,2);  // civka
										   }
								     }
									   else{
									     DrawBox(117,90+i*125,37,72,white);
									   }
                     //---<Max, Avg >---
									   // Max
  							     MaxMinAvg(553,101+i*125,"VAr",ShowVal[0][i],black,white,0,4);
                     // Min
  							     MaxMinAvg(553,123+i*125,"VAr",MinVal[0][i],black,white,0,4);
									 }
									 for(i = m; i < 3;i++){
                     ShowNumber(337,90+i*125,154,NumberShow,0,black,white,2,1,4);
  								   TextFrom = WriteTextB("VAr",337,90+i*125,black,white,2);    // Zobrazi jednotky a rekne odkud psat
  								   DrawBox(TextFrom,90+i*125,502-TextFrom,72,white);
	                   //---<Max, Avg >---
										 // Max
    								 MaxMinAvg(553,101+i*125,"VAr",ShowVal[0][i],black,white,1,4);
                     // Min
  								   MaxMinAvg(553,123+i*125,"VAr",MinVal[0][i],black,white,1,4);
									 }*/
					         break;
					case 11:if(flag.Change){  // Celkovy vykon
						        CleanScreen(white);
										WriteText("ËP:",110,90,black,white,2);
										WriteText("ËQ:",110,215,black,white,2);
										WriteText("ËS:",110,340,black,white,2);
									}	 
									NumberShow = ShowJednotky(450,90,"W",ShowVal[114][1],black,white,2,0);
							    NumToStr(NumberShow,5,1,1,0,1);
									WriteText(&cislo[0],245,90,black,white,2);
									NumberShow = ShowJednotky(450,215,"VAr",ShowVal[113][1],black,white,2,0);
									NumToStr(NumberShow,4,1,0,0,1);
									if(NumberShow != 0){  // Pokud je 0 nic nezobrazuju
									  if(NumberShow > 0){ // Je odber nebo dodavka
									    WriteCharacter('â',220,215,black,white,2);  // kondik
										}
										else{
									    WriteCharacter('ã',220,215,black,white,2);  // civka
										}
									}
									else{
									  WriteCharacter('ü',220,215,black,white,2);
									}
									WriteText(&cislo[0],270,215,black,white,2);
									NumberShow = ShowJednotky(450,340,"VA",ShowVal[115][1],black,white,2,0);
									NumToStr(NumberShow,4,1,0,0,1);
									WriteText(&cislo[0],270,340,black,white,2);
	                break;
				  case 12:ShowHarmonic(10,9,0);
					  			break;	
				  case 13:ShowHarmonic(10,9,1);
					  			break;
				  case 14:ShowHarmonic(10,9,2);
				    			break;	
				  case 15:ShowHarmonic(60,59,0);
					  			break;	
				  case 16:ShowHarmonic(60,59,1);
						  		break;	
			    case 17:ShowHarmonic(60,59,2);
					  			break;
		    }	
		break;
		case HARMONIC:
		  switch(menu_actual){
			  case 1: if(flag.Change){  // Prehled U
	                CleanScreen(white);
		              DrawAxisXT2(70,355,520,11,18);
		              DrawAxisY(55,69,290,11);
									for(i=0;i<3;i++){
		                WriteText("[%]",610,385+i*18,ColorPhase[i],white,3);
										TextFrom = WriteTextB("L",20,385+i*18,ColorPhase[i],white,3);
										TextFrom = WriteCharacter((unsigned char)i+0x31,TextFrom,385+i*18,ColorPhase[i],white,3);
									}
		              Screen_Zoom = 9; // Vychozi hodnota pro zoom
	              }
			         	// Zoom
               	if(Screen_Zoom == 0){
	                Zoom = 2.85;  // 100%
		              for(i=1;i<11;i++){
		                NumToStr(10*i,2,0,0,0,1);
			              TextFrom = WriteTextB(&cislo[0],10,60+(10-i)*29,black,white,3);
			              DrawBox(TextFrom,60+(10-i)*29,45-TextFrom,16,white);
		              }
	              }
	              else{
	                if(Screen_Zoom<=9){
		                Step_Zoom = (100-Screen_Zoom*10);
			              Zoom = 285/Step_Zoom;
			              for(i=1;i<11;i++){
			                NumToStr((Step_Zoom/10)*i,2,0,0,0,1);
				              TextFrom = WriteTextB(&cislo[0],10,60+(10-i)*29,black,white,3);
  			              DrawBox(TextFrom,60+(10-i)*29,45-TextFrom,16,white);
  		              }
		              }
		              else{
		                if(Screen_Zoom<=13){
		                  Step_Zoom = (10-(2*(Screen_Zoom-9)));
				              Zoom = 285/Step_Zoom;
				              for(i=1;i<11;i++){
				                NumToStr((Step_Zoom/10)*i,3,1,0,0,1);
					              TextFrom = WriteTextB(&cislo[0],5,60+(10-i)*29,black,white,3);
    			              DrawBox(TextFrom,60+(10-i)*29,45-TextFrom,16,white);
				              }
			              }
			              else{
  		                Step_Zoom = (2-(0.5*(Screen_Zoom-13)));
				              Zoom = 285/Step_Zoom;
	  	                for(i=1;i<11;i++){
				                NumToStr((Step_Zoom/10)*i,4,2,0,0,1);
					              TextFrom = WriteTextB(&cislo[0],2,60+(10-i)*29,black,white,3);
     			              DrawBox(TextFrom,60+(10-i)*33,45-TextFrom,16,white);
				              }
			              }	
		              }						 
	              }
                if(flag.Zoom){
	                ShowZoom(600,70,1,Screen_Zoom);
		              ScrollV(max_scroll,menu_scroll,2);  // Je zoom scroll neaktivni
	              }
	              else{
                  ShowZoom(600,70,0,Screen_Zoom);     // Neaktivni zoom
  	              if(flag.Scroll){                    // Neaktivni zoom povoluje se scroll
  	                ScrollV(max_scroll,menu_scroll,1);
	                }
		              else{
		                ScrollV(max_scroll,menu_scroll,0);
		              }
                }
				        for(i=menu_scroll*2;i<11+menu_scroll*2;i++){
									for(j=0;j<3;j++){
									  if((ShowVal[9+i][j]*Zoom)< 285){  // Zobrazuju sloupce
	                    DrawBox((70+7*j)+m*50.2,70,6,285-(ShowVal[9+i][j]*Zoom),white);
		                  DrawBox((70+7*j)+m*50.2,355-(ShowVal[9+i][j]*Zoom),6,ShowVal[9+i][j]*Zoom,ColorPhase[j]);
										}
									  else{
		                  DrawBox((70+7*j)+m*50.2,70,6,284,black);
		                }
									}
		              //--- Ocisluju osu X
                  NumToStr((i+2),1,0,0,0,1);
                  if(i+2<10){
		                TextFrom = WriteTextB(&cislo[0],66+m*50.35,370,black,white,3);
		 	              DrawBox(TextFrom,370,5,16,white);
		              }
		              else{
		                WriteText(&cislo[0],71+m*50.4,370,black,white,3);
		              }	
	                for(j=0;j<3;j++){
										NumToStr(ShowVal[9+i][j],4,2,0,0,1);
		                if(ShowVal[9+i][j] < 10){
		                  WriteText(&cislo[0],53+m*51,385+j*18,ColorPhase[j],white,3);
                    }
		                else{
	                    WriteText(&cislo[0],60+m*51,385+j*18,ColorPhase[j],white,3);
                    }
									}	
                  m++;
	              }
			          break;
				case 2: ZoomHarmVol(0); // Harm U1
						    break;
				case 3: ZoomHarmVol(1); // Harm U2
						    break;
				case 4:ZoomHarmVol(2);  // Harm U3
				       break;
				case 5:if(flag.Change){  // Prehled I
	                CleanScreen(white);
		              DrawAxisXT2(70,355,520,11,18);
		              DrawAxisY(55,69,290,11);
									for(i=0;i<3;i++){
		                WriteText("[%]",610,385+i*18,ColorPhase[4+i],white,3);
										TextFrom = WriteTextB("L",20,385+i*18,ColorPhase[4+i],white,3);
										TextFrom = WriteCharacter((unsigned char)i+0x31,TextFrom,385+i*18,ColorPhase[4+i],white,3);
									}
		              Screen_Zoom = 5; // Vychozi hodnota pro zoom
	              }
			         	// Zoom
 	              if(Screen_Zoom == 0){
	                Zoom = 1.083;  // 300%
		              for(i=1;i<11;i++){
		                NumToStr(30*i,2,0,0,0,1);
			              TextFrom = WriteTextB(&cislo[0],13,60+(10-i)*33,black,white,3);
			              DrawBox(TextFrom,60+(10-i)*33,45-TextFrom,16,white);
		              }
	              }
	              else{
	                if(Screen_Zoom<=5){
		                Step_Zoom = (300-Screen_Zoom*40);
			              Zoom = 325/Step_Zoom;
			              for(i=1;i<11;i++){
			                NumToStr((Step_Zoom/10)*i,3,0,0,0,1);
				              TextFrom = WriteTextB(&cislo[0],5,60+(10-i)*33,black,white,3);
  			              DrawBox(TextFrom,60+(10-i)*33,45-TextFrom,16,white);
  		              }
		              }
		              else{
		                if(Screen_Zoom<=11){
		                  Step_Zoom = (100-(15*(Screen_Zoom-5)));
				              Zoom = 325/Step_Zoom;
				              for(i=1;i<11;i++){
				                NumToStr((Step_Zoom/10)*i,3,1,0,0,1);
					              TextFrom = WriteTextB(&cislo[0],10,60+(10-i)*33,black,white,3);
    			              DrawBox(TextFrom,60+(10-i)*33,45-TextFrom,16,white);
				              }
			              }
			              else{
  		                Step_Zoom = (10-(2.25*(Screen_Zoom-11)));
				              Zoom = 325/Step_Zoom;
	  	                for(i=1;i<11;i++){
				                NumToStr((Step_Zoom/10)*i,4,2,0,0,1);
					              TextFrom = WriteTextB(&cislo[0],2,60+(10-i)*33,black,white,3);
     			              DrawBox(TextFrom,60+(10-i)*33,45-TextFrom,16,white);
				              }
			              }	
		              }						 
	              }
                if(flag.Zoom){
	                ShowZoom(600,70,1,Screen_Zoom);
		              ScrollV(max_scroll,menu_scroll,2);  // Je zoom scroll neaktivni
	              }
	              else{
                  ShowZoom(600,70,0,Screen_Zoom);     // Neaktivni zoom
  	              if(flag.Scroll){                    // Neaktivni zoom povoluje se scroll
  	                ScrollV(max_scroll,menu_scroll,1);
	                }
		              else{
		                ScrollV(max_scroll,menu_scroll,0);
		              }
                }
				        for(i=menu_scroll*2;i<11+menu_scroll*2;i++){
									for(j=0;j<3;j++){
									  if((ShowVal[59+i][j]*Zoom)< 285){  // Zobrazuju sloupce
	                    DrawBox((70+7*j)+m*50.2,70,6,285-(ShowVal[59+i][j]*Zoom),white);
		                  DrawBox((70+7*j)+m*50.2,355-(ShowVal[59+i][j]*Zoom),6,ShowVal[59+i][j]*Zoom,ColorPhase[4+j]);
										}
									  else{
		                  DrawBox((70+7*j)+m*50.2,70,6,284,black);
		                }
									}
		              //--- Ocisluju osu X
                  NumToStr((i+2),1,0,0,0,1);
                  if(i+2<10){
		                TextFrom = WriteTextB(&cislo[0],66+m*50.35,370,black,white,3);
		 	              DrawBox(TextFrom,370,5,16,white);
		              }
		              else{
		                WriteText(&cislo[0],71+m*50.4,370,black,white,3);
		              }	
	                for(j=0;j<3;j++){
										NumToStr(ShowVal[59+i][j],4,2,0,0,1);
		                if(ShowVal[59+i][j] < 10){
		                  WriteText(&cislo[0],53+m*51,385+j*18,ColorPhase[4+j],white,3);
                    }
		                else{
	                    WriteText(&cislo[0],60+m*51,385+j*18,ColorPhase[4+j],white,3);
                    }
									}	
                  m++;
	              }break;
				case 6: ZoomHarmCur(0);  //Harm I1
						    break;
				case 7: ZoomHarmCur(1); // Harm I2
						    break;
				case 8: ZoomHarmCur(2); // Harm I3
						    break;			
			}
		break;
//---------------------------------------------------------------------------------		
		case VECTOR: 
		        if(flag.Change){	
			        CleanScreen(white);
							for(i=0;i<6;i++){
							  dx[i][0] = 0;
								dy[i][0] = 0;
                TextX[i][0] = 0; 
		            TextY[i][0] = 0;
							}
  						DrawBox(0,45,225,435,blue2);
              WriteText("0°",620,255,black,white,3);
              WriteText("120°",315,425,black,white,3);
              WriteText("240°",315,85,black,white,3);
							for(i=0;i<3;i++){
							  TextFrom = WriteTextB("L",5,90+i*80,black,blue2,4);
								TextFrom += WriteCharacter((unsigned char)i+0x31,TextFrom+2,90+i*80,black,blue2,4);  // 0x31 Abych z i dostal cislo ve string
								WriteCharacter(':',TextFrom+2,90+i*80,black,blue2,4);  // 0x31 Abych z i dostal cislo ve string
                WriteCharacter('°',90,115+i*80,ColorPhase[i],blue2,4);
                WriteText("Cos:",130,120+i*80,ColorPhase[i+4],blue2,3);
 							}
						  WriteText("U",60,60,black,blue2,4);
							WriteText("I",175,60,black,blue2,4);							
						  WriteText("U:",555,430,black,white,3);
							WriteText("I:",560,450,black,white,3);
		        }
		      if(flag.Show){
   //---< Najdu MAxima napeti a proudu pro zobrazeni vektoru >------
				    for(i=0;i<3;i++){  // Pro rozsah vektoru
						  if(MaxVol < ShowVal[0][i])MaxVol = ShowVal[0][i];
							if(MaxCur < ShowVal[3][i])MaxCur = ShowVal[3][i];
						}			
  //-----------< Zobrazeni hodnot v pravem modrem pruhu >---------------						 
						for(i=0;i<3;i++){
							// Zobrazeni napeti
              PoleVector[i] = ShowJednotky(85,90+i*80,"V",ShowVal[0][i],ColorPhase[i],blue2,4,0);
						  NumToStr(PoleVector[i],2,0,0,0,1);
							WriteText(&cislo[0],45,90+i*80,ColorPhase[i],blue2,4);

							// Zobrazeni proudu
							PoleVector[i+3] = ShowJednotky(190,90+i*80,"A",ShowVal[3][i],ColorPhase[i+4],blue2,4,0);
						  NumToStr(PoleVector[i+3],3,1,0,0,1);
							WriteText(&cislo[0],150,90+i*80,ColorPhase[i+4],blue2,4);		

              // Uhel napeti
    				  NumberShow = asin(ShowVal[121][i])*57.29577951;
              if(ShowVal[120][i] <= 0)NumberShow -=180;
							if((ShowVal[121][i]<0) && (ShowVal[120][i] > 0))NumberShow+=360;
							if(NumberShow == 360)NumberShow = 0;
              NumToStr(fabs(NumberShow),4,1,0,0,1);
							WriteText(&cislo[0],27,115+i*80,ColorPhase[i],blue2,4);	

							// Uhel proudu
							if(ShowVal[3][i]!= 0){  // Pokud se proud nerovna 0 zobrazim cos 
							  NumToStr(ShowVal[6][i],3,2,0,0,1);
								WriteText(&cislo[0],163,115+i*80,ColorPhase[i+4],blue2,4);
							}
							else{
							  TextFrom = WriteTextB("-,--",163,115+i*80,ColorPhase[i+4],blue2,4);
								DrawBox(TextFrom,115+i*80,(225-TextFrom),25,blue2);
							}
						}
//---------------< Rozsah Napeti >--------------------- 
					  ShowJednotky(580,45,"V",MaxVol,white,white,4,0);  // Jednotky
			      HranaRoz = 10;
            for(i=0;i<5;i++){
						  if(MaxVol>(HranaRoz*100)){
								HranaRoz*=10;
							}
						}
						HranaRoz*=3; 
					  if(MaxVol > HranaRoz){  // Najdu mez osy
              while(MaxVol>PoleRozsahu[0]){
                PoleRozsahu[0] += HranaRoz;
	            }
		          while(MaxVol<(PoleRozsahu[0]-(HranaRoz*2))){ // Musim porovnavat se spodni hranou okna proto 40!!!
		            PoleRozsahu[0] -= HranaRoz;
		          }
						  for(i=0;i<3;i++){  // Odectu rozsahy od nam. hodnot  
				        PoleVector[i]= ShowVal[0][i]*((float)159/PoleRozsahu[0]);  // Prumer kol - 6 (Aby rozsah koncil s kolem)
							}	
	          }
            else{// Pokud je mensi nez 50 nebo 0
						  for(i=0;i<3;i++){
						    PoleVector[i]*=5.5;
							  PoleRozsahu[0] = 30;
							}
	          }
//------------< Rozsah proudu >----------------------
	  				ShowJednotky(580,45,"A",MaxCur,white,white,4,0);  // Jednotky
			      hodnota = MaxVol;
            HranaRoz = 1;
            for(i=0;i<5;i++){
						  if(MaxVol>(HranaRoz*100)){
								HranaRoz*=10;
							}
						}
						HranaRoz*=3; 
						if(MaxCur > 3){  // Najdu mez osy
              while(MaxCur>PoleRozsahu[1]){
                PoleRozsahu[1] += 3;
	            }
		          while(MaxCur<(PoleRozsahu[1]-6)){ // Musim porovnavat se spodni hranou okna proto 40!!!
		            PoleRozsahu[1] -= 3;
		          }
							for(i=0;i<3;i++){
						    PoleVector[i+3] = ShowVal[3][i]*((float)159/PoleRozsahu[1]);						
							}
	          }
            else{// Pokud je mensi nez 50 nebo 0
						  for(i=0;i<3;i++){
						    PoleVector[i+3]*=55;
							  PoleRozsahu[1]=3;
							}
	          }
						//--< Zobrazeni meritka napeti >---
						 hodnota = ShowJednotky(580,45,"V",PoleRozsahu[0],white,white,4,2);  // Jednotky
						 NumToStr((hodnota/3),2,0,0,0,1);
						 WriteText(&cislo[0],570,430,black,white,3);
						 TextFrom = ShowJednotky(597,430,"V",MaxVol,black,white,3,1);  // Jednotky
						 WriteText("/div",TextFrom,430,black,white,3);						 
            
						//---< Zobrazeni meritka proudu >----
						 NumToStr((PoleRozsahu[1]/3),2,0,0,0,1);
						 WriteText(&cislo[0],570,450,black,white,3);
						 TextFrom = ShowJednotky(597,450,"A",MaxCur,black,white,3,1);  // Jednotky
						 WriteText("/div",TextFrom,450,black,white,3);
             DrawLineEnd(430,262,ColorPhase[1]);  // Kresleni diagramu
					}
					  break;
		case BARGRAPH:    //bargraph
		  switch(menu_actual){
			  case 1:if(flag.TriFaze){  // L-N
						     if(flag.Change){
								   CleanScreen(white);
								   for(i=0;i<3;i++){
	                  TextFrom = WriteTextB("U",15,85+i*120,black,white,1);
									 }
									 WriteText("1-2",TextFrom,100,black,white,0);
									 WriteText("2-3",TextFrom,220,black,white,0);
									 WriteText("3-1",TextFrom,340,black,white,0);
   							 }
							   for(i=0;i<3;i++){
						       Delka = OsaX(110,120+i*120,450,"V",ShowVal[0][i],i,10,7);
							     DrawBox(110,85+i*120,Delka,30,ColorPhase[i]);
						       DrawBox(110+Delka,85+i*120,450-Delka,30,white);
								 }
					     }
					     else{
						     if(flag.Change){
								   CleanScreen(white);
									 for(i=0;i<4;i++){
									   TextFrom = WriteTextB("U",15,75+i*100,black,white,1);
										 WriteCharacter((unsigned char)i+0x31,TextFrom,90+i*100,black,white,0);  // 0x31 Abych z i dostal cislo ve string
 									 }
  							 }
								 for(i=0;i<4;i++){
						       Delka = OsaX(90,110+i*100,450,"V",ShowVal[0][i],i,10,7);
							     DrawBox(90,75+i*100,Delka,30,ColorPhase[i]);
						       DrawBox(90+Delka,75+i*100,450-Delka,30,white);
								 }
					     }
	             break;
				case 2: if(flag.Change){  //L-L
								  CleanScreen(white);
								  for(i=0;i<3;i++){
	                  TextFrom = WriteTextB("U",15,85+i*120,black,white,1);
									}
									WriteText("1-2",TextFrom,100,black,white,0);
									WriteText("2-3",TextFrom,220,black,white,0);
									WriteText("3-1",TextFrom,340,black,white,0);
   							}
								for(i=0;i<3;i++){
						      Delka = OsaX(110,120+i*120,450,"V",ShowVal[1][i],i,10,7);
							    DrawBox(110,85+i*120,Delka,30,ColorPhase[i]);
						      DrawBox(110+Delka,85+i*120,450-Delka,30,white);
								}
	              break;

				case 3:if(flag.TriFaze){  // Proud
						     if(flag.Change){  //L-L
								   CleanScreen(white);
								   for(i=0;i<3;i++){
	                   WriteText("I",15,85+i*120,black,white,1);
									 }
									 WriteText("1-2",45,100,black,white,0);
									 WriteText("2-3",45,220,black,white,0);
									 WriteText("3-1",45,340,black,white,0);
   							 }
								 for(i=0;i<3;i++){
						       Delka = OsaX(110,120+i*120,450,"V",ShowVal[3][i],i,10,7);
							     DrawBox(110,85+i*120,Delka,30,ColorPhase[i]);
						       DrawBox(110+Delka,85+i*120,450-Delka,30,white);
								 }
					     }
					     else{
						    if(flag.Change){
								  CleanScreen(white);
									for(i=0;i<4;i++){
									  TextFrom = WriteTextB("I",25,75+i*100,black,white,1);
										WriteCharacter((unsigned char)i+0x31,TextFrom,90+i*100,black,white,0);  // 0x31 Abych z i dostal cislo ve string
 									}
  							}
								for(i=0;i<4;i++){
						      Delka = OsaX(90,110+i*100,450,"A",ShowVal[3][i],i,1,7);
							    DrawBox(90,75+i*100,Delka,30,ColorPhase[i]);
						      DrawBox(90+Delka,75+i*100,450-Delka,30,white);
								}
					    }
	            break;
				case 4: if(flag.Change){  //Cinny
								  CleanScreen(white);
								  for(i=0;i<3;i++){
	                  TextFrom = WriteTextB("P",25,85+i*120,black,white,1);
	                  WriteCharacter((unsigned char)i+0x31,TextFrom,100+i*120,black,white,0);  // 0x31 Abych z i dostal cislo ve string
									}
								}
								for(i=0;i<3;i++){
						      Delka = OsaX(100,120+i*120,450,"W",ShowVal[110][i],i,10,7);
							    DrawBox(100,85+i*120,Delka,30,ColorPhase[i]);
						      DrawBox(100+Delka,85+i*120,450-Delka,30,white);
								}
	              break;
				case 5: if(flag.Change){  //Zdan.
								  CleanScreen(white);
								  for(i=0;i<3;i++){
	                  TextFrom = WriteTextB("S",15,85+i*120,black,white,1);
										WriteCharacter((unsigned char)i+0x31,TextFrom,100+i*120,black,white,0);  // 0x31 Abych z i dostal cislo ve string
									}
   							}
								for(i=0;i<3;i++){
						      Delka = OsaX(90,120+i*120,450,"VA",ShowVal[109][i],i,10,7);
							    DrawBox(90,85+i*120,Delka,30,ColorPhase[i]);
						      DrawBox(90+Delka,85+i*120,450-Delka,30,white);
								}
	              break;
				case 6: if(flag.Change){  //Jal.
								  CleanScreen(white);
								  for(i=0;i<3;i++){
	                  TextFrom = WriteTextB("Q",15,85+i*120,black,white,1);
                    WriteCharacter((unsigned char)i+0x31,TextFrom,100+i*120,black,white,0);  // 0x31 Abych z i dostal cislo ve string
									}
   							}
								for(i=0;i<3;i++){
						      Delka = OsaX(90,120+i*120,450,"VAr",ShowVal[111][i],i,10,7);
							    DrawBox(90,85+i*120,Delka,30,ColorPhase[i]);
						      DrawBox(90+Delka,85+i*120,450-Delka,30,white);
								}
	              break;
											
			}
			break;
		case SCOPE:
		  switch(menu_actual){
				case 1: if(flag.Change){  // Napeti
				          TypScope = 1;   // Vyber co se ma zobrazit				
					        CleanScreen(white);
									DrawBox(5,370,630,105,grey);
									DrawBox(563,372,70,101,grey2);
									DrawBox(565,388,66,83,grey);									
									WriteText("Uef",215,375,black,grey,3);
									WriteText("0",50,200,black,white,3); // 0 u osy y
									WriteText("Um",293,375,black,grey,3);
									WriteText("THDU",362,375,black,grey,3);
									flag.Scope = 1;
								}
				        DrawAxisYT2(72,60,300,10);
								m=0;
 								for(i=0;i<4;i++){
									if(ParamChar[0]&(0x80>>i)){
						 				TextFrom = WriteTextB("L",160,395+m*20,ColorPhase[i],grey,3);
										TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,395+m*20,ColorPhase[i],grey,3);
										TextFrom = WriteCharacter(':',TextFrom,395+m*20,ColorPhase[i],grey,3);				
                  // efektivni hodnota
	                  NumberShow = ShowJednotky(240,395+m*20,"V",ShowVal[0][i],ColorPhase[i],grey,3,0);
									  NumToStr(NumberShow,3,0,0,0,1);
									  WriteText(&cislo[0],200,395+m*20,ColorPhase[i],grey,3);
	                // amplituda
	                  NumberShow = ShowJednotky(320,395+m*20,"V",ShowVal[0][i]*1.4142,ColorPhase[i],grey,3,0);
									  NumToStr(NumberShow,3,0,0,0,1);
									  WriteText(&cislo[0],280,395+m*20,ColorPhase[i],grey,3);
	                // THDU
									  WriteCharacter('%',400,395+m*20,ColorPhase[i],grey,3);
  								  NumToStr(ShowVal[2][i],3,1,0,0,1);                                     
									  WriteText(&cislo[0],360,395+m*20,ColorPhase[i],grey,3);
										m++;								
								  }
								}
								// Ocisluju osu
								TextFrom = WriteTextB("[",5,50,black,white,3);  // Jednotky osy
								TextFrom = ShowJednotky(TextFrom,50,"V",ShowVal[0][m],black,white,3,1);
								TextFrom = WriteTextB("]",TextFrom,50,black,white,3);
								DrawBox(TextFrom,50,28-TextFrom,16,white);
								for(i=0;i<4;i++){
								  NumToStr((PoleRozsahu[0]/4)*(4-i),3,0,0,0,1);
                  WriteText(&cislo[0],28,50+i*37,black,white,3);
								  NumToStr((PoleRozsahu[0]/4)*(4-i),3,0,1,0,1);
                  WriteText(&cislo[0],28,350-i*37,black,white,3);
								}
		// ---< Vyber zobrazeni faze >---						
								if(flag.Param){  // Scope Napeti
             	    TlacitkaParam(); // Je Param jdu na jinou obsluhu tlacitek
                  flag.Scope = 0;					
					        WriteText("Esc",588,372,white,grey2,3);
								  m=0;
 								  for(i=0;i<4;i++){
										if(ParamChar[0]&(0x80>>i)){
											m++;
										}
							  	  if(i==ParamAct){
								      Troj(573,393+ParamAct*20,8,17,white);
									  }
									  else{
     								  Troj(573,393+i*20,8,17,grey);
  								  }
									 	TextFrom = WriteTextB("L",608,394+i*20,black,grey,3);
										TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,394+i*20,black,grey,3);										
									}
									DrawBox(160,395+m*20,255,16*(4-m),grey); 
                  color = black;
								}
								else{  // Neni param
					        TextFrom = WriteTextB("Set",588,372,white,grey2,3);
									DrawBox(TextFrom,372,5,16,grey2);
									DrawBox(568,390,15,80,grey);
                  color = grey2;
									for(i=0;i<4;i++){
									 	TextFrom = WriteTextB("L",608,394+i*20,grey2,grey,3);
										TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,394+i*20,grey2,grey,3);
									}	
									flag.Scope = 1;
								}
								if(ParamChar[0]&0x80)RadioButton(593,402,color,white,1);
				        else RadioButton(593,402,color,white,0);
					  		if(ParamChar[0]&0x40)RadioButton(593,422,color,white,1);
						  	else RadioButton(593,422,color,white,0);
							  if(ParamChar[0]&0x20)RadioButton(593,442,color,white,1);
							  else RadioButton(593,442,color,white,0);
  					  	if(ParamChar[0]&0x10)RadioButton(593,462,color,white,1);
						  	else RadioButton(593,462,color,white,0); 
								break;
				case 2:if(flag.Change){  // Proud
                  TypScope = 2;  //Vyber co se ma zobrazit
					        CleanScreen(white);
									DrawBox(5,370,630,105,grey);
									DrawBox(563,372,70,101,grey2);
									DrawBox(565,388,66,83,grey);									
									WriteText("Ief",220,375,black,grey,3);
									WriteText("0",50,200,black,white,3); // 0 u osy y
									WriteText("Im",298,375,black,grey,3);
									WriteText("THDI",367,375,black,grey,3);
									flag.Scope = 1;
								}
				        DrawAxisYT2(72,60,300,10);
								m=0;
 								for(i=0;i<4;i++){
									if(ParamChar[1]&(0x80>>i)){
						 				TextFrom = WriteTextB("L",160,395+m*20,ColorPhase[4+i],grey,3);
										TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,395+m*20,ColorPhase[4+i],grey,3);
										TextFrom = WriteCharacter(':',TextFrom,395+m*20,ColorPhase[4+i],grey,3);				
                  // efektivni hodnota
	                  NumberShow = ShowJednotky(240,395+m*20,"A",ShowVal[3][i],ColorPhase[4+i],grey,3,0);
									  NumToStr(NumberShow,3,1,0,0,1);
									  WriteText(&cislo[0],200,395+m*20,ColorPhase[4+i],grey,3);
	                // amplituda
	                  NumberShow = ShowJednotky(320,395+m*20,"A",ShowVal[3][i]*1.4142,ColorPhase[4+i],grey,3,0);
									  NumToStr(NumberShow,3,1,0,0,1);
									  WriteText(&cislo[0],280,395+m*20,ColorPhase[4+i],grey,3);
	                // THDI
									  WriteCharacter('%',400,395+m*20,ColorPhase[4+i],grey,3);
  								  NumToStr(ShowVal[5][i],3,1,0,0,1);                                     
									  WriteText(&cislo[0],360,395+m*20,ColorPhase[4+i],grey,3);
										m++;								
								  }
								}
								// Ocisluju osu
								TextFrom = WriteTextB("[",5,50,black,white,3);  // Jednotky osy
								TextFrom = ShowJednotky(TextFrom,50,"A",ShowVal[3][m],black,white,3,1);
								TextFrom = WriteTextB("]",TextFrom,50,black,white,3);
								DrawBox(TextFrom,50,28-TextFrom,16,white);
								 
								for(i=0;i<4;i++){
								  NumToStr((PoleRozsahu[0]/4)*(4-i),3,0,0,0,1);
                  WriteText(&cislo[0],28,50+i*37,black,white,3);
								  NumToStr((PoleRozsahu[0]/4)*(4-i),3,0,1,0,1);
                  WriteText(&cislo[0],28,350-i*37,black,white,3);
								}
				//---< Vyber zobrazeni faze >---				
								if(flag.Param){  // Scope Proud
							    TlacitkaParam(); // Je Param jdu na jinou obsluhu tlacitek
                  flag.Scope = 0;					
					        WriteText("Esc",588,372,white,grey2,3);
								  m=0;
 								  for(i=0;i<4;i++){
										if(ParamChar[1]&(0x80>>i)){
											m++;
										}
							  	  if(i==ParamAct){
								      Troj(573,393+ParamAct*20,8,17,white);
									  }
									  else{
     								  Troj(573,393+i*20,8,17,grey);
  								  }
									 	TextFrom = WriteTextB("L",608,394+i*20,black,grey,3);
										TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,394+i*20,black,grey,3);										
									}
									DrawBox(160,395+m*20,255,16*(4-m),grey); 
                  color = black;
								}
								else{  // Neni param
					        TextFrom = WriteTextB("Set",588,372,white,grey2,3);
									DrawBox(TextFrom,372,5,16,grey2);
									DrawBox(568,390,15,80,grey);
                  color = grey2;
									for(i=0;i<4;i++){
									 	TextFrom = WriteTextB("L",608,394+i*20,grey2,grey,3);
										TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,394+i*20,grey2,grey,3);
									}	
									flag.Scope = 1;
								}
								if(ParamChar[1]&0x80)RadioButton(593,402,color,white,1);
				        else RadioButton(593,402,color,white,0);
					  		if(ParamChar[1]&0x40)RadioButton(593,422,color,white,1);
						  	else RadioButton(593,422,color,white,0);
							  if(ParamChar[1]&0x20)RadioButton(593,442,color,white,1);
							  else RadioButton(593,442,color,white,0);
  					  	if(ParamChar[1]&0x10)RadioButton(593,462,color,white,1);
						  	else RadioButton(593,462,color,white,0); 
								break;
				case 3:if(flag.Change){  // Proud
                  TypScope = 3;  //Vyber co se ma zobrazit
					        CleanScreen(white);
									DrawBox(5,370,630,105,grey);
									DrawBox(563,372,70,101,grey2);
									DrawBox(565,388,66,83,grey);									
									WriteText("Ief",220,425,black,grey,3);
									WriteText("0",50,200,grey2,white,3); // 0 u osy y
									WriteText("Im",298,425,black,grey,3);
									WriteText("THDI",367,425,black,grey,3);
									
									WriteText("Uef",215,375,black,grey,3);
									WriteText("Um",293,375,black,grey,3);
									WriteText("THDU",362,375,black,grey,3);									
									flag.Scope = 1;
								}
				        DrawAxisYT2(72,60,300,10);
 								for(i=0;i<4;i++){
									if(ParamChar[2]&(0x80>>i)){
	  				 				WriteText("U:",170,395,ColorPhase[i],grey,3);
                  // efektivni hodnota
	                  NumberShow = ShowJednotky(240,395,"V",ShowVal[0][i],ColorPhase[i],grey,3,0);
									  NumToStr(NumberShow,3,0,0,0,1);
									  WriteText(&cislo[0],200,395,ColorPhase[i],grey,3);
	                // amplituda
	                  NumberShow = ShowJednotky(320,395,"V",ShowVal[0][i]*1.4142,ColorPhase[i],grey,3,0);
									  NumToStr(NumberShow,3,0,0,0,1);
									  WriteText(&cislo[0],280,395,ColorPhase[i],grey,3);
	                // THDU
									  WriteCharacter('%',400,395,ColorPhase[i],grey,3);
  								  NumToStr(ShowVal[2][i],3,1,0,0,1);                                     
									  WriteText(&cislo[0],360,395,ColorPhase[i],grey,3);


						 				TextFrom = WriteTextB("I:",175,445,ColorPhase[4+i],grey,3);
                  // efektivni hodnota
	                  NumberShow = ShowJednotky(240,445,"A",ShowVal[3][i],ColorPhase[4+i],grey,3,0);
									  NumToStr(NumberShow,3,1,0,0,1);
									  WriteText(&cislo[0],200,445,ColorPhase[4+i],grey,3);
	                // amplituda
	                  NumberShow = ShowJednotky(320,445,"A",ShowVal[3][i]*1.4142,ColorPhase[4+i],grey,3,0);
									  NumToStr(NumberShow,3,1,0,0,1);
									  WriteText(&cislo[0],280,445,ColorPhase[4+i],grey,3);
	                // THDI
									  WriteCharacter('%',400,445,ColorPhase[4+i],grey,3);
  								  NumToStr(ShowVal[5][i],3,1,0,0,1);                                     
									  WriteText(&cislo[0],360,445,ColorPhase[4+i],grey,3);
										m=i;								
								  }
								}
								// Ocisluju osu 
									TextFrom = WriteTextB("[",5,46,ColorPhase[m],white,3);  // Jednotky osy
									TextFrom = ShowJednotky(TextFrom,46,"V",ShowVal[0][m],ColorPhase[m],white,3,1);
									TextFrom = WriteTextB("]",TextFrom,46,ColorPhase[m],white,3);
									DrawBox(TextFrom,46,28-TextFrom,16,white);

									TextFrom = WriteTextB("[",5,59,ColorPhase[m+4],white,3);  // Jednotky osy
									TextFrom = ShowJednotky(TextFrom,59,"A",ShowVal[3][m],ColorPhase[m+4],white,3,1);									
									TextFrom = WriteTextB("]",TextFrom,59,ColorPhase[m+4],white,3);
									DrawBox(TextFrom,59,28-TextFrom,16,white);

								for(i=0;i<4;i++){
									//---< Nap >---
								  NumToStr((PoleRozsahu[0]/4)*(4-i),3,0,0,0,1);
                  WriteText(&cislo[0],28,46+i*37,ColorPhase[m],white,3);
								  NumToStr((PoleRozsahu[0]/4)*(4-i),3,0,1,0,1);
                  WriteText(&cislo[0],28,341-i*37,ColorPhase[m],white,3);
									//---< Proud >---
									NumToStr((PoleRozsahu[1]/4)*(4-i),3,0,0,0,1);
                  WriteText(&cislo[0],28,59+i*37,ColorPhase[4+m],white,3);
								  NumToStr((PoleRozsahu[1]/4)*(4-i),3,0,1,0,1);
                  WriteText(&cislo[0],28,354-i*37,ColorPhase[4+m],white,3);
								}
					//---< Vyber zobrazeni faze >---			
								if(flag.Param){  // Scope Napeti a proud
                  flag.Scope = 0;
							    TlacitkaParam(); // Je Param jdu na jinou obsluhu tlacitek
					        WriteText("Esc",588,372,white,grey2,3);
								  m=0;
 								  for(i=0;i<4;i++){
										if(ParamChar[2]&(0x80>>i)){
											m++;
										}
							  	  if(i==ParamAct){
								      Troj(573,393+ParamAct*20,8,17,white);
									  }
									  else{
     								  Troj(573,393+i*20,8,17,grey);
  								  }
									 	TextFrom = WriteTextB("L",608,394+i*20,black,grey,3);
										TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,394+i*20,black,grey,3);										
									}
                  color = black;
								}
								else{  // Neni param
					        TextFrom = WriteTextB("Set",588,372,white,grey2,3);
									DrawBox(TextFrom,372,5,16,grey2);
									DrawBox(568,390,15,80,grey);
                  color = grey2;
									for(i=0;i<4;i++){
									 	TextFrom = WriteTextB("L",608,394+i*20,grey2,grey,3);
										TextFrom = WriteCharacterB((unsigned char)i+0x31,TextFrom,394+i*20,grey2,grey,3);
									}	
									flag.Scope = 1;
								}
								if(ParamChar[2]&0x80)RadioButton(593,402,color,white,1);
				        else RadioButton(593,402,color,white,0);
					  		if(ParamChar[2]&0x40)RadioButton(593,422,color,white,1);
						  	else RadioButton(593,422,color,white,0);
							  if(ParamChar[2]&0x20)RadioButton(593,442,color,white,1);
							  else RadioButton(593,442,color,white,0);
  					  	if(ParamChar[2]&0x10)RadioButton(593,462,color,white,1);
						  	else RadioButton(593,462,color,white,0); 
								break;
		  }
		break;
		case HISTORY:break;
		case EVENTS:break;
		case SETTINGS:Settings();break;  	
	}
	flag.Change = 0;
	flag.NewScreen = 0;
	flag.Show = 0;
	flag.ParamEnd = 0; 
}			




