#include "mybool.h"
#include "packet.h"
#include "IntroImage.h"

#include <string.h>				// praca so stringom
/* FreeRTOS includes */
#include "FreeRTOS.h"
#include "task.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 "Drivers/kitronix320x240x16_ssd2119_idm_sbc.h"		// driver pre display

#include "MySound.h"

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


extern	tImageButtonWidget	g_sIntroScrean;

xTimerHandle xTimerLogoScreenReset;
	
ImageButton(g_sIntroScrean, WIDGET_ROOT, 0, 0,
                  &g_sKitronix320x240x16_SSD2119, 0, 0, 320, 240,
                  ( IB_STYLE_KEYCAP_OFF | IB_STYLE_RELEASE_NOTIFY ), ClrSilver, 0, 0, 0, 0, g_pIntroImage, g_pIntroImage, 0, 0, 0, 0, 0, OnImgButtonPress); 

void InitLogoScreen(void)
{
	xTimerLogoScreenReset= xTimerCreate( "Reset Logo Screan",  ( 5000 / portTICK_RATE_MS ), pdFALSE, 0, vTimerLogoScreenReset );
}

void vTimerLogoScreenReset( xTimerHandle pxTimer )
{
	RemoveMesageWindow();
	RemoveMenuSpinModulScrean();
	RemoveSMscrean();
	RemoveMenuLedModulScrean();
	RemoveSettingsLedModulScrean();
	RemoveLockKeyScreen();
	RemoveLogoScreen();
	RemoveMenuScreen();
	WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sIntroScrean);
	WidgetPaint(WIDGET_ROOT);
	xTimerStop( xTimerLogoScreenReset, 100 );
	SoundPlayPassWrong();
}

void ResetLogoScreenTimer(void)
{
	xTimerReset( xTimerLogoScreenReset, 100 );
}
                  
void SetLogoScreen(void)
{
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sIntroScrean);
}

void RemoveLogoScreen(void)
{
	WidgetRemove((tWidget *)&g_sIntroScrean ); 
}

void OnImgButtonPress(tWidget *pWidget)
{
	SetTimerLogoScreenT1();
	xTimerStart( xTimerLogoScreenReset, 100 );
	RemoveLogoScreen();
	SetLockKeyScreen();
	WidgetPaint(WIDGET_ROOT);
	SoundPlayKeyClick();	
}

void SetTimerLogoScreenT1(void)
{
	xTimerChangePeriod( xTimerLogoScreenReset, ( 5000 / portTICK_RATE_MS ), 100 );
}

void SetTimerLogoScreenT2(void)
{
	xTimerChangePeriod( xTimerLogoScreenReset, ( 30000 / portTICK_RATE_MS ), 100 );
}
