#include "lvgl.h"
#include "img_def.h"
#include "demo.h"
//#include "lv_common_function.h"
#include "img_basic.h"
#include "spde_ipc.h"
#include "mxc_meter.h"

static uint8_t background_style = 0;

#define M_PI 3.14
static int center_x = 242, center_y = 119;
static int radius = 51;
static double start_angle = 0;
static double end_angle = 0;
static float progress =0.0;
#define TEST_FUN      0

#define HOME_KEY_BIT   	0x08
#define ENTER_KEY_BIT  	0x10
#define UP_KEY_BIT  	0x20
#define DOWN_KEY_BIT  	0x40
#define END_KEY_BIT  	0x80
#define SHORT_KEY_BIT  	0x01
#define MULTI_KEY_BIT  	0x02
#define LONG_KEY_BIT  	0x04

#define KEY_CODE_HOME 		HOME_KEY_BIT|SHORT_KEY_BIT    //0000 1001   0x09
#define KEY_CODE_ENTER 		ENTER_KEY_BIT|SHORT_KEY_BIT	  //0001 0001	  0x11

static const char show_scale_x[13]={22,-18,-53,-74,-75,-60,-25,18 ,62 ,99,120,126,118};
static const char show_scale_y[13]={120,110,81,40, -3 ,-44,-76,-88,-81,-61,-22,20,60};

extern lv_timer_t * time_refresh_timer;


lv_obj_t *meter;
lv_meter_indicator_t * indic;
lv_meter_indicator_t * indic1;

lv_obj_t * oil_meter;
lv_meter_indicator_t *oil_indic1;
lv_meter_indicator_t *oil_indic2;

lv_obj_t * temp_meter;
lv_meter_indicator_t *temp_indic1;
lv_meter_indicator_t *temp_indic2;


static int speed_angle = 0;
static int speed_value = 0;
static int bar_value = 0;
static int gear_value = 0;

#define CANVAS_WIDTH  200
#define CANVAS_HEIGHT 200

void creatRootObj(void);
void Enter_screen_id(lv_obj_t *parent_main);


void win_init(void)
{
    uint8_t ui_mode = 0;

//    creatRootObj();
     lv_group_t * scr_key_group =get_key_group();
     lv_win32_add_all_input_devices_to_group(scr_key_group);

    system_date_init();
    ui_mode = spde_ipc_get_ui_mode();
    switch (ui_mode)
    {
        case UI_MODE_NORMAL:
            Enter_screen_id(get_root_win());
            break;
        case UI_MODE_CHARGE:
            break;
        case UI_MODE_OTA:
            break;
        case UI_MODE_POWER_OFF:

            break;
        case UI_MODE_POWER_ON:

            break;
        case UI_MODE_CHARGE_FULL:
            break;
        default:
            Enter_screen_id(get_root_win());
            break;
    }

}

//界面入口函数
void Enter_screen_id(lv_obj_t *parent_main)
{
    daily_data_t *local_data = daily_get_UiData();
    Set_UI_page_id(get_top_history_win());

    if(local_data->ui_page_id == IDLE_CONTROL_WIN_ID)
    {
        printf("enter_demo . \n");
        lv_demo(parent_main,NULL);
//        enter_control_main_win(parent_main);
    }
    else if(local_data->ui_page_id == PAGE_MAINMENU_WIN_ID)
    {
        printf("enter_list . \n");
//        enter_mainmenu_win(parent_main);
    }
}

//定时刷新函数
static int espeed_counter = 0;
static int water_counter = 0;
static int oil_counter = 0;

