first commit

This commit is contained in:
wen
2025-09-30 13:01:24 +08:00
parent d8d17c8076
commit ec83999cef
40 changed files with 13830 additions and 136 deletions

View File

@@ -19,13 +19,11 @@
#ifdef RT_USING_ULOG
#include <ulog.h>
#endif
#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "aic_core.h"
#include "aic_hal_gpio.h"
@@ -40,7 +38,7 @@
#include "zigbee_fun.h"
// #include "cJSON.h"
#include <drivers/rtc.h>
#include "ESP32_Clock.h"
extern rt_mutex_t xGuiSemaphore;
@@ -142,13 +140,14 @@ void gpio_set_level(char *name, u32 value)
*/
//接收消息
rt_mq_t custom_rx_evt_queue = NULL; //定义一个队列返回变量
lv_timer_t * poweralarmtimer = NULL;//上电 时间错误警告
lv_timer_t * animationtimer = NULL;//动画定时器 窗帘 纱帘 卷帘 幕布等使用
int scenebarindex;//
void custom_Task(void *pvParameter);
rt_thread_t custom_thread = RT_NULL;
void custom_init(lv_ui *ui)
{
/* Add your codes here */
@@ -722,6 +721,16 @@ static void custom_rollersinfo_timerclose(lv_timer_t * timer)
}
}
static void custom_power_timealarm(lv_timer_t * timer)
{
if(guider_ui.scene_alarmtimecont)
{
lv_obj_del(guider_ui.scene_alarmtimecont);
}
lv_timer_del(poweralarmtimer);
poweralarmtimer=NULL;
}
void custom_Task(void *pvParameter)
{
ZIGEvent evt;
@@ -732,14 +741,16 @@ void custom_Task(void *pvParameter)
time_t now;
struct tm timeinfo;
// struct timeval tv;
// tv.tv_sec=(time_t)1741335863;//用本地时间 不用处理时区了
// tv.tv_usec=0;
struct timeval tv;
tv.tv_sec=(time_t)1735689600;//上电的默认时间 2025-01-01 08:00:00
tv.tv_usec=0;
// // int settimeofday(const struct timeval *tv , const struct timezone *tz);
// //tz参数为时区 通常将参数tz设置为NULL表示使用当前系统的时区
// //输入时间戳通过settimeofday()函数来设置系统时间,这个函数设置的精度可以精确到微秒
// settimeofday(&tv, NULL);//不用重新设置时区
settimeofday(&tv, NULL);//不用重新设置时区
//开启lv_time定时3s之后删除时间警告
poweralarmtimer = lv_timer_create(custom_power_timealarm,5000,NULL);
for(;;)
{
if(evt.buffStr)//接收到的是指针 用完释放内存
@@ -1067,9 +1078,11 @@ void custom_Task(void *pvParameter)
break;
//=======================================================================
case ZIG_STATE_RTC_CURRENT://显示
{
{//在RT-Thread中使用time()函数来获取当前的系统时间。这个函数返回一个time_t类型的值表示自1970年1月1日(UTC)以来的秒数
/* 获取当前时间 */
time(&now);
localtime_r(&now, &timeinfo);
/* 将time_t类型转换为struct tm类型 */
localtime_r(&now, &timeinfo);//localtime_r()先加上时区值再调用gmtime_r()转换为结构体
// //struct tm
// //{
// // int tm_sec; //分后的秒(0~61)
@@ -1083,16 +1096,18 @@ void custom_Task(void *pvParameter)
// // int tm_isdst; //夏令时标志(大于0说明夏令时有效等于0说明无效小于0说明信息不可用)
// //
// //};
// LOG_I("time==%d:%d:%d:%d:%02d:%02d:%02d:%02d:%02d",
// timeinfo.tm_isdst, //是否为夏时制
// timeinfo.tm_yday, //一年过去的天数
// timeinfo.tm_wday, //星期1对应星期一
// timeinfo.tm_year, //年距离1900年的差值默认是70
// timeinfo.tm_mon, //日期从0开始 0~11
// timeinfo.tm_mday, //日期从1开始
// timeinfo.tm_hour, //小时
// timeinfo.tm_min, //分钟
// timeinfo.tm_sec); //秒钟
LOG_I("now=%d",now);
LOG_I("zone:%d",tz_get());
LOG_I("time==%d:%d:%d:%d:%02d:%02d:%02d:%02d:%02d",
timeinfo.tm_isdst, //是否为夏时制
timeinfo.tm_yday, //一年过去的天数
timeinfo.tm_wday, //星期1对应星期一
timeinfo.tm_year+1900, //年距离1900年的差值默认是70
timeinfo.tm_mon+1, //日期从0开始 0~11
timeinfo.tm_mday, //日期从1开始
timeinfo.tm_hour, //小时
timeinfo.tm_min, //分钟
timeinfo.tm_sec); //秒钟
if((timeinfo.tm_min==59)&&(timeinfo.tm_sec==59))//每小时更新一次
{
ZIGEvent evtstate;
@@ -1133,6 +1148,20 @@ void custom_Task(void *pvParameter)
//printf("hh-angle:%d\r\n",angle);
lv_img_set_angle(guider_ui.screensaver_clock_hour, angle);//
}
if(guider_ui.dateinfopage)//时间开关页
{
lv_label_set_text_fmt(guider_ui.dateinfopage_timetxtlabel,"%02d:%02d",timeinfo.tm_hour,timeinfo.tm_min);
if(GET_nvs_Sys_Info_language()==LANG_CH)
{
lv_label_set_text_fmt(guider_ui.dateinfopage_datetxtlabel,"%d年%d月%d日",timeinfo.tm_year+1900,timeinfo.tm_mon+1,timeinfo.tm_mday);
}
else
{
lv_label_set_text_fmt(guider_ui.dateinfopage_datetxtlabel,"%s %d, %d",Menu_monList[timeinfo.tm_mon+1],timeinfo.tm_mday,timeinfo.tm_year+1900);
}
}
if(guider_ui.scene)//情景页时间
{
lv_label_set_text_fmt(guider_ui.scene_timelabel,"%02d:%02d",timeinfo.tm_hour,timeinfo.tm_min);
@@ -6095,6 +6124,224 @@ void custom_language_key_status(char key,lv_event_code_t code)
// evtstate.buffStr=NULL;
// rt_mq_send(custom_rx_evt_queue, &evtstate, sizeof(ZIGEvent));//上报给zigbee
}
static void month_erro_msgbox_callback(lv_event_t *event)
{
lv_event_code_t code = lv_event_get_code(event);
lv_obj_t * msgbox = lv_event_get_current_target(event);
if ((code == LV_EVENT_VALUE_CHANGED) && (msgbox != NULL))
{
lv_msgbox_close(msgbox);
}
}
void custom_datetime_key_status(char key,lv_event_code_t code)
{
switch(key)
{
case 1://自动获取时间开关
{
if (lv_obj_has_state(guider_ui.dateinfopage_sw_1, LV_STATE_CHECKED))
{//自动获取时间 禁用按钮
printf("on\r\n");
//日期按键禁止按下
lv_obj_add_state(guider_ui.dateinfopage_datebtn, LV_STATE_DISABLED);//off
//时间禁止允许按下
lv_obj_add_state(guider_ui.dateinfopage_timebtn, LV_STATE_DISABLED);//off
SET_nvs_Sys_Info_autoupdatetime(true);
nvs_eepom_sysInfo_update();
//立即去更新时间
ZIGEvent evt;
evt.event=ZIG_STATE_RTC_UPDATE;
evt.length=0;
evt.buffStr=NULL;
rt_mq_send(zig_rx_evt_queue, &evt, sizeof(ZIGEvent));//上报给zigbee
}
else
{//手动 允许按钮操作
printf("off\r\n");
//日期按键允许按下
lv_obj_clear_state(guider_ui.dateinfopage_datebtn, LV_STATE_DISABLED);//on
//时间按键允许按下
lv_obj_clear_state(guider_ui.dateinfopage_timebtn, LV_STATE_DISABLED);//on
SET_nvs_Sys_Info_autoupdatetime(false);
nvs_eepom_sysInfo_update();
}
}
break;
case 2://更改
{
LOG_I("custom_datetime_key_status");
/*
struct tm {
int tm_sec; // 秒 [0-59]
int tm_min; // 分 [0-59]
int tm_hour; // 时 [0-23]
int tm_mday; // 日 [1-31]
int tm_mon; // 月 [0-11]0 代表 1 月)
int tm_year; // 年(自 1900 年的偏移,如 2024 年为 124
int tm_wday; // 星期 [0-6]0 代表周日)
int tm_yday; // 年中的第几天 [0-365]
int tm_isdst; // 夏令时标志UTC 时间中通常为 0
};
*/
////timeinfo.tm_sec //秒钟
//struct tm timeinfo = {0};
char str[64];
//uint16_t int year, int month, int day, int hour, int minute, int second;//
//年
uint16_t sel_opt_idt=lv_dropdown_get_selected(guider_ui.datesetpage_yearddlist);//0~99
lv_dropdown_get_selected_str(guider_ui.datesetpage_yearddlist,str,sizeof(str));
int year=sel_opt_idt+2024;//0~99-->2024~2099
LOG_I("year:%s---%d",str,year);
//timeinfo.tm_year=(int)((year)-1900);
//月
sel_opt_idt=lv_dropdown_get_selected(guider_ui.datesetpage_moonddlist);//0~11
lv_dropdown_get_selected_str(guider_ui.datesetpage_moonddlist,str,sizeof(str));
int month=sel_opt_idt+1;//0~11-->1~12
LOG_I("mon:%s---%d",str,month);
//timeinfo.tm_mon=month-1;
//日
sel_opt_idt=lv_dropdown_get_selected(guider_ui.datesetpage_sunddlist);//0~30
lv_dropdown_get_selected_str(guider_ui.datesetpage_sunddlist,str,sizeof(str));
int day=sel_opt_idt+1;//0~30-->1~31
LOG_I("sun:%s---%d",str,sel_opt_idt+1);
//timeinfo.tm_mday=day-1;
//时
sel_opt_idt=lv_dropdown_get_selected(guider_ui.datesetpage_hourddlist);//0~23
lv_dropdown_get_selected_str(guider_ui.datesetpage_hourddlist,str,sizeof(str));
int hour=sel_opt_idt;
LOG_I("hour:%s---%d",str,hour);
//timeinfo.tm_hour=hour;
//分
sel_opt_idt=lv_dropdown_get_selected(guider_ui.datesetpage_minuteddlist);//0~59
lv_dropdown_get_selected_str(guider_ui.datesetpage_minuteddlist,str,sizeof(str));
int minute=sel_opt_idt;
LOG_I("min:%s---%d",str,minute);
//timeinfo.tm_min=minute;
//1 3 5 7 8 10 12 31天
//4 6 9 11 30天
//2 28天
//卡月对应天 不能超过最大日
// if(
// (
// (month==1)
// ||(month==3)
// ||(month==5)
// ||(month==7)
// ||(month==8)
// ||(month==10)
// ||(month==12)
// )
// &&(day<=31)
// )
// {
// }
//警告
if(
( ( (month==4)||(month==6)||(month==9)||(month==11) ) && (day>30) )
||((month==2)&&(day>28))
)
{
char txtbuf[64];
if(GET_nvs_Sys_Info_language()==LANG_CH)
{
sprintf(txtbuf,"%d月没有%d日",month,day);
}
else
{
sprintf(txtbuf,"There is no %dth in %s",day,Menu_monList[month-1]);
}
//lv_obj_t * mbox1 = lv_msgbox_create(NULL,NULL, Menu_List[GET_nvs_Sys_Info_language()][MENU_LIST_System_Restartmsgbox], btns_chs[GET_nvs_Sys_Info_language()], false);
lv_obj_t * mbox1 = lv_msgbox_create(NULL,NULL, (const char *)txtbuf, btns_chs[GET_nvs_Sys_Info_language()], false);
lv_msgbox_t * mbox = (lv_msgbox_t *)mbox1;
// lv_obj_set_style_text_font(mbox->title, &lv_font_simsun_16, LV_PART_MAIN | LV_STATE_DEFAULT);//标题字体
// lv_obj_set_style_text_align(mbox->title, LV_TEXT_ALIGN_CENTER, 0);//标题居中显示
lv_obj_set_style_text_font(mbox->text, &lv_font_simsun_16, LV_PART_MAIN | LV_STATE_DEFAULT);//内容字体
lv_obj_set_style_text_align(mbox->text, LV_TEXT_ALIGN_CENTER, 0);//内容居中显示
lv_obj_set_style_text_font(mbox->btns, &lv_font_simsun_16, LV_PART_ITEMS | LV_STATE_DEFAULT);//按键字体
lv_obj_set_size(lv_msgbox_get_btns(mbox1), 250, 50);
lv_obj_center(mbox1);
lv_obj_add_event_cb((lv_obj_t *)mbox1,month_erro_msgbox_callback, LV_EVENT_ALL, NULL);
}
else
{
//时区
sel_opt_idt=lv_dropdown_get_selected(guider_ui.datesetpage_zoneddlist);//0~24
lv_dropdown_get_selected_str(guider_ui.datesetpage_zoneddlist,str,sizeof(str));
LOG_I("zone:%s---%d",str,sel_opt_idt-12);
tz_set(sel_opt_idt-12);
LOG_I("new read zone:%d",tz_get());
//UTC的起始时间为1970年1月1日 00:00:00协调世界时
//标准时间戳通常指的是UTC 协调世界时 )。时间戳以 1970年1月1日 零时UTC为起点
//标准时间戳:格林威治时间,以 1970.01.01 00:00:00 为起点到现在的总秒数。
//本地时间戳:考虑时区和夏令时的本地时间,即标准时间 ± 时差。一般设备以本地时间为准
//UTC +时区差*3600秒本地时间
//zone=(Localtime-standardtime)/3600
//UTC=本地时间-时区差*3600
//now()显示的是 UTC标准时间
//设置的时间当本地时间
// LOG_I("dateToEpoch:%d\r\n", dateToEpoch(2025, 7, 8, 18, 20, 0));//当地时间 1970开始计算的
// LOG_I("dateToEpoch2:%d\r\n", dateToEpoch(2025, 7, 8, 18, 20, 0)-tz_get()*3600);//utc时间
time_t Localtime=dateToEpoch(year, month, day, hour, minute, 0);//年月日转换为本地时间(1970开始计算的)
LOG_I("Localtime:%d\r\n", Localtime);
time_t standardtime=Localtime-tz_get()*3600;//本地时间转换为UTC标准时间戳
LOG_I("standardtime:%d\r\n",standardtime);
//更新时间 更新的是utc时间
struct timeval tv;
tv.tv_sec=(time_t)standardtime;//utc时间
tv.tv_usec=0;
settimeofday(&tv, NULL);//不用重新设置时区
// SET_nvs_Sys_Info_tzzone(zone);
// nvs_eepom_sysInfo_update();
//退出
if(!guider_ui.dateinfopage)
{
setup_scr_dateinfopage(&guider_ui);
}
lv_scr_load(guider_ui.dateinfopage);
if(guider_ui.datesetpage)
{
lv_obj_del(guider_ui.datesetpage);
guider_ui.datesetpage = NULL;
}
}
}
break;
default:
break;
}
}
// //实现原理 top层创建arc,默认是1s是1%,100s超时退出; 根据入网进程,改变animationtimer的周期 入网成功后定时器周期改为100ms 很快到达100%
void custom_network_timercb(lv_timer_t * timer)
{

View File

@@ -55,6 +55,8 @@ void custom_mianinfo_key_status(char key,lv_event_code_t code);
void custom_display_key_status(char key,lv_event_code_t code);
//语言
void custom_language_key_status(char key,lv_event_code_t code);
//时间设置
void custom_datetime_key_status(char key,lv_event_code_t code);
//网络页
void custom_network_key_status(char key,lv_event_code_t code);
//首屏