#include "mybool.h"
#include "packet.h"
#include <string.h>				// praca so stringom
#include <stdio.h>				// sprintf
#include "utils/ustdlib.h"	//ulprintf

#include "displayScreens/ButtonsImages.h"
/* FreeRTOS includes */
#include "FreeRTOS.h"
#include "timers.h"

// vsetko pre pracu s displejom
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/pushbutton.h"
#include "grlib/imgbutton.h"
#include "grlib/container.h"
#include "grlib/slider.h"
#include "Drivers/kitronix320x240x16_ssd2119_idm_sbc.h"		// driver pre display

#include "MySound.h"
#include "MainTask.h"

#include "displayScreens/MenuScreen.h"
#include "displayScreens/MesageWindow.h"
#include "displayScreens/LEDscreen.h"
#include "displayScreens/LogoScreen.h"

#define 		LEDM_MAX_ScreanIndex	2
unsigned char	LedM_ScreanIndex;
unsigned char	LedM_SettingsIndex;
unsigned char	LedM_SlidersStatus[2][8];

extern tContext sContext;

// ****************** menu SCREEN pre LED modul ***************************************
extern	tCanvasWidget		g_sMenuLedModul;
extern	tContainerWidget	g_sMenuLedMSet;
extern	tContainerWidget	g_sMenuLedMConfig;
extern	tImageButtonWidget	g_sMenuLedMBack;
extern	tImageButtonWidget	g_sMenuLedMSettings1ConfigPushButt;
extern	tImageButtonWidget	g_sMenuLedMManualConfigPushButt;
extern	tImageButtonWidget 	g_psMenuSLedMSetPushButt[];

// ****************** SCREEN pre LED modul nastavenia ***************************************

extern	tCanvasWidget		g_sSettingsLedModul;
extern	tCanvasWidget		g_sLedMSliderPanel;
extern	tCanvasWidget		g_sLedMCentralSliderPanel;
extern	tCanvasWidget		g_sLedMControlPanel;
extern	tImageButtonWidget	g_sLedMPrevious;
extern	tImageButtonWidget	g_sLedMNext;
extern	tImageButtonWidget	g_sLedMSave;
extern	tImageButtonWidget	g_sLedMClose;
extern	tSliderWidget		g_sLedMCentralSlider;
extern	tSliderWidget		g_sLedMSliders[];

// ****************** menu SCREEN pre LED modul ***************************************
Canvas(g_sMenuLedModul, WIDGET_ROOT, 0, &g_sMenuLedMSet, &g_sKitronix320x240x16_SSD2119, 0, 0,
			320, 240, (/*CANVAS_STYLE_APP_DRAWN | */CANVAS_STYLE_FILL),
			ClrBlack, 0, 0, 0, 0, 0, 0);

Container(g_sMenuLedMSet, &g_sMenuLedModul, &g_sMenuLedMConfig, g_psMenuSLedMSetPushButt, &g_sKitronix320x240x16_SSD2119,
			0, 0, 159, 240, (CTR_STYLE_OUTLINE/* | CTR_STYLE_FILL*/ | CTR_STYLE_TEXT), ClrMidnightBlue,ClrLime /*ClrGray*/, ClrLime/*ClrSilver*/,
			&g_sFontCmss22, "Set");
Container(g_sMenuLedMConfig, &g_sMenuLedModul, &g_sMenuLedMBack, &g_sMenuLedMSettings1ConfigPushButt, &g_sKitronix320x240x16_SSD2119,
			161, 0, 159, 72, (CTR_STYLE_OUTLINE/* | CTR_STYLE_FILL*/ | CTR_STYLE_TEXT), ClrMidnightBlue, ClrLime /*ClrGray*/, ClrLime/*ClrSilver*/,
			&g_sFontCmss22, "Config");