void refresh_timer_cb(lv_timer_t *t)
{
    printf("enter refresh_timer_cb()...\n");

    lv_obj_t* parent = t->user_data;
    if(!lv_obj_is_valid(parent))
    {
        printf("parent lv_obj_is_valid fail.\n");
        return;
    }
    if(parent == NULL)
    {
        printf("parent ==NULL\n");
        return;
    }

    //printf("AAA...\n");
    //if(Get_sys_power_on_self_test() == 0)  //单板需要，模拟器需注释
    //return;
    //printf("BBB...\n");

#if 1
    static int GearValue = 0, SpeedValue = 0;
    static float VoltValue = 0.0;
    static int espeedFlag = 0, espeed = 0;
    static int espeedangle = 0;  //espeedpointFlag = 0
    static int waterFlag = 0, waterspeed = 0;
    static int waterangle = 0;
    static int oilFlag = 0, oilspeed = 0;
    static int oilangle = 0;

    //获取主界面子对象
    lv_obj_t* pSpeed = lv_obj_get_child(parent, 15);        //获取档位信息
    lv_obj_t* pGear = lv_obj_get_child(parent, 17);         //获取速度信息
    lv_obj_t* pTimelabel = lv_obj_get_child(parent, 18);   //获取当前时间
    lv_obj_t* pVoltage = lv_obj_get_child(parent, 19);     //获取电瓶电压

    lv_obj_t* pEspeedArc = lv_obj_get_child(parent, 20);     //转速圆弧   //lv_obj_t* pEspeedImg = lv_obj_get_child(parent, 21);//转速颜色条
    lv_obj_t* pEspeedPoint = lv_obj_get_child(parent, 26);   //转速指针

    lv_obj_t* pWaterArc = lv_obj_get_child(parent, 22);      //水箱圆弧
    lv_obj_t* pWaterPoint = lv_obj_get_child(parent, 27);    //水箱指针
    lv_obj_t* pOilArc = lv_obj_get_child(parent, 23);        //油箱圆弧
    lv_obj_t* pOilPoint = lv_obj_get_child(parent, 28);      //油箱指针

    //档位数据
    lv_label_set_text_fmt(pGear, "%d", GearValue+2);
    //速度数据
    lv_label_set_text_fmt(pSpeed, "%d", SpeedValue+20);
    //当前时间,时间更新
    lv_label_set_text(pTimelabel, GetCurTimeString());    //获取当前时间
    //电瓶电压
    lv_label_set_text_fmt(pVoltage, "%0.1fV", VoltValue+10.0);

    //档位数据
    GearValue++;
    if(GearValue == 8)
    {
        GearValue = 0;
    }
    //速度数据
    SpeedValue += 10;
    if(SpeedValue == 350)
    {
        SpeedValue = 0;
    }
    //电压数据
    VoltValue += 0.2;
    if(VoltValue <= 14.0)
    {
        SpeedValue = 0.0;
    }

    //转速圆弧
    lv_arc_set_value(pEspeedArc, espeed);               //设置圆弧值范围 (0~120),实际转速值缩小100倍
    //转速指针
    lv_img_set_angle(pEspeedPoint, espeedangle + 600);  //圆弧指针角度范围 (60~300),分12份，20度
    printf("espeedangle = %d\n", espeedangle);
    if(espeedFlag%2 == 0)
    {
        espeed += 10;
        espeedangle += 200;
    }
    else
    {
        espeed -= 10;
        espeedangle -= 200;
    }
    espeed_counter++;
    espeedFlag = espeed_counter/12;

    //水箱圆弧
    lv_arc_set_value(pWaterArc, waterspeed);     //水温范围值(0~100),圆弧值范围 (0~100)
    //水箱指针
    lv_img_set_angle(pWaterPoint, waterangle + 2200);      //圆弧指针角度范围 (220~340)
    printf("waterangle = %d\n", waterangle);
    if(waterFlag%2 == 0)
    {
        waterspeed = waterspeed + 10;
        waterangle = waterangle + 100;
    }
    else
    {
        waterspeed = waterspeed - 10;
        waterangle = waterangle - 100;
    }
    water_counter++;
    waterFlag = water_counter/10;

        //水箱圆弧
    lv_arc_set_value(pOilArc, oilspeed);     //水温范围值(0~100),圆弧值范围 (0~100)
    //水箱指针
    lv_img_set_angle(pOilPoint, oilangle + 2200);      //圆弧指针角度范围 (220~340)
    printf("oilangle = %d\n", oilangle);
    if(oilFlag%2 == 0)
    {
        oilspeed = oilspeed + 10;
        oilangle = oilangle + 100;
    }
    else
    {
        oilspeed = oilspeed - 10;
        oilangle = oilangle - 100;
    }
    oil_counter++;
    oilFlag = oil_counter/10;



    /*printf("-------\n");
    if(num%2==0)
        speed_angle+=20;
    else
        speed_angle-=20;

    if(speed_angle >= 3000|| speed_angle == 0)
        num++;

    printf("num = %d\n", num);
    printf("speed_angle = %d\n", speed_angle);
    */

#else if
    static int num=0,bar_num=0,peed_num=0,gear_num=0,mileage=0;
    uint8_t scale_num;
    //指针刷新
    lv_obj_t * ui_Arc1 = lv_obj_get_child(parent,5);
    lv_obj_t * hand_img = lv_obj_get_child(parent,6);

    lv_obj_t * speed = lv_obj_get_child(parent,7);
    lv_obj_t * gear = lv_obj_get_child(parent,8);
    lv_obj_t * gear_null = lv_obj_get_child(parent,9);
    lv_obj_t * tcs = lv_obj_get_child(parent,10);
    lv_obj_t * time_label = lv_obj_get_child(parent,11);
    lv_obj_t * max_speed = lv_obj_get_child(parent,12);
    lv_obj_t * avg_speed = lv_obj_get_child(parent,13);
    lv_obj_t * trip_mileage = lv_obj_get_child(parent,14);
    lv_obj_t * odo_mileage = lv_obj_get_child(parent,15);

    lv_img_set_angle(hand_img, speed_angle);
    lv_arc_set_value(ui_Arc1, (speed_angle/25));
    //lv_arc_set_value(ui_Arc1, (speed_angle/25));
    lv_label_set_text_fmt(speed, "%d", speed_value);

    lv_label_set_text_fmt(gear, "%d",gear_value);

    if(gear_value !=7)
    {
        lv_obj_clear_flag(gear,LV_OBJ_FLAG_HIDDEN);
        lv_obj_add_flag(gear_null,LV_OBJ_FLAG_HIDDEN );
    }
    else
    {
        lv_obj_clear_flag(gear_null,LV_OBJ_FLAG_HIDDEN );
        lv_obj_add_flag(gear,LV_OBJ_FLAG_HIDDEN );
    }
    lv_label_set_text(time_label, GetCurTimeString());

    lv_label_set_text_fmt(max_speed, "%d",speed_value);
    lv_label_set_text_fmt(avg_speed, "%d",speed_value);

    lv_label_set_text_fmt(trip_mileage, "%d",speed_value);
    lv_label_set_text_fmt(odo_mileage, "%d",speed_value);

    scale_num = (speed_angle/250) ;
    lv_meter_set_indicator_end_value(meter, indic1, speed_angle/20);


    if(bar_value <60)
    {
        lv_meter_set_indicator_end_value(oil_meter, oil_indic1, bar_value);
        lv_meter_set_indicator_end_value(oil_meter, oil_indic2, 60);
    }
    else
    {
        lv_meter_set_indicator_end_value(oil_meter, oil_indic1, 60);
        lv_meter_set_indicator_end_value(oil_meter, oil_indic2, bar_value);
    }

    if(bar_value<210)
    {
        lv_meter_set_indicator_end_value(temp_meter, temp_indic1, bar_value);
        lv_meter_set_indicator_end_value(temp_meter, temp_indic2, 210);
    }
    else
    {
        lv_meter_set_indicator_end_value(temp_meter, temp_indic1, 210);
        lv_meter_set_indicator_end_value(temp_meter, temp_indic2, bar_value);
    }

    //转速指针
    if(num%2==0)
        speed_angle+=20;
    else
        speed_angle-=20;

    if(speed_angle >= 3000|| speed_angle == 0)
        num++;

    printf("num = %d\n", num);
    printf("speed_angle = %d\n", speed_angle);

    //速度
    if(peed_num%2==0)
        speed_value+=1;
    else
        speed_value-=1;

    if(speed_value>=255 || speed_value ==0)
        peed_num++;

    //档位
    if(gear_num%2==0)
        gear_value+=1;
    else
        gear_value-=1;

    if(gear_value>=7 || gear_value ==0)
    {
        gear_num++;
    }

    //温度油量
    if(bar_num%2 ==0)
        bar_value+=2;
    else
        bar_value-=2;

    if(bar_value>=270 || bar_value==0)
        bar_num++;

    mileage++;
    if(mileage>=888888)
        mileage=0;
#endif

}


