MXC-A36_2024.04.18/fr3092_lvglcode/lv_user_code/app/demo.c~

520 lines
18 KiB
C
Raw Normal View History

#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);
}
}
void refresh_timer_cb(lv_timer_t *t){
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;
}
if(Get_sys_power_on_self_test() ==0)
return;
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++;
//速度
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;
}
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);
//
// 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Բ<72>IJ<EFBFBD><C4B2><EFBFBD>ʾ
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);
}