完成天气、联网时钟

This commit is contained in:
lxbpxylps@126.com 2021-09-28 14:27:44 +08:00
parent 821c3616f8
commit 1407d87385
4 changed files with 232 additions and 0 deletions

View File

@ -0,0 +1,119 @@
#include "sys.h"
#include "systick.h"
#include "key.h"
#include "GameEngine.h"
#include "WLAN.h"
#include "APP_Weather.h"
/**************************************** 私有定义 ****************************************/
typedef struct
{
uint8_t city[20];
uint8_t weather[20];
uint8_t temp[20];
uint8_t wind_dir[20];
uint8_t wind_force[20];
uint8_t humidity[20];
uint8_t quality[20];
} Weather;
/*****************************************************************************************/
/**************************************** 全局变量 ****************************************/
Weather weather;
uint8_t city_str[30];
/*****************************************************************************************/
/**************************************** 私有函数 ****************************************/
void APP_Weather_SetCity(uint8_t *str);
uint8_t APP_Weather_Sync(void);
/*****************************************************************************************/
/**
* @brief
*/
void APP_Weather_Launcher(void)
{
APP_Weather_SetCity("汉中");
GE_Draw_ClrAll(WHITE);
if (APP_Weather_Sync())
{
printf("连网获取天气成功\n天气: %s %s %s %s %s %s %s\n",
weather.city,
weather.weather,
weather.temp,
weather.wind_dir,
weather.wind_force,
weather.humidity,
weather.quality);
uint8_t temp_str[200];
sprintf(temp_str,
"城市:%s\n天气:%s\n温度:%s\n风向:%s\n风力:%s\n湿度:%s\n空气质量:%s\n",
weather.city,
weather.weather,
weather.temp,
weather.wind_dir,
weather.wind_force,
weather.humidity,
weather.quality);
GE_GUI_MsgBox(5, 5, 310, 230, "天气", temp_str, NULL);
}
else
{
printf("连网获取天气失败\n");
GE_GUI_MsgBox(5, 5, 310, 230, "天气", "连网获取天气失败", NULL);
}
KEY_WaitKey(JOY_L);
}
/**
* @brief
* @param str:
*/
void APP_Weather_SetCity(uint8_t *str)
{
strcpy(city_str, str);
}
/**
* @brief
* @retval 1 0
*/
uint8_t APP_Weather_Sync(void)
{
uint8_t weather_str[50];
if (WLAN_GetWeather(weather_str, city_str) != 1)
return 0;
uint8_t *p;
strtok(weather_str, "&");
strcpy(weather.city, weather_str);
p = strtok(NULL, "&");
strcpy(weather.weather, p);
p = strtok(NULL, "&");
strcpy(weather.temp, p);
p = strtok(NULL, "&");
strcpy(weather.wind_dir, p);
p = strtok(NULL, "&");
strcpy(weather.wind_force, p);
p = strtok(NULL, "&");
strcpy(weather.humidity, p);
p = strtok(NULL, "&");
strcpy(weather.quality, p);
return 1;
}

View File

@ -0,0 +1,6 @@
#ifndef __APP_WEATHER_H
#define __APP_WEATHER_H
void APP_Weather_Launcher(void);
#endif

86
User/Clock/Clock.c Normal file
View File

@ -0,0 +1,86 @@
#include "GameEngine.h"
#include "WLAN.h"
#include "Clock.h"
ClockTime clock_time = {0, 0, 0, 0, 0, 0};
uint8_t is_disp = 0;
uint16_t disp_x;
uint16_t disp_y;
uint8_t disp_mode;
void Clock_Init(void)
{
printf(
"连网获取时间是否成功: %d\n时间: %d-%d-%d %d:%d:%d\n",
Clock_Sync(),
clock_time.year,
clock_time.month,
clock_time.day,
clock_time.hour,
clock_time.minute,
clock_time.second);
}
uint8_t Clock_Sync(void)
{
uint8_t clock_time_str[20];
if (WLAN_GetNetClockTime(clock_time_str) != 1)
return 0;
uint8_t *p;
strtok(clock_time_str, "&");
sscanf(clock_time_str, "%d", &clock_time.year);
p = strtok(NULL, "&");
sscanf(p, "%d", &clock_time.month);
p = strtok(NULL, "&");
sscanf(p, "%d", &clock_time.day);
p = strtok(NULL, "&");
sscanf(p, "%d", &clock_time.hour);
p = strtok(NULL, "&");
sscanf(p, "%d", &clock_time.minute);
p = strtok(NULL, "&");
sscanf(p, "%d", &clock_time.second);
return 1;
}
void Clock_Handler(void)
{
clock_time.second++;
if (clock_time.second == 60)
{
clock_time.second = 0;
clock_time.minute++;
if (clock_time.minute == 60)
{
clock_time.minute = 0;
clock_time.hour++;
if (clock_time.hour == 24)
{
clock_time.hour = 0;
clock_time.day++;
}
}
}
// static char temp_str[20];
// if (is_disp)
// {
// sprintf(
// temp_str,
// "%04d %02d %02d %02d %02d %02d",
// clock_time.year,
// clock_time.month,
// clock_time.day,
// clock_time.hour,
// clock_time.minute,
// clock_time.second);
// GE_Font_Print(disp_x, disp_y, BORDER_MAX, BORDER_MAX, FONT_16, BLUE, WHITE, FALSE, temp_str);
// GE_Draw_Disp();
// }
}

21
User/Clock/Clock.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef __CLOCK_H
#define __CLOCK_H
#include "sys.h"
typedef struct
{
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} ClockTime;
void Clock_Init(void);
uint8_t Clock_Sync(void);
void Clock_Handler(void);
#endif