diff --git a/User/APP_Weather/APP_Weather.c b/User/APP_Weather/APP_Weather.c new file mode 100644 index 0000000..a6a3ed0 --- /dev/null +++ b/User/APP_Weather/APP_Weather.c @@ -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; +} diff --git a/User/APP_Weather/APP_Weather.h b/User/APP_Weather/APP_Weather.h new file mode 100644 index 0000000..a0810aa --- /dev/null +++ b/User/APP_Weather/APP_Weather.h @@ -0,0 +1,6 @@ +#ifndef __APP_WEATHER_H +#define __APP_WEATHER_H + +void APP_Weather_Launcher(void); + +#endif diff --git a/User/Clock/Clock.c b/User/Clock/Clock.c new file mode 100644 index 0000000..d52eedf --- /dev/null +++ b/User/Clock/Clock.c @@ -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(); + // } +} diff --git a/User/Clock/Clock.h b/User/Clock/Clock.h new file mode 100644 index 0000000..f7e81fd --- /dev/null +++ b/User/Clock/Clock.h @@ -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