ImageButton(g_sMenuLedMBack, &g_sMenuLedModul, 0, 0,
			&g_sKitronix320x240x16_SSD2119, 180, 190, 120, 40,
			(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
			&g_sFontCmss20b, "Back", g_pucButtonBlue120x40, g_pucButtonBlue120x40Press, 0, 0, 0,
			0, 0, LedM_OnBackButtonPress);
   
#define	YSMMENU_BUTT_SHIFT			10			
#define	XSMMENU_BUTT_SPACE			20
#define	XSMCONFIGMENU_BUTT_SPACE	180
#define	YSMMENU_BUTT_SPACE			15
#define	XSMMENU_BUTT_WIDTH			120
#define	YSMMENU_BUTT_HEIGHT			40   
#define	XSLIDER_NAME_SHIFT		10

ImageButton(g_sMenuLedMSettings1ConfigPushButt, &g_sMenuLedMConfig, &g_sMenuLedMManualConfigPushButt, 0,
			&g_sKitronix320x240x16_SSD2119, XSMCONFIGMENU_BUTT_SPACE, YSMMENU_BUTT_SHIFT + YSMMENU_BUTT_SPACE, XSMMENU_BUTT_WIDTH, YSMMENU_BUTT_HEIGHT,
			(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
			&g_sFontCmss20b, "Settings 1", g_pucButtonBlue120x40, g_pucButtonBlue120x40Press, 0, 0, 0,
			0, 0, LedM_OnConfigSettingsButtonPress);

ImageButton(g_sMenuLedMManualConfigPushButt, &g_sMenuLedMConfig, 0, 0,
			&g_sKitronix320x240x16_SSD2119, XSMCONFIGMENU_BUTT_SPACE, YSMMENU_BUTT_SHIFT + YSMMENU_BUTT_SPACE + (YSMMENU_BUTT_SPACE + YSMMENU_BUTT_HEIGHT), XSMMENU_BUTT_WIDTH, YSMMENU_BUTT_HEIGHT,
			(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
			&g_sFontCmss20b, "Manual", g_pucButtonBlue120x40, g_pucButtonBlue120x40Press, 0, 0, 0,
			0, 0, LedM_OnManualButtonPress);
                 
tImageButtonWidget g_psMenuSLedMSetPushButt[] =
{	
	ImageButtonStruct(&g_sMenuLedMSet, g_psMenuSLedMSetPushButt + 1, 0,
				&g_sKitronix320x240x16_SSD2119, XSMMENU_BUTT_SPACE, YSMMENU_BUTT_SHIFT + YSMMENU_BUTT_SPACE, XSMMENU_BUTT_WIDTH, YSMMENU_BUTT_HEIGHT,
				(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
				&g_sFontCmss20b, "Settings 1", g_pucButtonBlue120x40, g_pucButtonBlue120x40Press, 0, 0, 0,
				0, 0, LedM_OnSetButtonPress),
	ImageButtonStruct(&g_sMenuLedMSet, g_psMenuSLedMSetPushButt + 2, 0,
				&g_sKitronix320x240x16_SSD2119, XSMMENU_BUTT_SPACE, YSMMENU_BUTT_SHIFT + YSMMENU_BUTT_SPACE + (YSMMENU_BUTT_SPACE + YSMMENU_BUTT_HEIGHT), XSMMENU_BUTT_WIDTH, YSMMENU_BUTT_HEIGHT,
				(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
				&g_sFontCmss20b, "Demo 1", g_pucButtonBlue120x40, g_pucButtonBlue120x40Press, 0, 0, 0,
				0, 0, LedM_OnSetButtonPress),
	ImageButtonStruct(&g_sMenuLedMSet, g_psMenuSLedMSetPushButt + 3, 0,
				&g_sKitronix320x240x16_SSD2119, XSMMENU_BUTT_SPACE, YSMMENU_BUTT_SHIFT + YSMMENU_BUTT_SPACE + 2*(YSMMENU_BUTT_SPACE + YSMMENU_BUTT_HEIGHT), XSMMENU_BUTT_WIDTH, YSMMENU_BUTT_HEIGHT,
				(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
				&g_sFontCmss20b, "Demo 2", g_pucButtonBlue120x40, g_pucButtonBlue120x40Press, 0, 0, 0,
				0, 0, LedM_OnSetButtonPress),
	ImageButtonStruct(&g_sMenuLedMSet, 0, 0,
				&g_sKitronix320x240x16_SSD2119, XSMMENU_BUTT_SPACE, YSMMENU_BUTT_SHIFT + YSMMENU_BUTT_SPACE + 3*(YSMMENU_BUTT_SPACE + YSMMENU_BUTT_HEIGHT), XSMMENU_BUTT_WIDTH, YSMMENU_BUTT_HEIGHT,
				(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
				&g_sFontCmss20b, "Demo 3", g_pucButtonBlue120x40, g_pucButtonBlue120x40Press, 0, 0, 0,
				0, 0, LedM_OnSetButtonPress)
};                   

// ****************** SCREEN pre LED modul nastavenia ***************************************

Canvas(g_sSettingsLedModul, WIDGET_ROOT, 0, &g_sLedMSliderPanel, &g_sKitronix320x240x16_SSD2119, 0, 0,
			320, 240, (/*CANVAS_STYLE_APP_DRAWN | */CANVAS_STYLE_FILL),
			ClrBlack, 0, 0, 0, 0, 0, 0);
			
Canvas(g_sLedMSliderPanel, &g_sSettingsLedModul, &g_sLedMControlPanel, g_sLedMSliders, &g_sKitronix320x240x16_SSD2119, 0, 0,
		320, 190, (CANVAS_STYLE_APP_DRAWN| CANVAS_STYLE_FILL),
		ClrBlack, ClrWhite, 0, 0, 0, 0, OnSliderPanelPaint);
		
Canvas(g_sLedMCentralSliderPanel, &g_sSettingsLedModul, 0/*&g_sLedMControlPanel*/, &g_sLedMCentralSlider, &g_sKitronix320x240x16_SSD2119, 0, 0,
		320, 190, (CANVAS_STYLE_APP_DRAWN| CANVAS_STYLE_FILL),
		ClrBlack, ClrWhite, 0, 0, 0, 0, OnCentralSliderPanelPaint);
			
Canvas(g_sLedMControlPanel, &g_sSettingsLedModul, 0, &g_sLedMPrevious, &g_sKitronix320x240x16_SSD2119, 0, 188,
		320, 52, CANVAS_STYLE_FILL,
		ClrBlack, ClrWhite, 0, 0, 0, 0, 0);

ImageButton(g_sLedMPrevious, &g_sLedMControlPanel, &g_sLedMNext, 0,
			&g_sKitronix320x240x16_SSD2119, 5, 195, 40, 40,
			(IB_STYLE_KEYCAP_OFF | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
			0, 0, g_pucButtonBlueLeft40x40, g_pucButtonBlueLeft40x40Press, 0, 0, 0,
			0, 0, LedM_OnPreviousPress);

ImageButton(g_sLedMNext, &g_sLedMControlPanel, &g_sLedMSave, 0,
			&g_sKitronix320x240x16_SSD2119, 275, 195, 40, 40,
			(IB_STYLE_KEYCAP_OFF | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
			0, 0, g_pucButtonBlueRight40x40, g_pucButtonBlueRight40x40Press, 0, 0, 0,
			0, 0, LedM_OnNextPress);

ImageButton(g_sLedMSave, &g_sLedMControlPanel, &g_sLedMClose, 0,
			&g_sKitronix320x240x16_SSD2119, 60, 197, 90, 35,
			(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
			&g_sFontCmss20b, "Save", g_pucButtonBlue90x35, g_pucButtonBlue90x35Press, 0, 0, 0,
			0, 0, LedM_OnSavePress);

ImageButton(g_sLedMClose, &g_sLedMControlPanel, 0, 0,
			&g_sKitronix320x240x16_SSD2119, 170, 197, 90, 35,
			(IB_STYLE_KEYCAP_OFF | IB_STYLE_TEXT | IB_STYLE_RELEASE_NOTIFY), ClrWhite, 0, 0,
			&g_sFontCmss20b, "Close", g_pucButtonBlue90x35, g_pucButtonBlue90x35Press, 0, 0, 0,
			0, 0, LedM_OnClosePress);
			
#define	XSLIDER_SHIFT			80
#define	YSLIDER_SHIFT			15
#define	YSLIDER_SPACE			15

#define	XSLIDER_WIDTH			230
#define	YSLIDER_HEIGHT			30  

char *g_pLedMSliderNames[] =
{
    "OUT 1",	"OUT 2",	"OUT 3",	"OUT 4",	"OUT 5",	"OUT 6",	"OUT 7",	"OUT 8"
};

Slider(g_sLedMCentralSlider, &g_sLedMCentralSliderPanel, 0, 0,
			&g_sKitronix320x240x16_SSD2119, 10, 90, 300, YSLIDER_HEIGHT, 0, 255, 25,
			(SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
			SL_STYLE_TEXT | SL_STYLE_BACKG_TEXT),
			ClrBlue, ClrBlack, ClrSilver, ClrWhite, ClrWhite,
			&g_sFontCmss20, 0, 0, 0, OnCentralSliderChange);

tSliderWidget	g_sLedMSliders[] =
{
	    SliderStruct(&g_sLedMSliderPanel, g_sLedMSliders + 1, 0,
                 &g_sKitronix320x240x16_SSD2119, XSLIDER_SHIFT, YSLIDER_SHIFT, XSLIDER_WIDTH, YSLIDER_HEIGHT, 0, 255, 25,
                 (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
                  SL_STYLE_TEXT | SL_STYLE_BACKG_TEXT),
                 ClrBlue, ClrBlack, ClrSilver, ClrWhite, ClrWhite,
                 &g_sFontCmss20, 0, 0, 0, OnSliderChange),
	    SliderStruct(&g_sLedMSliderPanel, g_sLedMSliders + 2, 0,
                 &g_sKitronix320x240x16_SSD2119, XSLIDER_SHIFT, YSLIDER_SHIFT + (YSLIDER_HEIGHT + YSLIDER_SPACE), XSLIDER_WIDTH, YSLIDER_HEIGHT, 0, 255, 25,
                 (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
                  SL_STYLE_TEXT | SL_STYLE_BACKG_TEXT),
                 ClrBlue, ClrBlack, ClrSilver, ClrWhite, ClrWhite,
                 &g_sFontCmss20, 0, 0, 0, OnSliderChange),
	    SliderStruct(&g_sLedMSliderPanel, g_sLedMSliders + 3, 0,
                 &g_sKitronix320x240x16_SSD2119, XSLIDER_SHIFT, YSLIDER_SHIFT + 2*(YSLIDER_HEIGHT + YSLIDER_SPACE), XSLIDER_WIDTH, YSLIDER_HEIGHT, 0, 255, 25,
                 (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
                  SL_STYLE_TEXT | SL_STYLE_BACKG_TEXT),
                 ClrBlue, ClrBlack, ClrSilver, ClrWhite, ClrWhite,
                 &g_sFontCmss20, 0, 0, 0, OnSliderChange),
	    SliderStruct(&g_sLedMSliderPanel, 0, 0,
                 &g_sKitronix320x240x16_SSD2119, XSLIDER_SHIFT, YSLIDER_SHIFT + 3*(YSLIDER_HEIGHT + YSLIDER_SPACE), XSLIDER_WIDTH, YSLIDER_HEIGHT, 0, 255, 25,
                 (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
                  SL_STYLE_TEXT | SL_STYLE_BACKG_TEXT),
                 ClrBlue, ClrBlack, ClrSilver, ClrWhite, ClrWhite,
                 &g_sFontCmss20, 0, 0, 0, OnSliderChange)
};

// ****************** Funkcie z menu SCREEN pre Spinaci modul ***************************************

// nastavi LED MENU screan
void SetMenuLedModulScrean(void)		
{
		WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMenuLedModul);
		LedM_ScreanIndex= 0;
}  
void	RemoveMenuLedModulScrean(void)
{
	WidgetRemove((tWidget *)&g_sMenuLedModul ); 
}

// spravy popisky k sliderom
void 	OnSliderPanelPaint(tWidget *pWidget, tContext *pContext)	
{
	UpdateSlidersDescription();
}
// pri vikresleni centralneho slideru s ktorim sa menia vsetky vystupi
void 	OnCentralSliderPanelPaint(tWidget *pWidget, tContext *pContext)
{
	GrContextFontSet(&sContext, &g_sFontCmss26b);
	GrContextForegroundSet(&sContext, ClrWhite);
	GrStringDraw(&sContext, "Set all outputs", -1, 90, 35, true);
}

void	LedM_OnBackButtonPress(tWidget *pWidget)
{
	RemoveMenuLedModulScrean(); 
	SetMenuScreen();
	WidgetPaint(WIDGET_ROOT);
	SoundPlayKeyClick();
	ResetLogoScreenTimer();
}                
// pri stlaceni set tlacidiel (SETTINGS 1 DEMO 1 - 3)
void	LedM_OnSetButtonPress(tWidget *pWidget)
{
	unsigned char index;
	for(index = 0; index < 4; index++)		// zistujem ktore tlacitko bolo stlacene
	{
		if(pWidget == (tWidget *)(g_psMenuSLedMSetPushButt + index))
		{
			break;
		}
	}
	if( index == 4)return;
	t_MainQueueStruct	Mesage;
	Mesage.Mesage_ID= C_QUEUE_LEDM_SET;	// uloz nastavenia alebo aplikuj aktualne
	Mesage.Data[0]= index+1;		// nula je manual
	sendToMainQueue( &Mesage, 0 );
	RemoveMenuLedModulScrean(); 
	SetMenuScreen();
	WidgetPaint(WIDGET_ROOT);	
	SoundPlayKeyClick();
	ResetLogoScreenTimer();
}
// po stlaceni SETTINGS1  skoci do nastavovaciehomenu
void	LedM_OnConfigSettingsButtonPress(tWidget *pWidget)
{
	LedM_SettingsIndex= 1;
	RemoveMenuLedModulScrean();
	SetSettingsLedModulScrean();
	UpdateSlidersValue();
	ImageButtonTextSet( (tPushButtonWidget *)&g_sLedMSave, "Save" );
	WidgetPaint(WIDGET_ROOT);
	SoundPlayKeyClick();
	ResetLogoScreenTimer();
}
// po stlaceni MANUAL  skoci do nastavovaciehomenu
void	LedM_OnManualButtonPress(tWidget *pWidget)
{
	LedM_SettingsIndex= 0;	
	RemoveMenuLedModulScrean();
	SetSettingsLedModulScrean();
	UpdateSlidersValue();
	ImageButtonTextSet( (tPushButtonWidget *)&g_sLedMSave, "Set" );
	WidgetPaint(WIDGET_ROOT);
	SoundPlayKeyClick();
	ResetLogoScreenTimer();
}

// ****************** funkcie pre LED modul nastavenia ***************************************
// Nastavi OKNO SO SLIDERMY
void SetSettingsLedModulScrean(void)		
{
	ImageButtonImageSet( &g_sLedMPrevious, g_pucButtonBlack40x40 );
	ImageButtonImagePressedSet( &g_sLedMPrevious, g_pucButtonBlack40x40 );
	
	ImageButtonImageSet( &g_sLedMNext, g_pucButtonBlueRight40x40 );
	ImageButtonImagePressedSet( &g_sLedMNext, g_pucButtonBlueRight40x40Press );
		
	WidgetRemove((tWidget *)&g_sLedMCentralSliderPanel);
	WidgetAdd((tWidget *)&g_sSettingsLedModul, (tWidget *)&g_sLedMSliderPanel);	
	WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sSettingsLedModul);
}
void 	RemoveSettingsLedModulScrean(void)
{
	WidgetRemove((tWidget *)&g_sSettingsLedModul ); 
}

// PREVIOUS
void	LedM_OnPreviousPress(tWidget *pWidget)		
{
	LedM_ScreanIndex--;
	if( LedM_ScreanIndex > LEDM_MAX_ScreanIndex)
	{
		LedM_ScreanIndex= 0;
		return;
	}
	if( LedM_ScreanIndex == 0)
	{
		ImageButtonImageSet( &g_sLedMPrevious, g_pucButtonBlack40x40 );
		ImageButtonImagePressedSet( &g_sLedMPrevious, g_pucButtonBlack40x40 );
		WidgetPaint((tWidget *)&g_sLedMPrevious); 
	}
	if( LedM_ScreanIndex == (LEDM_MAX_ScreanIndex - 1) )
	{
		ImageButtonImageSet( &g_sLedMNext, g_pucButtonBlueRight40x40 );
		ImageButtonImagePressedSet( &g_sLedMNext, g_pucButtonBlueRight40x40Press );
		WidgetPaint((tWidget *)&g_sLedMNext); 
	// menim screan na screan s slidermi pre kazdy vistup osobitne	
		WidgetRemove((tWidget *)&g_sLedMCentralSliderPanel);
		WidgetAdd((tWidget *)&g_sSettingsLedModul, (tWidget *)&g_sLedMSliderPanel);
		WidgetPaint((tWidget *)&g_sLedMSliderPanel);
	}	
	UpdateSlidersDescription();
	UpdateSlidersValue();
	SoundPlayKeyClick();
	ResetLogoScreenTimer();
}
// NEXT
void	LedM_OnNextPress(tWidget *pWidget)
{
	LedM_ScreanIndex++;
	if( LedM_ScreanIndex > LEDM_MAX_ScreanIndex)
	{
		LedM_ScreanIndex= LEDM_MAX_ScreanIndex;
		return;
	}
	if( LedM_ScreanIndex == 1)
	{
		ImageButtonImageSet( &g_sLedMPrevious, g_pucButtonBlueLeft40x40 );
		ImageButtonImagePressedSet( &g_sLedMPrevious, g_pucButtonBlueLeft40x40Press );
		WidgetPaint((tWidget *)&g_sLedMPrevious); 
	}
	if( LedM_ScreanIndex == LEDM_MAX_ScreanIndex)
	{
		ImageButtonImageSet( &g_sLedMNext, g_pucButtonBlack40x40 );
		ImageButtonImagePressedSet( &g_sLedMNext, g_pucButtonBlack40x40 );
		
		WidgetPaint((tWidget *)&g_sLedMNext); 
	// menim screan na central slider kde je jeden slider s ktorym sa nastavuju vsetky vystupy
		WidgetRemove((tWidget *)&g_sLedMSliderPanel);
		WidgetAdd((tWidget *)&g_sSettingsLedModul, (tWidget *)&g_sLedMCentralSliderPanel);
		WidgetPaint((tWidget *)&g_sLedMCentralSliderPanel);
	}
	UpdateSlidersDescription();
	UpdateSlidersValue();
	SoundPlayKeyClick();
	ResetLogoScreenTimer();
}
// pri SAVE
void	LedM_OnSavePress(tWidget *pWidget)
{
	t_MainQueueStruct	Mesage;
	Mesage.Mesage_ID= C_QUEUE_LEDM_CONFIG;	// uloz nastavenia alebo aplikuj aktualne
	Mesage.Data[0]= LedM_SettingsIndex;
	memcpy( (Mesage.Data + 1), LedM_SlidersStatus[LedM_SettingsIndex], 8 );
	sendToMainQueue( &Mesage, 0 );
	RemoveSettingsLedModulScrean(); 
	SetMenuScreen();
	WidgetPaint(WIDGET_ROOT);
	SoundPlayKeyClick();
	ResetLogoScreenTimer();
}
// CLOSE
void	LedM_OnClosePress(tWidget *pWidget)
{
	RemoveSettingsLedModulScrean();
	SetMenuScreen();
	WidgetPaint(WIDGET_ROOT);
	SoundPlayKeyClick();
	ResetLogoScreenTimer();
}
// zmana hlavneho slideru
void	OnCentralSliderChange(tWidget *pWidget, long lValue)
{
	static char pcSliderText[5];
	unsigned long temp;
	temp= (lValue*100)/254;
	usprintf(pcSliderText, "%3d%%", temp);
	SliderTextSet(&g_sLedMCentralSlider, pcSliderText);
	WidgetPaint((tWidget *)&g_sLedMCentralSlider);
	for(temp=0; temp<8;temp++)
	{
		LedM_SlidersStatus[LedM_SettingsIndex][temp]=lValue;
	}
	ResetLogoScreenTimer();
}
// zmema miakeho slideru
void OnSliderChange(tWidget *pWidget, long lValue)
{
	static char pcSliderText[5];
	unsigned char index;
	for(index = 0; index < 4; index++)		// zistujem ktore tlacitko bolo stlacene
	{	
		if(pWidget == (tWidget *)(g_sLedMSliders + index))
		{
			break;
		}   	
	}
	if( index == 4)return;
	unsigned long temp;
	temp= (lValue*100)/254;
	usprintf(pcSliderText, "%3d%%", temp);
	SliderTextSet(&g_sLedMSliders[index], pcSliderText);
	WidgetPaint((tWidget *)&g_sLedMSliders[index]);
	
	LedM_SlidersStatus[LedM_SettingsIndex][index + (LedM_ScreanIndex*4)]=lValue;
	ResetLogoScreenTimer();
	
////	// online zmena
//	t_MainQueueStruct	Mesage;
//	Mesage.Mesage_ID= C_QUEUE_LEDM_CONFIG;	// uloz nastavenia alebo aplikuj aktualne
//	Mesage.Data[0]= LedM_SettingsIndex;
//	memcpy( (Mesage.Data + 1), LedM_SlidersStatus[LedM_SettingsIndex], 8 );
//	sendToMainQueue( &Mesage, 0 );
}

void	SetLEDMSlidersStatus( unsigned char *data )
{
	memcpy( LedM_SlidersStatus, data, 16 );	//ulozim nastavenia do aktualnich s ktorich sa nacitavaju slidery
}

// uprava popislu k sliderom podla ScreanIndexu
void	UpdateSlidersDescription(void)
{
	if( LedM_ScreanIndex < 2 )
	{	
		GrContextFontSet(&sContext, &g_sFontCmss20b);
		GrContextForegroundSet(&sContext, ClrWhite);
		GrStringDraw(&sContext, g_pLedMSliderNames[(LedM_ScreanIndex*4)], 5, XSLIDER_NAME_SHIFT, 5 + YSLIDER_SHIFT, true);
		GrStringDraw(&sContext, g_pLedMSliderNames[(LedM_ScreanIndex*4)+1], 5, XSLIDER_NAME_SHIFT, 5 + YSLIDER_SHIFT + (YSLIDER_HEIGHT + YSLIDER_SPACE), true);
		GrStringDraw(&sContext, g_pLedMSliderNames[(LedM_ScreanIndex*4)+2], 5, XSLIDER_NAME_SHIFT, 5 + YSLIDER_SHIFT + 2*(YSLIDER_HEIGHT + YSLIDER_SPACE), true);
		GrStringDraw(&sContext, g_pLedMSliderNames[(LedM_ScreanIndex*4)+3], 5, XSLIDER_NAME_SHIFT, 5 + YSLIDER_SHIFT + 3*(YSLIDER_HEIGHT + YSLIDER_SPACE), true);
	}
}
// uprava hodonti sliderov podla ScreanIndexu
void	UpdateSlidersValue(void)
{
	// nastavenie hodnot sliderov
	unsigned long i;
	static char pcSliderText[5][5];
	for(i=0; i<4; i++)
	{
		SliderValueSet(&g_sLedMSliders[i], LedM_SlidersStatus[LedM_SettingsIndex][i + (LedM_ScreanIndex * 4)]);
		usprintf(pcSliderText[i], "%3d%%", ((100*LedM_SlidersStatus[LedM_SettingsIndex][i + (LedM_ScreanIndex * 4)]) / 254) );
		SliderTextSet(&g_sLedMSliders[i], pcSliderText[i] );
		if(LedM_ScreanIndex < 2) WidgetPaint((tWidget *)&g_sLedMSliders[i]);
	}
	
	SliderValueSet(&g_sLedMCentralSlider, LedM_SlidersStatus[LedM_SettingsIndex][0]);		// hodnota s prveho slidera so central slideru
	usprintf(pcSliderText[4], "%3d%%", ((100*LedM_SlidersStatus[LedM_SettingsIndex][0]) / 254) );
	SliderTextSet(&g_sLedMCentralSlider, pcSliderText[4] );								
}


