FluxDC/components/FluxTime/FluxTime.c

90 lines
2.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file FluxTimer.c
* @brief 时间同步源文件
*
* 用于芯片内部时钟同步Not Used
*
* @author wang xiang en
* @date 2025-04-19
* @version 版本号
* @copyright 版权声明((C)2025, YUWELL MEDTECH Co.ltd
*/
#include <stdio.h>
#include "FluxTime.h"
#include "ui.h"
#include "esp_err.h"
#include "esp_log.h"
/*包含SNTP的头文件*/
#include "lwip/apps/sntp.h"
#include <time.h>
/**
* @brief 时间同步函数
*
* 用于时间同步操作,无网络环境无法使用。
*
* @param[in] arg not used
*/
void time_synic_task(void *arg)
{
/*用来进行显示的字符串*/
char strftime_buf[64];
char time_str[64];
/*大数*/
time_t now = 0;
/*时间结构体*/
struct tm timeinfo = {0};
ESP_LOGI("SNTP..........","SNTP task start");
while (1)
{
/*1秒钟更新一下显示时间*/
vTaskDelay(SYSTEM_TIME_UPDATE_INTERVAL_SEC*1000 / portTICK_PERIOD_MS);
time(&now);
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
lv_label_set_text_fmt(ui_pageTimeDebug_labelHearderTime,"%s",strftime_buf);
ESP_LOGI("SNTP","The current date/time in China is: %s", strftime_buf);
/* 更新时间信息 */
lv_label_set_text_fmt(ui_pageHome_labelTime,"%d:%d",timeinfo.tm_hour,timeinfo.tm_min);
lv_label_set_text_fmt(ui_pageTime_time,"%d:%d:%d",timeinfo.tm_hour,timeinfo.tm_min,timeinfo.tm_sec);
lv_label_set_text_fmt(ui_pageTime_date,"%d-%d-%d %d",timeinfo.tm_year+1900,timeinfo.tm_mon+1,timeinfo.tm_mday,timeinfo.tm_wday);
}
}
/**
* @brief 时间获取API
*
* 将时间转换为字符串上交
*
* @return 时间字符串提交函数
*/
char* get_time_str(void)
{
char strftime_buf[64];
time_t now = 0;
struct tm timeinfo = {0};
/* 获取时间 */
time(&now);
/* 获取时间字符串 */
localtime_r(&now, &timeinfo);
/* 返回时间字符串 */
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
return strftime_buf;
}