#include "main.h"
#include "gpio.h"
#include "USART.h"
#include "Delay.h"
#include "i2c.h"
#include "AHT10_S.h"
#include "lcd.h"
#include "stdio.h"
#include "touch.h"
#include "tim.h"
#include "lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"
#include "ADC.h"
#include "WIFI.h"
#include "usart2.h"
#include "cJSON.h"
#include "lvgl_text.h"
#include "jonsson.h"
#include "time10.h"
#include "FreeRTOS.h"
#include "task.h"
void GET_Time();
void GET_DATA();
int64_t st_time;
int64_t end_time;
int64_t st_data;
int64_t end_data;
char HUMI[64];
char TEMP[64];
uint8_t cp_time_buff[1024];
char* time_p;
char* weed_p;
cJSON* TIME;
cJSON* result;
cJSON* DAT;
char* one_p;
char* tow_p;
char* three_p;
int16_t temp1;
int16_t humi1;
StackType_t xTask3Static[1500];
StaticTask_t xTaskTCB;
StackType_t xIdle3Static[1500];
StaticTask_t xIdleTCB;
StackType_t xITimeStatic[1500];
StaticTask_t xITimeTCB;
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,StackType_t ** ppxIdleTaskStackBuffer,uint32_t * pulIdleTaskStackSize ){
*ppxIdleTaskTCBBuffer=&xIdleTCB;
*ppxIdleTaskStackBuffer=xIdle3Static;
*pulIdleTaskStackSize=1500;
}
void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
uint32_t * pulTimerTaskStackSize ){
* ppxTimerTaskTCBBuffer=&xITimeTCB;
* ppxTimerTaskStackBuffer=xITimeStatic;
* pulTimerTaskStackSize =1500;
}
void Task1Funtion(void* param){
for(;;){
}
}
void Task2Funtion(void* param){
AT_GET_Weather_dat();
JSON_CP_Dat(Rxbuff);
printf("--------------------------------------------------------\r\n");
AT_GET_API_TIME();
for(;;)
{
vTaskDelay(20000);
GET_DATA();
GET_Time();
//GET_Time();
//vTaskDelay(1);
}
}
void Task3Funtion(void* param){
LCD_Init();
tp_dev.init();
lv_init();
lv_port_disp_init();
lv_port_indev_init();
lvgl_dome();
//解析时间
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(data);
lv_label_set_text(label_days,one_dat);
one_p=one_dat+6;
tow_p=tow_dat+6;
three_p=three_dat+6;
lv_label_set_text(Time_one,one_p);
lv_label_set_text(Time_tow,tow_p);
lv_label_set_text(Time_three,three_p);
//解析温度
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(high);
sprintf(TEMP,"%sC",one_dat);
int temp_dat=atoi(one_dat);
lv_label_set_text(temp_label,TEMP);
//解析湿度
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(humidity);
sprintf(HUMI,"%s%%",one_dat);
int humi_dat=atoi(one_dat);
lv_label_set_text(humi_label,HUMI);
lvgl_Indoor_humi_temp_display(temp_dat,humi_dat);
chart_display_now(temp_dat,humi_dat);
//解析天气
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(code_day);
int weather=atoi(one_dat);
int weather_tow=atoi(tow_dat);
int weather_three=atoi(three_dat);
lvgl_Right_display_weather(weather);
lvgl_weather_one_display(weather);
lvgl_weather_tow_display(weather_tow);
lvgl_weather_three_display(weather_three);
//解析时间
TIME=cJSON_Parse((char*)Rxbuff);
result=cJSON_GetObjectItem(TIME,"result");
//cJSON* Date=cJSON_GetArrayItem(result,0);
DAT=cJSON_GetObjectItem(result,"datetime_1");
time_p=DAT->valuestring+11;
printf("\r\nTIME=%s\r\n",time_p);
lv_label_set_text(label_time,time_p);
cJSON_Delete(TIME);
//解析星期
TIME=cJSON_Parse((char*)Rxbuff);
result=cJSON_GetObjectItem(TIME,"result");
DAT=cJSON_GetObjectItem(result,"week_1");
weed_p=DAT->valuestring;
printf("WEED=%s\r\n",weed_p);
int weed=atoi(weed_p);
lvgl_Right_display_weed(weed);
lvgl_Weed_display(weed);
cJSON_Delete(TIME);
uint32_t i;
while(1){
tp_dev.scan(0);
lv_task_handler();
}
}
int main(void)
{
TaskHandle_t xTask;
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
Delay_init(180);
ADC_Config();
uart_init(115200);
printf("begin...\r\n");
USART_config();
MX_TIM8_Init();
xTaskCreate(Task1Funtion,"Task1",1500,NULL,1,&xTask);
xTaskCreate(Task2Funtion,"Task2",1500,NULL,1,NULL);
xTaskCreateStatic(Task3Funtion,"Task3",1500,NULL,1,xTask3Static,&xTaskTCB);
vTaskStartScheduler();
while (1)
{
// GET_DATA(20000);
// GET_Time(600000);
//atoi();//字符串转整形
// tp_dev.scan(0);
// lv_task_handler();
}
}
//**********************刷新时间
void GET_DATA(){
AT_WIFIMODE(STA);
printf("\n");
AT_CONNECT_WIFI(ssid,pass);
printf("\n");
AT_Connect_TCP(TCP_IP_TIME);
printf("\n");
AT_SET_TCPMODE(PT);
printf("\n");
AT_SEND_TCP();
AT_SEND_MES(TCP_GET_TIMES);
AT_BAKE_SEND();
//解析时间
cJSON* TIME=cJSON_Parse((char*)Rxbuff);
cJSON* result=cJSON_GetObjectItem(TIME,"result");
//cJSON* Date=cJSON_GetArrayItem(result,0);
cJSON* DAT=cJSON_GetObjectItem(result,"datetime_1");
time_p=DAT->valuestring+11;
printf("\r\nTIME=%s\r\n",time_p);
cJSON_Delete(TIME);
lv_label_set_text(label_time,time_p);
//解析星期
TIME=cJSON_Parse((char*)Rxbuff);
result=cJSON_GetObjectItem(TIME,"result");
DAT=cJSON_GetObjectItem(result,"week_1");
weed_p=DAT->valuestring;
printf("\r\nWEED=%s\r\n",weed_p);
int weed=atoi(weed_p);
lvgl_Right_display_weed(weed);
lvgl_Weed_display(weed);
cJSON_Delete(TIME);
}
//************************************刷新温湿度和日期
void GET_Time(){
AT_GET_Weather_dat();
JSON_CP_Dat(Rxbuff);
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(data);
lv_label_set_text(label_days,one_dat);
one_p=one_dat+6;
tow_p=tow_dat+6;
three_p=three_dat+6;
lv_label_set_text(Time_one,one_p);
lv_label_set_text(Time_tow,tow_p);
lv_label_set_text(Time_three,three_p);
//解析温度
JSON_CP_Dat(Rxbuff);
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(high);
sprintf(TEMP,"%sC",one_dat);
int temp_dat=atoi(one_dat);
lv_label_set_text(temp_label,TEMP);
//解析湿度
JSON_CP_Dat(Rxbuff);
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(humidity);
sprintf(HUMI,"%s%%",one_dat);
int humi_dat=atoi(one_dat);
lv_label_set_text(humi_label,HUMI);
lvgl_Indoor_humi_temp_display(temp_dat,humi_dat);
chart_display_now(temp_dat,humi_dat);
//解析天气
JSON_CP_Dat(Rxbuff);
JSON_Read_buf(CP_Rxbuff);
JSON_GET_three_Dat(code_day);
int weather=atoi(one_dat);
int weather_tow=atoi(tow_dat);
int weather_three=atoi(three_dat);
lvgl_Right_display_weather(weather);
lvgl_weather_one_display(weather);
lvgl_weather_tow_display(weather_tow);
lvgl_weather_three_display(weather_three);
}