#include "LVGL_TaskHand.h"

#include "lvgl.h"
#include "FreeRTOS.h"
#include "task.h"


void vApplicationTickHook()
{
	lv_tick_inc(1);     //LVGL心跳
}


static void MeterDisplay_Init(void)
{
    lv_obj_t * scr = lv_scr_act();//获取当前活跃的屏幕对象

    static lv_style_t stytle_title;
    lv_style_init(&stytle_title);
    lv_style_set_text_font(&stytle_title,LV_STATE_DEFAULT,&lv_font_montserrat_14);
    lv_obj_t * title = lv_label_create(lv_scr_act(), NULL);
    lv_style_list_t * list = lv_obj_get_style_list(title, LV_LABEL_PART_MAIN);
    _lv_style_list_add_style(list, &stytle_title);
    lv_obj_refresh_style(title, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
    lv_label_set_text(title, "testing");
}

TaskHandle_t Task2_LVGLTASK;
#define LVGLTask_Prior 		(tskIDLE_PRIORITY + 3)	// lvgl task handel
#define LVGLTask_SckDep 	(512)
void LVGL_TaskHand_Period(void)
{
	TickType_t WaitTime;
	const TickType_t xPeriod = pdMS_TO_TICKS(5);	
	WaitTime = xTaskGetTickCount();	
	
	lv_init();
	lv_port_disp_init();
	MeterDisplay_Init();
    for( ; ; )
	{    
		vTaskDelayUntil(&WaitTime,xPeriod);
		lv_task_handler();
	}
}


int Creat_LVGLTask(void)
{
    
	
    xTaskCreate((TaskFunction_t)LVGL_TaskHand_Period,"LVGLTask",LVGLTask_SckDep,NULL,LVGLTask_Prior,Task2_LVGLTASK);
    return 0;
}

