#include #include #include #include #include "../inc/ui/ui_screen3.h" #include "../inc/ui/ui_screen3_chart.h" #include "../inc/ui/fs_function.h" lv_obj_t * ui_Screen3;//用来切屏 lv_obj_t * screen3_calender; lv_obj_t * screen3_calender_dsc_label; //用来设置选中日期 lv_obj_t * btn_page_plus; //用来设置是否可选中 lv_obj_t * btn_page_reduce;//用来设置是否可选中 //用来设置数据 lv_obj_t * data_table1; lv_obj_t * data_table2; lv_obj_t * data_table3; lv_obj_t * data_table4; lv_obj_t * data_table5; lv_obj_t * data_table6; lv_obj_t * data_table7; lv_obj_t * data_table8; lv_obj_t * screen3_spinbox; lv_obj_t * screen3_spinbox_dsc_label; lv_obj_t * screen3_spinbox_label_textarea; lv_obj_t * btnm; lv_obj_t * scrren3_spinbox_btn; lv_obj_t * calendar_dropdown_year; lv_obj_t * calendar_dropdown_month; // lv_obj_t * chart; lv_obj_t * chart_screen; lv_chart_series_t * ser1; lv_chart_series_t * ser2; lv_chart_series_t * ser3; lv_chart_series_t * ser4; lv_obj_t * primary_y_label; lv_obj_t * secondry_y_label; lv_obj_t * chart_change_btn_label; extern lv_obj_t * ui_Screen2; extern lv_obj_t * ui_Screen4; extern int current_id; extern int end_count; struct Return_Data global_file_data_p; struct ChartData chartdata;//存储chart数据 uint8_t this_date_have_data = 0; //判断是否需要重新读取文件 uint16_t screen3_spinbox_btnm_teatarea_flag = 0; uint8_t user_first_see_calendar_or_change_date = 1; lv_calendar_date_t highlighted_days[31]; uint8_t highlighted_days_cnt = 0; void ui_Screen3_calendar_set_highlight(void) { //通过日期获取路径 char year[10]; char month[10]; char filedir[20]; lv_dropdown_get_selected_str(calendar_dropdown_year, year, sizeof(year)); lv_dropdown_get_selected_str(calendar_dropdown_month, month, sizeof(month)); sprintf(filedir,"SD:/%s/%s",year,month); //printf("%s\n",filedir); uint16_t a = atoi(year); int8_t b = atoi(month); //printf("%d.%02d\n",a,b); //lv_calendar_date_t highlighted_days[30]; for(int i = 0; i < 31; i++){ highlighted_days[i].year = a; highlighted_days[i].month = b; highlighted_days[i].day = 0; } //printf("%d.%02d\n",highlighted_days[0].year,highlighted_days[0].month); char filenames[30][7]; for (int i = 0; i < 31; i++) { sprintf(filenames[i], "%02d.txt", i+1); } //打开文件读取目录 QDIR * dir = ql_opendir(filedir); if(dir != NULL){ highlighted_days_cnt = 0; while(1){ qdirent *dirinfo = ql_readdir(dir); if(dirinfo == NULL){ break; } for( int i = 0; i < 31; i++){ if(strcmp(dirinfo->d_name, filenames[i]) == 0){ highlighted_days[highlighted_days_cnt].day = atoi(filenames[i]); highlighted_days_cnt++; break; } } } lv_calendar_set_highlighted_dates(screen3_calender, highlighted_days, highlighted_days_cnt);//高亮对应的日期 ql_closedir(dir); } // else{ // LV_LOG_USER("no date need highlight\n"); // } } //点击使spinbox数值+1 void lv_spinbox_increment_event_cb(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); if(code == LV_EVENT_SHORT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) { //如果可以点击进入回调函数,代表一定有数据 LV_LOG_USER("increment the data"); lv_spinbox_increment(screen3_spinbox); //根据增加后的页数设置table数据: uint8_t current_page = (uint8_t)lv_spinbox_get_value(screen3_spinbox); if(current_page <= 0){ return; } uint8_t page_count = global_file_data_p.id_count/8 + 1; LV_LOG_USER("page:%d page_count:%d\n",current_page,page_count); setDataToTables(&global_file_data_p,current_page,page_count); } } //点击使spinbox数值-1 void lv_spinbox_decrement_event_cb(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); if(code == LV_EVENT_SHORT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) { //LV_LOG_USER("decrement the data"); lv_spinbox_decrement(screen3_spinbox); //根据增加后的页数设置table数据: uint8_t current_page = (uint8_t)lv_spinbox_get_value(screen3_spinbox); if(current_page <= 0){ return; } uint8_t page_count = global_file_data_p.id_count/8 + 1; //LV_LOG_USER("page:%d page_count:%d\n",current_page,page_count); setDataToTables(&global_file_data_p,current_page,page_count); } } //使用keyborad对textarea输入数字,按下回车按钮后隐藏textarea和keyboard并将数字设置到spinbox上 void screen3_textarea_keyboard_event_cb(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); lv_obj_t * target = lv_event_get_target(e); if(code == LV_EVENT_VALUE_CHANGED) { //当能进入这个回调,说明spinbox btn 可以点击,说明存在有用的数据 //获取被点击的btn的id int id = lv_btnmatrix_get_selected_btn(target); // const char * txt = lv_btnmatrix_get_btn_text(target, id); // LV_LOG_USER("%s was pressed\n", txt); uint8_t textarea_page_count = global_file_data_p.id_count/8 + 1; uint8_t textarea_page = 0; //回车被点击 if(id == 11){ //隐藏textarea和keyboard lv_obj_add_flag(screen3_spinbox_label_textarea,LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(btnm,LV_OBJ_FLAG_HIDDEN); screen3_spinbox_btnm_teatarea_flag = 0; //获取此时textarea的文本值 const char * textarea_value = lv_textarea_get_text(screen3_spinbox_label_textarea); //当存在文本时 if (textarea_value[0] != '\0'){ uint8_t value = atoi(textarea_value); if(value > 0 && value tm_year + 1900; // 年份需要加上1900 int month = local_time->tm_mon + 1; // 月份从0开始,需要加1 int day = local_time->tm_mday; char calendar[11]; sprintf(calendar,"%d.%d.%d",year,month,day); */ lv_label_set_text(screen3_calender_dsc_label,"2024.01.10"); /*****************************************************显示页数的spinbox**********************************************************/ //创建承载spinbox和描述label的btn scrren3_spinbox_btn = lv_btn_create(ui_Screen3); lv_obj_set_pos(scrren3_spinbox_btn,330,0); lv_obj_set_size(scrren3_spinbox_btn,80,30); lv_obj_set_style_bg_color(scrren3_spinbox_btn,lv_color_hex(0xFFFFFFF),0); //点击显示输入文本框和键盘 lv_obj_add_event_cb(scrren3_spinbox_btn, lv_spinbox_textarea_event_cb, LV_EVENT_CLICKED, NULL); //创建spinbox screen3_spinbox = lv_spinbox_create(scrren3_spinbox_btn); lv_spinbox_set_digit_format(screen3_spinbox, 2, 2); lv_obj_set_width(screen3_spinbox, 46); lv_obj_align(screen3_spinbox,LV_ALIGN_CENTER,-15,0); lv_spinbox_set_value(screen3_spinbox,1);//设置初始为第一页 lv_obj_set_style_border_opa(screen3_spinbox,0,0); lv_obj_set_style_outline_opa(screen3_spinbox,0,0); //创建显示总页数的label screen3_spinbox_dsc_label = lv_label_create(scrren3_spinbox_btn); lv_obj_set_size(screen3_spinbox_dsc_label,50,34); lv_obj_align_to(screen3_spinbox_dsc_label,screen3_spinbox,LV_ALIGN_OUT_RIGHT_MID,0,8); lv_obj_set_style_text_font(screen3_spinbox_dsc_label,&lv_font_montserrat_16,0); lv_label_set_text(screen3_spinbox_dsc_label,"/100"); lv_obj_set_style_border_opa(screen3_spinbox_dsc_label,0,0); lv_obj_set_style_outline_opa(screen3_spinbox_dsc_label,0,0); /*****************************************************控制翻页的button**********************************************************/ btn_page_plus = lv_btn_create(ui_Screen3); lv_obj_set_size(btn_page_plus, 30, 30); lv_obj_set_pos(btn_page_plus,410,0); lv_obj_set_style_bg_img_src(btn_page_plus, LV_SYMBOL_PLUS, 0); btn_page_reduce = lv_btn_create(ui_Screen3); lv_obj_set_size(btn_page_reduce, 30, 30); lv_obj_set_pos(btn_page_reduce,300,0); lv_obj_set_style_bg_img_src(btn_page_reduce, LV_SYMBOL_MINUS, 0); //spinbox页数+1 lv_obj_add_event_cb(btn_page_plus, lv_spinbox_increment_event_cb, LV_EVENT_ALL,NULL); //spinbox页数-1 lv_obj_add_event_cb(btn_page_reduce, lv_spinbox_decrement_event_cb, LV_EVENT_ALL,NULL); /*****************************************************记录数据的table**********************************************************/ char text[6][16] = {"桩点号","最大喷浆量","最大深度","平均电流","开始时间","结束时间"}; int align[6] = {-210,-125,-40,35,120,210}; int size[6] = {50,80,70,70,70,70}; for(int i = 0; i < 6; i++){ lv_obj_t * screen3_label = lv_label_create(ui_Screen3); lv_obj_set_size(screen3_label,size[i],30); lv_obj_align(screen3_label,LV_ALIGN_TOP_MID, align[i], 45); lv_obj_clear_flag(screen3_label,LV_OBJ_FLAG_SCROLLABLE); lv_label_set_text(screen3_label,text[i]); lv_obj_set_style_text_font(screen3_label, &lv_font_chinese_12_name, 0); } data_table1 = lv_table_create(ui_Screen3); data_table2 = lv_table_create(ui_Screen3); data_table3 = lv_table_create(ui_Screen3); data_table4 = lv_table_create(ui_Screen3); data_table5 = lv_table_create(ui_Screen3); data_table6 = lv_table_create(ui_Screen3); data_table7 = lv_table_create(ui_Screen3); data_table8 = lv_table_create(ui_Screen3); lv_obj_t*screen3_data_tables[] = {data_table1, data_table2, data_table3, data_table4,data_table5, data_table6, data_table7, data_table8}; int align_data[] = {-224,-192,-160,-128,-96,-64,-32,0}; for(int r=0;r<8;r++){ lv_obj_align(screen3_data_tables[r],LV_ALIGN_BOTTOM_MID, 10, align_data[r]);//设置位置 lv_table_set_row_cnt(screen3_data_tables[r],1);//设置行列数 lv_table_set_col_cnt(screen3_data_tables[r],6); lv_obj_set_height(screen3_data_tables[r],35); lv_obj_set_style_border_width(screen3_data_tables[r],1,LV_PART_MAIN); lv_obj_set_style_pad_top(screen3_data_tables[r],0,LV_PART_ITEMS); lv_obj_clear_flag(screen3_data_tables[r],LV_OBJ_FLAG_SCROLLABLE); lv_table_set_col_width(screen3_data_tables[r],0,75); lv_table_set_col_width(screen3_data_tables[r],1,87); lv_table_set_col_width(screen3_data_tables[r],2,75); lv_table_set_col_width(screen3_data_tables[r],3,80); lv_table_set_col_width(screen3_data_tables[r],4,100); lv_table_set_col_width(screen3_data_tables[r],5,100); //当点击table时,生成对应的chart lv_obj_add_event_cb(screen3_data_tables[r], screen3_data_table_chart_create, LV_EVENT_CLICKED,NULL); } /*****************************************************calendar**********************************************************/ screen3_calender = lv_calendar_create(ui_Screen3); lv_obj_set_size(screen3_calender, 480, 287); lv_obj_align(screen3_calender,LV_ALIGN_BOTTOM_MID,0,0); lv_obj_add_flag(screen3_calender,LV_OBJ_FLAG_HIDDEN); //选择日期,读取对应日期文件,设置table,更新label lv_obj_add_event_cb(screen3_calender, screen3_calender_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_t * calendar_dropdown_background = lv_calendar_header_dropdown_create(screen3_calender); calendar_dropdown_year = lv_obj_get_child(calendar_dropdown_background,0); calendar_dropdown_month = lv_obj_get_child(calendar_dropdown_background,1); //当日历的年月改变时,读取相对应的路径并高亮对应日期 lv_obj_add_event_cb(calendar_dropdown_year, screen3_calender_dropdown_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_add_event_cb(calendar_dropdown_month, screen3_calender_dropdown_cb, LV_EVENT_VALUE_CHANGED, NULL); /*****************************************************textarea+keyboard**********************************************************/ //创建输入文本框并隐藏 screen3_spinbox_label_textarea = lv_textarea_create(ui_Screen3); lv_textarea_set_one_line(screen3_spinbox_label_textarea, true); lv_obj_align(screen3_spinbox_label_textarea, LV_ALIGN_TOP_MID, 0, 32); lv_obj_set_width(screen3_spinbox_label_textarea,480); lv_obj_add_state(screen3_spinbox_label_textarea, LV_STATE_FOCUSED); lv_obj_add_flag(screen3_spinbox_label_textarea,LV_OBJ_FLAG_HIDDEN); //为输入文本框创建输入键盘 static const char * btnm_map[] = { "1", "2", "3", "\n", "4", "5", "6", "\n", "7", "8", "9", "\n", LV_SYMBOL_BACKSPACE, "0", LV_SYMBOL_NEW_LINE, ""}; btnm = lv_btnmatrix_create(ui_Screen3); lv_obj_set_size(btnm, 480, 250); lv_obj_align(btnm, LV_ALIGN_BOTTOM_MID, 0, 0); lv_obj_clear_flag(btnm, LV_OBJ_FLAG_CLICK_FOCUSABLE); /*To keep the text area focused on button clicks*/ lv_btnmatrix_set_map(btnm, btnm_map); lv_obj_add_flag(btnm,LV_OBJ_FLAG_HIDDEN); //回车时设置label,隐藏ta和btnm lv_obj_add_event_cb(btnm, screen3_textarea_keyboard_event_cb, LV_EVENT_ALL, NULL); //将键盘输入的数据键入到textarea上 lv_obj_add_event_cb(btnm, screen3_btnm_event_handler, LV_EVENT_VALUE_CHANGED, screen3_spinbox_label_textarea); }