赞
踩
链接:https://pan.baidu.com/s/1_nBFausDp_TqTG74boxFlw
提取码:mjdp
/** * @brief 创建模拟时钟界面 */ void analog( lv_obj_t *win) { lv_obj_t* central = win; lv_obj_set_size(central, LV_HOR_RES_MAX, LV_VER_RES_MAX); lv_obj_set_pos(central, 0, 0); lv_obj_t * img = lv_img_create(central,NULL); lv_img_set_src(img, &watch_bg); //加载表盘 lv_obj_set_size(img, 200, 200); lv_obj_set_auto_realign(img, true); lv_obj_align(img, central, LV_ALIGN_CENTER, 0, 0); lvHour = lv_img_create(central,NULL); // 时针 lv_img_set_src( lvHour, &hour); lv_obj_align( lvHour, img,LV_ALIGN_CENTER, 0, 0); uint16_t h = Hour * 300 + Minute * 5; lv_img_set_angle( lvHour, h); lvMinute = lv_img_create(central,NULL); // 分针 lv_img_set_src( lvMinute, &minute); lv_obj_align( lvMinute, img,LV_ALIGN_CENTER, 0, 0); lv_img_set_angle( lvHour, Minute*60); lvSecond = lv_img_create(central,NULL); //秒针 lv_img_set_src( lvSecond, &second); lv_obj_align( lvSecond, img,LV_ALIGN_CENTER, 0, 0); lv_img_set_angle( lvSecond, Second*60); lv_task_create(update_time, 1000, LV_TASK_PRIO_LOW, NULL); // 1秒任务 }
/** * @brief 1秒钟更新时间 */ static void update_time(void *arg) { if(lvHour !=NULL) { // Hour,Minute,Second; uint16_t h = Hour * 300 + Minute * 5; lv_img_set_angle(lvHour, h); lv_img_set_angle(lvMinute, Minute * 6 * 10); lv_img_set_angle(lvSecond, Second * 6 * 10); printf("h %d m %d s %d\n", Hour, Minute, Second); } if (++Second >= 60) { Second = 0; if (++Minute >= 60) { Minute = 0; if (++Hour >= 12) Hour = 0; } } }
analog(lv_scr_act());
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。