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

#include <string.h>				// praca so stringom
#include <stdio.h>				// sprintf

/* FreeRTOS includes */
#include "FreeRTOS.h"
#include "timers.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "priorities.h"

/* Standard Stellaris includes */
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "driverlib/rom.h"
#include "driverlib/gpio.h"

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

#include "com_RS485.h"
#include "display_task.h"

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

tContext sContext;				// vontext displeja
xTaskHandle pvDisplayTask;

//***************** DISPLAY TASK ************************************************************
void DisplayTask(void *pvParameters)
{
	// Initialize the graphics context.
	GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119);

	InitLogoScreen();	// inicializacia logo screnu (spusta sa casovac)
    
    SetLogoScreen();

    // Paint the widget tree to make sure they all appear on the display.
    WidgetPaint(WIDGET_ROOT);
    
    for( ;; )
    {
		// Process any messages from or for the widgets.
		WidgetMessageQueueProcess();
		vTaskDelay( 10 );
		UpdateRandomTime();
    }
}


unsigned long	DisplayTaskInit(void)		//	inicializacia displeja a vitvorenie displej tasku v maine
{	
    // Initialize the display driver.
    Kitronix320x240x16_SSD2119Init();
    
    // Turn on the backlight at full brightness.
    Kitronix320x240x16_SSD2119BacklightOn(255);

    // Initialize the touch screen driver.
    TouchScreenInit();

    // Set the touch screen event handler.
    TouchScreenCallbackSet(WidgetPointerMessage);	

    // Create the display task.	       	
    if(xTaskCreate( DisplayTask, "DisplayTask", STACK_SIZE_DISPLAY_TASK, 0, PRIORITY_DISPLAY_TASK, pvDisplayTask ) != pdPASS)
    {
    	return(1);
    }
    // vsetko ok
	return(0);
}