static void demo_win_event_handle(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    uint8_t key_code = 0;

    uint32_t *key = lv_event_get_param(e);
    key_code = (uint8_t)*key;

    printf("demo_win_event_handle==========.\n");
    if (code == LV_EVENT_KEY)
    {

        uint32_t *key = lv_event_get_param(e);
        key_code = (uint8_t)*key;
        printf("key_code = %d . code = 0x%02d \n",key_code,code);

        switch (key_code)
        {

            case LV_KEY_W:
                close_ui_refresh_timer();
                close_all_win();
                if (time_refresh_timer != NULL)
                {
                    lv_timer_del(time_refresh_timer);
                    time_refresh_timer = NULL;
                }
                enter_mainmenu_win(get_root_win());
                break;

            default:
                break;
        }
    }

}

void lv_demo(lv_obj_t *parent, lv_point_t *top)
{
//    start_angle = atan2(center_y - 143, 199 - center_x) * 180 / M_PI;
//    end_angle = atan2(center_y - 143, 284 - center_x) * 180 / M_PI;
//    if(!lv_obj_is_valid(parent))
//    return;

    lv_obj_t *win2_screen = lv_obj_create(parent);
    lv_obj_set_style_pad_all(win2_screen, 0, 0);
    lv_obj_set_style_border_width(win2_screen, 0, 0);
    lv_obj_set_style_opa(win2_screen, LV_OPA_100, 0);
    lv_obj_set_scrollbar_mode(win2_screen, LV_SCROLLBAR_MODE_ACTIVE);
    lv_obj_clear_flag(win2_screen, LV_OBJ_FLAG_SCROLL_ELASTIC);
    lv_obj_clear_flag(win2_screen, LV_OBJ_FLAG_GESTURE_BUBBLE);
//    lv_obj_set_size(win2_screen, 320, 170);
    lv_obj_set_size(win2_screen,LV_PCT(100),LV_PCT(100));
    lv_obj_set_style_radius(win2_screen, 0, 0);
    lv_obj_set_style_bg_color(win2_screen, lv_color_black(), NULL);

# if 1
    lv_obj_clear_flag(win2_screen, LV_OBJ_FLAG_SCROLLABLE);
    //背景 0
    lv_obj_t* panel_bg_img = lv_img_big_create(win2_screen, panel_blackgroud_src, 106, 15, 6, 0);

    //加载左转向 1
    lv_obj_t* pTurnLeft = lv_img_create(win2_screen);
    lv_obj_align(pTurnLeft, LV_ALIGN_TOP_LEFT, 12, 7);
    lv_img_set_src(pTurnLeft, IMG_A36_LEFT_ICO);

    //加载右转向 2
    lv_obj_t* pTurnRight = lv_img_create(win2_screen);
    lv_obj_align(pTurnRight, LV_ALIGN_TOP_LEFT, 446, 7);
    lv_img_set_src(pTurnRight, IMG_A36_RIGHT_ICO);

    //加载绿灯A 3
    lv_obj_t* pGreenLightA = lv_img_create(win2_screen);
    lv_obj_align(pGreenLightA, LV_ALIGN_TOP_LEFT, 52, 10);
    lv_img_set_src(pGreenLightA, IMG_A36_GREENALIGHT_ICO);

    //加载绿灯 4
    lv_obj_t* pGreenLight = lv_img_create(win2_screen);
    lv_obj_align(pGreenLight, LV_ALIGN_TOP_LEFT, 86, 10);
    lv_img_set_src(pGreenLight, IMG_A36_GREENLIGHT_ICO);

    //加载蓝灯 5
    lv_obj_t* pBlueLight = lv_img_create(win2_screen);
    lv_obj_align(pBlueLight, LV_ALIGN_TOP_LEFT, 119, 10);
    lv_img_set_src(pBlueLight, IMG_A36_BLUELIGHT_ICO);

    //加载蓝牙 6
    lv_obj_t* pBlueTooth = lv_img_create(win2_screen);
    lv_obj_align(pBlueTooth, LV_ALIGN_TOP_LEFT, 422, 10);
    lv_img_set_src(pBlueTooth, IMG_A36_BLUETOOTH_ICO);

    //加载右黄色图标1 7
    lv_obj_t* pRightYellow1 = lv_img_create(win2_screen);
    lv_obj_align(pRightYellow1, LV_ALIGN_TOP_LEFT, 425.8, 249.3);
    lv_img_set_src(pRightYellow1, IMG_A36_RIGHTYELLOW1_ICO);

    //加载右黄色图标2 8
    lv_obj_t* pRightYellow2 = lv_img_create(win2_screen);
    lv_obj_align(pRightYellow2, LV_ALIGN_TOP_LEFT, 395, 249);
    lv_img_set_src(pRightYellow2, IMG_A36_RIGHTYELLOW2_ICO);

    //加载右黄色图标3 9
    lv_obj_t* pRightYellow3 = lv_img_create(win2_screen);
    lv_obj_align(pRightYellow3, LV_ALIGN_TOP_LEFT, 352, 248.9);
    lv_img_set_src(pRightYellow3, IMG_A36_RIGHTYELLOW3_ICO);

    //加载左红色图标1 10
    lv_obj_t* pLeftRed1 = lv_img_create(win2_screen);
    lv_obj_align(pLeftRed1, LV_ALIGN_TOP_LEFT, 14, 250.67);
    lv_img_set_src(pLeftRed1, IMG_A36_LEFTRED1_ICO);

    //加载左红色图标2 11
    lv_obj_t* pLeftRed2 = lv_img_create(win2_screen);
    lv_obj_align(pLeftRed2, LV_ALIGN_TOP_LEFT, 107.7, 251.57);
    lv_img_set_src(pLeftRed2, IMG_A36_LEFTRED2_ICO);

    //加载水箱图标 12
    lv_obj_t* pWaterTank = lv_img_create(win2_screen);
    lv_obj_align(pWaterTank, LV_ALIGN_TOP_LEFT, 397, 71.6);
    lv_img_set_src(pWaterTank, IMG_A36_WATER_ICO);

    //加载水箱图标 13
    lv_obj_t* pOilTank = lv_img_create(win2_screen);
    lv_obj_align(pOilTank, LV_ALIGN_TOP_LEFT, 397, 175.7);
    lv_img_set_src(pOilTank, IMG_A36_OIL_ICO);

    //加载转速单位 14
    lv_obj_t* pLabel_ESpeedUnit = lv_label_create(win2_screen);
    lv_obj_set_style_text_font(pLabel_ESpeedUnit, LV_FONT_MXC_MSYAHEI_CT_10PX, LV_STATE_DEFAULT);
    lv_label_set_text(pLabel_ESpeedUnit, "x1000r/min");          //实际使用需要换成一个变量
    lv_obj_align(pLabel_ESpeedUnit, LV_ALIGN_TOP_LEFT, 209, 89);

    //加载速度数据 15
    lv_obj_t* pLabel_Speed = lv_label_create(win2_screen);
    lv_obj_set_style_text_font(pLabel_Speed, LV_FONT_MXC_MSYAHEI_CT_48PX, LV_STATE_DEFAULT);
    lv_label_set_text(pLabel_Speed, "135");          //实际使用需要换成一个变量
    lv_obj_align(pLabel_Speed, LV_ALIGN_TOP_LEFT, 194, 107);

    //加载速度单位 16
    lv_obj_t* pLabel_SpeedUnit = lv_label_create(win2_screen);
    lv_obj_set_style_text_font(pLabel_SpeedUnit, LV_FONT_MXC_MSYAHEI_CT_14PX, LV_STATE_DEFAULT);
    lv_label_set_text(pLabel_SpeedUnit, "km/h");
    lv_obj_align(pLabel_SpeedUnit, LV_ALIGN_TOP_LEFT, 221, 169);

    //加载档位数据 17
    lv_obj_t* pLabel_GearPos = lv_label_create(win2_screen);
    lv_obj_set_style_text_font(pLabel_GearPos, LV_FONT_MXC_MSYAHEI_CT_36PX, LV_STATE_DEFAULT);
    lv_label_set_text(pLabel_GearPos, "6");
    lv_obj_align(pLabel_GearPos, LV_ALIGN_TOP_LEFT, 227, 187);

    //加载当前时间数据 18
    lv_obj_t* pLabel_TimeValue = lv_label_create(win2_screen);
    lv_obj_set_style_text_font(pLabel_TimeValue, LV_FONT_MXC_MSYAHEI_CT_21PX, LV_STATE_DEFAULT);
    lv_label_set_text(pLabel_TimeValue, "15:36");
    lv_obj_align(pLabel_TimeValue, LV_ALIGN_TOP_LEFT, 210, 252);

    //加载电瓶电压 19
    lv_obj_t* pLabel_Valtage = lv_label_create(win2_screen);
    lv_obj_set_style_text_font(pLabel_Valtage, LV_FONT_MXC_MSYAHEI_CT_14PX, LV_STATE_DEFAULT);
    lv_label_set_text(pLabel_Valtage, "12.2V");
    lv_obj_align(pLabel_Valtage, LV_ALIGN_TOP_LEFT, 44, 250);

    //加载转速颜色圆弧 20
    lv_obj_t* ui_Arc2 = lv_arc_create(win2_screen);
    lv_obj_set_width(ui_Arc2, 300);
    lv_obj_set_height(ui_Arc2, 300);
    lv_obj_set_x(ui_Arc2, -1);       //修改调整圆弧图片坐标(-1,-15)
    lv_obj_set_y(ui_Arc2, -15);
    lv_obj_set_align(ui_Arc2, LV_ALIGN_CENTER);
    lv_arc_set_range(ui_Arc2, 0, 120);   //设置圆弧值的范围(转速值缩小100倍)
    lv_arc_set_value(ui_Arc2, 110);      //设置圆弧的实际大小
    lv_obj_set_style_arc_color(ui_Arc2, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_opa(ui_Arc2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_width(ui_Arc2, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    lv_obj_set_style_arc_width(ui_Arc2, 100, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_rounded(ui_Arc2, false, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    //lv_obj_set_style_arc_img_src(ui_Arc2, &ui_img_a36_colorbar_png, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_img_src(ui_Arc2, &A36_colorbar_cfile, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_color(ui_Arc2, lv_color_hex(0xFFFFFF), LV_PART_KNOB | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_Arc2, 0, LV_PART_KNOB | LV_STATE_DEFAULT);

/*  //图片21
//    lv_obj_t* ui_Image2 = lv_img_create(win2_screen);
//    //lv_img_set_src(ui_Image2, &A36_colorbar_cfile);
//    lv_obj_set_style_arc_img_src(ui_Arc2, &A36_colorbar_cfile, LV_PART_INDICATOR | LV_STATE_DEFAULT);
//    lv_obj_set_width(ui_Image2, LV_SIZE_CONTENT);       /// 269
//    lv_obj_set_height(ui_Image2, LV_SIZE_CONTENT);      /// 218
//    lv_obj_set_x(ui_Image2, 230);
//    lv_obj_set_y(ui_Image2, -32);
//    lv_obj_set_align(ui_Image2, LV_ALIGN_CENTER);
//    lv_obj_add_flag(ui_Image2, LV_OBJ_FLAG_ADV_HITTEST);       /// Flags
//    lv_obj_clear_flag(ui_Image2, LV_OBJ_FLAG_SCROLLABLE);      /// Flags
*/
    //加载转速数字和刻度 21
    lv_obj_t* panel_numscale_img = lv_img_big_create(win2_screen, panel_numscale_src, 114, 22, 3, 0);

    //加载水箱颜色 22
    lv_obj_t* ui_ArcWaterbar1 = lv_arc_create(win2_screen);
    lv_obj_set_width(ui_ArcWaterbar1, 80);
    lv_obj_set_height(ui_ArcWaterbar1, 80);
    lv_obj_set_x(ui_ArcWaterbar1, 182);  //重新调整的坐标位置
    lv_obj_set_y(ui_ArcWaterbar1, -49);
    lv_obj_set_align(ui_ArcWaterbar1, LV_ALIGN_CENTER);
    lv_arc_set_bg_angles(ui_ArcWaterbar1, 300, 60);
    lv_obj_set_style_arc_color(ui_ArcWaterbar1, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_opa(ui_ArcWaterbar1, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_width(ui_ArcWaterbar1, 30, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_rounded(ui_ArcWaterbar1, false, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_img_src(ui_ArcWaterbar1, &A36_waterbar1_cfile, LV_PART_INDICATOR | LV_STATE_DEFAULT);

    lv_obj_set_style_bg_color(ui_ArcWaterbar1, lv_color_hex(0xFFFFFF), LV_PART_KNOB | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_ArcWaterbar1, 0, LV_PART_KNOB | LV_STATE_DEFAULT);
    lv_arc_set_range(ui_ArcWaterbar1, 0, 100);       //设置圆弧值的范围(转速值缩小100倍)
    lv_arc_set_value(ui_ArcWaterbar1, 100);

    //加载油箱颜色 23
    lv_obj_t* ui_ArcOilbar1 = lv_arc_create(win2_screen);
    lv_obj_set_width(ui_ArcOilbar1, 80);
    lv_obj_set_height(ui_ArcOilbar1, 80);
    lv_obj_set_x(ui_ArcOilbar1, 182);  //重新调整的坐标位置
    lv_obj_set_y(ui_ArcOilbar1, 55);
    lv_obj_set_align(ui_ArcOilbar1, LV_ALIGN_CENTER);
    lv_arc_set_bg_angles(ui_ArcOilbar1, 300, 60);
    lv_obj_set_style_arc_color(ui_ArcOilbar1, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_opa(ui_ArcOilbar1, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

    lv_obj_set_style_arc_width(ui_ArcOilbar1, 30, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_rounded(ui_ArcOilbar1, false, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_img_src(ui_ArcOilbar1, &A36_oilbar1_cfile, LV_PART_INDICATOR | LV_STATE_DEFAULT);

    lv_obj_set_style_bg_color(ui_ArcOilbar1, lv_color_hex(0xFFFFFF), LV_PART_KNOB | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_ArcOilbar1, 0, LV_PART_KNOB | LV_STATE_DEFAULT);
    lv_arc_set_range(ui_ArcOilbar1, 0, 100);        //范围(转速值缩小100倍)
    lv_arc_set_value(ui_ArcOilbar1, 100);

    //加载水箱和邮箱刻度图标 24 25
    lv_obj_t* pWatersScale = lv_img_create(win2_screen);
    lv_obj_align(pWatersScale, LV_ALIGN_TOP_LEFT, 433, 54);
    lv_img_set_src(pWatersScale, IMG_A36_WATERSCALE_ICO);

    lv_obj_t* pOilScale = lv_img_create(win2_screen);
    lv_obj_align(pOilScale, LV_ALIGN_TOP_LEFT, 433, 158);
    lv_img_set_src(pOilScale, IMG_A36_OILSCALE_ICO);

    //转速指针 26
    lv_obj_t* pESpeedPoint_img = lv_img_create(win2_screen);
 	lv_img_set_src(pESpeedPoint_img, IMG_A36_ESPEEDPOINT_ICO);
 	lv_obj_update_layout(pESpeedPoint_img);                        //更新图片布局信息
 	lv_obj_align(pESpeedPoint_img, LV_ALIGN_TOP_LEFT, 190, 193);   //原始计算坐标(194,183),修正坐标(190,193) x-4,y+10
 	lv_img_set_pivot(pESpeedPoint_img, 46, -45);    //原始计算坐标(45, -45),修正坐标 (46,-45)
    lv_img_set_angle(pESpeedPoint_img, 3000);

    //水箱指针 27 (图形失真)
    lv_obj_t* pWaterpoint_img = lv_img_create(win2_screen);
 	lv_img_set_src(pWaterpoint_img, IMG_A36_WATERPOINT_ICO);
 	lv_obj_update_layout(pWaterpoint_img);                        //更新图片布局信息
 	lv_obj_align(pWaterpoint_img, LV_ALIGN_TOP_LEFT, 369, 37);   //原始计算坐标(366,41),修正坐标(369,37) x+3,y-4
 	lv_img_set_pivot(pWaterpoint_img, 44, 48);                   //原始计算坐标(44, 44),修正坐标(44,48)
    lv_img_set_angle(pWaterpoint_img, -900);

    //油箱指针 28 (图形失真)
    lv_obj_t* pOilpoint_img = lv_img_create(win2_screen);
 	lv_img_set_src(pOilpoint_img, IMG_A36_OILPOINT_ICO);
 	lv_obj_update_layout(pOilpoint_img);                        //更新图片布局信息
 	lv_obj_align(pOilpoint_img, LV_ALIGN_TOP_LEFT, 369, 142);   //原始计算坐标(366,146),修正坐标(369,142) x+3,y-4
 	lv_img_set_pivot(pOilpoint_img, 44, 48);                    //原始计算坐标(44, 44),修正坐标(44,48)
    lv_img_set_angle(pOilpoint_img, -900);

    lv_obj_t* demo_group = get_key_group();
    lv_group_add_obj(demo_group, win2_screen);

    lv_obj_add_event_cb(win2_screen, demo_win_event_handle, LV_EVENT_KEY, NULL);

//    lv_timer_t * ui_refresh_timer = get_ui_refresh_timer();
    time_refresh_timer = lv_timer_create(refresh_timer_cb, 1000, win2_screen);

#else if
//    UI_PARENT_INIT(win2_screen);
    lv_obj_clear_flag(win2_screen, LV_OBJ_FLAG_SCROLLABLE);
    //背景
    lv_obj_t* panel_bg_img1 = lv_img_big_create(win2_screen, panel_demo1_src, 176, 2, 5, 0);
    //arc外边框
    lv_obj_t* panel_bg_img2 = lv_img_big_create(win2_screen, panel_bg2_src, 15, 17 ,3 , 0);//0
//    //刻度
//    lv_obj_t* panel_bg_img3 = lv_img_big_create(parent,panel_bg3_src,25,25,3,0);//0

    // bar
    meter = lv_meter_create(win2_screen);
    lv_obj_remove_style(meter, NULL, LV_PART_INDICATOR);  //meterԲ�Ĳ���ʾ
    lv_obj_remove_style(meter, NULL, LV_PART_MAIN);
    lv_obj_set_size(meter, 228, 228);
    lv_obj_align(meter,LV_ALIGN_CENTER,-109,-3);

    lv_meter_scale_t * scale = lv_meter_add_scale(meter);
    lv_meter_set_scale_ticks(meter, scale, 0, 1, 5, lv_palette_main(LV_PALETTE_GREY));
    lv_meter_set_scale_range(meter, scale, 0, 150, 300, 90);

    indic1 = lv_meter_add_arc(meter, scale, 18, lv_color_hex(0x62d5f9), 0);
//    indic = lv_meter_add_needle_line(meter, scale, 4, lv_palette_main(LV_PALETTE_GREY), -10);

    //oil bar
    oil_meter= lv_meter_create(win2_screen);
    lv_obj_remove_style(oil_meter, NULL, LV_PART_MAIN);
    lv_obj_remove_style(oil_meter, NULL, LV_PART_INDICATOR);

    lv_meter_scale_t * oil_scale;
    oil_scale = lv_meter_add_scale(oil_meter);
    lv_meter_set_scale_range(oil_meter, oil_scale, 0, 270, 270, 90);
    lv_meter_set_scale_ticks(oil_meter, oil_scale, 0, 3, 12, lv_color_white());

    oil_indic1 = lv_meter_add_arc(oil_meter, oil_scale, 6, lv_color_hex(0xff0000), 0);
    lv_meter_set_indicator_start_value(oil_meter, oil_indic1, 0);
//    lv_meter_set_indicator_end_value(oil_meter, oil_indic1, 60);//设置范围
    lv_meter_set_indicator_end_value(oil_meter, oil_indic1, 0);//设置范围

    oil_indic2 = lv_meter_add_arc(oil_meter, oil_scale, 6, lv_color_hex(0x00ff00), 0);
    lv_meter_set_indicator_start_value(oil_meter, oil_indic2, 60);
//    lv_meter_set_indicator_end_value(oil_meter, oil_indic2, 270);
    lv_meter_set_indicator_end_value(oil_meter, oil_indic2, 60);//初始值

    lv_obj_update_layout(win2_screen);
    lv_obj_set_size(oil_meter, 45, 45);
   	lv_obj_align(oil_meter,LV_ALIGN_TOP_LEFT,140,217);

    //temp bar
    temp_meter = lv_meter_create(win2_screen);
    lv_obj_remove_style(temp_meter, NULL, LV_PART_MAIN);
    lv_obj_remove_style(temp_meter, NULL, LV_PART_INDICATOR);

    lv_meter_scale_t * temp_scale;

    temp_scale = lv_meter_add_scale(temp_meter);
    lv_meter_set_scale_range(temp_meter, temp_scale, 0, 270, 270, 90);
    lv_meter_set_scale_ticks(temp_meter, temp_scale, 0, 3, 12, lv_color_white());

    temp_indic1 = lv_meter_add_arc(temp_meter, temp_scale, 6, lv_color_hex(0x0070BB), 0);
    lv_meter_set_indicator_start_value(temp_meter, temp_indic1, 0);
//    lv_meter_set_indicator_end_value(temp_meter, temp_indic1, 210);
    lv_meter_set_indicator_end_value(temp_meter, temp_indic1, 0);

    temp_indic2 = lv_meter_add_arc(temp_meter, temp_scale, 6, lv_color_hex(0xff0000), 0);
    lv_meter_set_indicator_start_value(temp_meter, temp_indic2, 210);
//    lv_meter_set_indicator_end_value(temp_meter, temp_indic2, 270);
    lv_meter_set_indicator_end_value(temp_meter, temp_indic2, 210);

    lv_obj_update_layout(win2_screen);
    lv_obj_set_size(temp_meter, 45, 45);
    lv_obj_align(temp_meter,LV_ALIGN_TOP_LEFT,180,191);

    lv_obj_t * ui_Arc1 = lv_arc_create(win2_screen);
    lv_obj_set_width(ui_Arc1, 230);
    lv_obj_set_height(ui_Arc1, 230);
    lv_obj_set_x(ui_Arc1, 16);
    lv_obj_set_y(ui_Arc1, 17);
    lv_arc_set_range(ui_Arc1, 0, 120);
    lv_arc_set_value(ui_Arc1, 0);
    lv_arc_set_bg_angles(ui_Arc1, 0, 300);
    lv_arc_set_rotation(ui_Arc1, 90);
    lv_obj_set_style_arc_opa(ui_Arc1, 0, LV_PART_MAIN|LV_STATE_DEFAULT);

    lv_obj_set_style_arc_color(ui_Arc1, lv_color_hex(0x9393FF), LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_opa(ui_Arc1, 255, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_width(ui_Arc1, 30, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_rounded(ui_Arc1, false, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_arc_img_src(ui_Arc1, &speed_arc, LV_PART_INDICATOR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(ui_Arc1, 0, LV_PART_KNOB | LV_STATE_DEFAULT);
    lv_obj_remove_style(ui_Arc1, NULL, LV_PART_KNOB);   /*Be sure the knob is not displayed*/
    lv_obj_clear_flag(ui_Arc1, LV_OBJ_FLAG_CLICKABLE);  /*To not allow adjusting by click*/

    //指针
    lv_obj_t *hand_img = lv_img_create(win2_screen);//4
 	lv_img_set_src(hand_img,IMG_POINTER2);
 	lv_obj_align(hand_img,LV_ALIGN_CENTER,-108,93);
 	lv_img_set_pivot(hand_img, 3, -81);
    lv_img_set_angle(hand_img, 0);

    lv_obj_t * speed = lv_label_create(win2_screen);
    lv_obj_set_style_text_align(speed, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_center(speed);
    lv_obj_set_pos(speed,-105,-10);
    lv_obj_set_style_text_font(speed, LV_FONT_MXC_WRYH_CT_72PX, 0);
    lv_label_set_text_fmt(speed, "%d",speed_value);

    lv_obj_t * gear = lv_label_create(win2_screen);
    lv_obj_set_pos(gear, 120, 180);
//    lv_obj_align_to(gear,panel_bg_img2,LV_ALIGN_CENTER,25,75);
    lv_obj_set_style_text_font(gear,LV_FONT_MXC_WRYH_CT_30PX,0);
//    lv_label_set_text_fmt(gear, "3",gear_value);

    lv_obj_t * gear_null = lv_img_create(win2_screen);
    lv_obj_set_pos(gear_null, 120, 183);
//    lv_obj_align_to(gear_null,panel_bg_img2,LV_ALIGN_CENTER,-5,58);
    lv_img_set_src(gear_null, IMG_DM1_NULL);

    lv_obj_t * tcs = lv_img_create(win2_screen);
    lv_obj_align(tcs,LV_ALIGN_BOTTOM_LEFT,10,-10);
    lv_img_set_src(tcs, IMG_DM1_TCS);

    lv_obj_t * time_label = lv_label_create(win2_screen);
    lv_obj_set_pos(time_label, 10, 10);
    lv_obj_set_style_text_font(time_label,LV_FONT_MXC_WRYH_CT_20PX,0);
    lv_label_set_text(time_label, GetCurTimeString());

    lv_obj_t * max_speed = lv_label_create(win2_screen);
    lv_obj_set_pos(max_speed, -50, 20);
    lv_obj_set_align(max_speed, LV_ALIGN_TOP_RIGHT);
    lv_obj_set_style_text_font(max_speed,LV_FONT_MXC_WRYH_CT_30PX,0);
    lv_label_set_text(max_speed,"255");

    lv_obj_t * avg_speed = lv_label_create(win2_screen);
    lv_obj_set_pos(avg_speed, -50, -35);
    lv_obj_set_align(avg_speed, LV_ALIGN_RIGHT_MID);
    lv_obj_set_style_text_font(avg_speed,LV_FONT_MXC_WRYH_CT_30PX,0);
    lv_label_set_text(avg_speed, "254");

    lv_obj_t * trip = lv_label_create(win2_screen);
    lv_obj_set_pos(trip, -30, 40);
    lv_obj_set_align(trip, LV_ALIGN_RIGHT_MID);
    lv_obj_set_style_text_font(trip,LV_FONT_MXC_WRYH_CT_30PX,0);
    lv_label_set_text(trip, "888888");

    lv_obj_t * total = lv_label_create(win2_screen);
    lv_obj_set_pos(total, -30, -20);
    lv_obj_set_align(total, LV_ALIGN_BOTTOM_RIGHT);
    lv_obj_set_style_text_font(total,LV_FONT_MXC_WRYH_CT_30PX,0);
    lv_label_set_text(total, "888888");

    lv_obj_t * img_oil = lv_img_create(win2_screen);
    lv_obj_align_to(img_oil,oil_meter,LV_ALIGN_CENTER,-7,-7);
    lv_img_set_src(img_oil, IMG_DM1_OIL);

    lv_obj_t * img_temp = lv_img_create(win2_screen);
    lv_obj_align_to(img_temp,temp_meter,LV_ALIGN_CENTER,-7,-7);
    lv_img_set_src(img_temp, IMG_DM1_TEMP);

    lv_obj_t * speed_uint = lv_label_create(win2_screen);
    lv_obj_set_pos(speed_uint, 90, 64);
//    lv_obj_align_to(speed_uint,panel_bg_img2,LV_ALIGN_CENTER,-10,-40);
    lv_obj_set_style_text_font(speed_uint,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(speed_uint, "1000r/min");

    lv_obj_t * speed_uint2 = lv_label_create(win2_screen);
    lv_obj_set_pos(speed_uint2, 110, 160);
    //lv_obj_align_to(speed_uint2,panel_bg_img2,LV_ALIGN_CENTER,10,50);
    lv_obj_set_style_text_font(speed_uint2,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(speed_uint2, "km/h");

    lv_obj_t * speed_uint3 = lv_label_create(win2_screen);
    lv_obj_set_pos(speed_uint3, 435, 28);
    lv_obj_set_style_text_font(speed_uint3,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(speed_uint3, "km/h");

    lv_obj_t * speed_uint4 = lv_label_create(win2_screen);
    lv_obj_set_pos(speed_uint4, 435, 98);
    lv_obj_set_style_text_font(speed_uint4,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(speed_uint4, "km/h");

    lv_obj_t * mileage_uint1 = lv_label_create(win2_screen);
    lv_obj_set_pos(mileage_uint1, 450, 173);
    lv_obj_set_style_text_font(mileage_uint1,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(mileage_uint1, "km");

    lv_obj_t * mileage_uint2 = lv_label_create(win2_screen);
    lv_obj_set_pos(mileage_uint2, 450, 238);
    lv_obj_set_style_text_font(mileage_uint2,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(mileage_uint2, "km");

    lv_obj_t * max_speed_label = lv_label_create(win2_screen);
    lv_obj_set_pos(max_speed_label, 300, 25);
    lv_obj_set_style_text_font(max_speed_label,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(max_speed_label, "最高时速:");

    lv_obj_t * avg_speed_label = lv_label_create(win2_screen);
    lv_obj_set_pos(avg_speed_label, 300, 90);
//    lv_obj_set_align(avg_speed_label, LV_ALIGN_RIGHT_MID);
    lv_obj_set_style_text_font(avg_speed_label,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(avg_speed_label, "平均时速:");

    lv_obj_t * trip_label = lv_label_create(win2_screen);
    lv_obj_set_pos(trip_label, 300, 140);
    lv_obj_set_style_text_font(trip_label,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(trip_label, "小计里程:");

    lv_obj_t * total_label = lv_label_create(win2_screen);
    lv_obj_set_pos(total_label, 299, 210);
    lv_obj_set_style_text_font(total_label,LV_FONT_MXC_WRYH_CT_16PX,0);
    lv_label_set_text(total_label, "总计里程:");

    self_checking_animo(win2_screen);

    lv_obj_t *demo_group = get_key_group();
    lv_group_add_obj(demo_group, win2_screen);

//    lv_obj_add_flag(win2_screen, LV_STATE_FOCUSED );
//    lv_obj_add_flag(win2_screen, LV_STATE_FOCUS_KEY );
//    lv_obj_add_state(win2_screen, LV_STATE_FOCUSED );
//    lv_obj_add_state(win2_screen, LV_STATE_FOCUS_KEY );


    lv_obj_add_event_cb(win2_screen, demo_win_event_handle, LV_EVENT_KEY, NULL);

//    lv_timer_t * ui_refresh_timer = get_ui_refresh_timer();
    time_refresh_timer = lv_timer_create(refresh_timer_cb,50,win2_screen);

#endif

}


