完成 HC-25
This commit is contained in:
parent
d7560cc5b0
commit
821c3616f8
32
Hardware/hc25/hc25.c
Normal file
32
Hardware/hc25/hc25.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
//HC25 库
|
||||||
|
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
#include "systick.h"
|
||||||
|
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
#include "hc25.h"
|
||||||
|
|
||||||
|
/**************************************** 私有变量 ****************************************/
|
||||||
|
|
||||||
|
uint8_t is_at_mode = 1; //开机时默认 AT 模式打开,防止出错
|
||||||
|
uint8_t at_cmd[30];
|
||||||
|
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
/**************************************** 私有函数 ****************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
void HC25_Init(void)
|
||||||
|
{
|
||||||
|
HC25_ExitATMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HC25_SendATCmd(uint8_t *cmd)
|
||||||
|
{
|
||||||
|
strcpy(at_cmd, "AT+");
|
||||||
|
strcat(at_cmd, cmd);
|
||||||
|
HC25_SendBuff(at_cmd, strlen(at_cmd) + 1);
|
||||||
|
}
|
||||||
39
Hardware/hc25/hc25.h
Normal file
39
Hardware/hc25/hc25.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
//HC25 ¿â
|
||||||
|
|
||||||
|
#ifndef __HC25_H
|
||||||
|
#define __HC25_H
|
||||||
|
|
||||||
|
#include "sys.h"
|
||||||
|
#include "uart.h"
|
||||||
|
|
||||||
|
#define HC25_COM COM2
|
||||||
|
|
||||||
|
#define HC25_SendBuff(__pdata__, __data_len__) \
|
||||||
|
Uart_SendBuf(HC25_COM, __pdata__, __data_len__); \
|
||||||
|
Delay_ms(50)
|
||||||
|
#define HC25_Receive(__pdata__) Uart_GetChar(HC25_COM, __pdata__)
|
||||||
|
#define HC25_ReceiveBuffUntil(__pdata__, __end_byte__, __timeout__) Uart_GetBuffUntil(HC25_COM, __pdata__, __end_byte__, __timeout__)
|
||||||
|
#define HC25_ClearSend Uart_ClearTxFifo(HC25_COM)
|
||||||
|
#define HC25_ClearReceive Uart_ClearRxFifo(HC25_COM)
|
||||||
|
#define HC25_EnterATMode \
|
||||||
|
if (is_at_mode == 0) \
|
||||||
|
{ \
|
||||||
|
HC25_SendBuff("+++", 4); \
|
||||||
|
Delay_ms(200); \
|
||||||
|
is_at_mode = 1; \
|
||||||
|
HC25_ClearReceive; \
|
||||||
|
}
|
||||||
|
#define HC25_ExitATMode \
|
||||||
|
if (is_at_mode == 1) \
|
||||||
|
{ \
|
||||||
|
HC25_SendATCmd("ENTM"); \
|
||||||
|
Delay_ms(200); \
|
||||||
|
is_at_mode = 0; \
|
||||||
|
HC25_ClearReceive; \
|
||||||
|
}
|
||||||
|
|
||||||
|
void HC25_Init(void);
|
||||||
|
|
||||||
|
void HC25_SendATCmd(uint8_t *cmd);
|
||||||
|
|
||||||
|
#endif
|
||||||
145
User/APP_Setting/APP_Setting.c
Normal file
145
User/APP_Setting/APP_Setting.c
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
//系统设置应用
|
||||||
|
|
||||||
|
#include "sys.h"
|
||||||
|
#include "systick.h"
|
||||||
|
|
||||||
|
#include "key.h"
|
||||||
|
#include "lcd.h"
|
||||||
|
#include "hc25.h"
|
||||||
|
|
||||||
|
#include "GameEngine.h"
|
||||||
|
#include "WLAN.h"
|
||||||
|
|
||||||
|
#include "APP_Setting.h"
|
||||||
|
|
||||||
|
/**************************************** 私有定义 ****************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
/**************************************** 全局变量 ****************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
/**************************************** 私有函数 ****************************************/
|
||||||
|
|
||||||
|
void APP_Setting_Msg(uint8_t *head, uint8_t *content);
|
||||||
|
|
||||||
|
/*****************************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 启动设置
|
||||||
|
*/
|
||||||
|
void APP_Setting_Launcher(void)
|
||||||
|
{
|
||||||
|
uint8_t content[4][GE_GUI_MENUBOX_CONTENT_LEN] = {"网络设置", "夜间模式", "关于", "退出设置"};
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
label_menu_1:
|
||||||
|
GE_Draw_ClrAll(WHITE);
|
||||||
|
switch (GE_GUI_MenuBox(5, 5, 310, 230, "系统设置", 4, content, NULL))
|
||||||
|
{
|
||||||
|
case 0: //退出设置
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: //网络设置
|
||||||
|
{
|
||||||
|
uint8_t content[1][GE_GUI_MENUBOX_CONTENT_LEN] = {"网络信息"};
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
GE_Draw_Fill(5, 5, 310, 230, WHITE);
|
||||||
|
switch (GE_GUI_MenuBox(5, 5, 310, 230, "网络设置", 1, content, NULL))
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
goto label_menu_1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
GE_Draw_Fill(5, 5, 310, 230, WHITE);
|
||||||
|
|
||||||
|
uint8_t temp_str[80];
|
||||||
|
|
||||||
|
if (WLAN_CheckNet())
|
||||||
|
{
|
||||||
|
uint8_t temp_ip_str[20];
|
||||||
|
uint8_t temp_ipaddr_str[40];
|
||||||
|
|
||||||
|
Delay_ms(50);
|
||||||
|
if (WLAN_GetIP(temp_ip_str) != 1)
|
||||||
|
strcpy(temp_ip_str, "查询失败");
|
||||||
|
Delay_ms(50);
|
||||||
|
if (WLAN_GetIPAddr(temp_ipaddr_str) != 1)
|
||||||
|
strcpy(temp_ipaddr_str, "查询失败");
|
||||||
|
|
||||||
|
sprintf(temp_str, "网络已连接\n\nIP地址:%s\nIP归属地:%s", temp_ip_str, temp_ipaddr_str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy(temp_str, "网络未连接");
|
||||||
|
}
|
||||||
|
|
||||||
|
GE_GUI_MsgBox(5, 5, 310, 230, "网络设置", temp_str, NULL);
|
||||||
|
|
||||||
|
KEY_WaitKey(JOY_L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: //夜间模式
|
||||||
|
{
|
||||||
|
uint8_t content[2][GE_GUI_MENUBOX_CONTENT_LEN] = {"开启", "关闭"};
|
||||||
|
|
||||||
|
GE_Draw_Fill(5, 5, 310, 230, WHITE);
|
||||||
|
switch (GE_GUI_MenuBox(5, 5, 310, 230, "夜间模式", 2, content, NULL))
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
LCD_SendCmd(LCD_CMD_DINVON);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
LCD_SendCmd(LCD_CMD_DINVOFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3: //关于
|
||||||
|
{
|
||||||
|
GE_Draw_Fill(5, 5, 310, 230, WHITE);
|
||||||
|
GE_GUI_MsgBox(5, 5, 310, 230, "关于", "STM32Player v0.2\nPowered By StopPointTeam.\nAll Rights Reversed.\n\n版权所有,盗版必究", NULL);
|
||||||
|
|
||||||
|
KEY_WaitKey(JOY_L);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4: //退出设置
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 消息框,任意键按下后退出
|
||||||
|
* @param head: 标题
|
||||||
|
* @param content: 内容
|
||||||
|
*/
|
||||||
|
void APP_Setting_Msg(uint8_t *head, uint8_t *content)
|
||||||
|
{
|
||||||
|
GE_Draw_Fill(60, 75, 200, 90, WHITE);
|
||||||
|
GE_GUI_MsgBox(60, 75, 200, 90, head, content, NULL);
|
||||||
|
KEY_WaitKey(JOY_L);
|
||||||
|
}
|
||||||
8
User/APP_Setting/APP_Setting.h
Normal file
8
User/APP_Setting/APP_Setting.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//系统设置应用
|
||||||
|
|
||||||
|
#ifndef __APP_SETTING
|
||||||
|
#define __APP_SETTING
|
||||||
|
|
||||||
|
void APP_Setting_Launcher(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
86
User/WLAN/WLAN.c
Normal file
86
User/WLAN/WLAN.c
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
//WLAN ¿â
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
#include "systick.h"
|
||||||
|
|
||||||
|
#include "led.h"
|
||||||
|
#include "hc25.h"
|
||||||
|
|
||||||
|
#include "Clock.h"
|
||||||
|
|
||||||
|
#include "WLAN.h"
|
||||||
|
|
||||||
|
uint8_t WLAN_CheckNet(void)
|
||||||
|
{
|
||||||
|
uint8_t str[6];
|
||||||
|
|
||||||
|
HC25_ClearReceive;
|
||||||
|
HC25_SendBuff("checknet", 9);
|
||||||
|
|
||||||
|
str[0] = '\0';
|
||||||
|
if (HC25_ReceiveBuffUntil(str, '\n', 1000) && strcmp(str, "OK") == 0)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t WLAN_GetIP(uint8_t *ip_str)
|
||||||
|
{
|
||||||
|
HC25_ClearReceive;
|
||||||
|
HC25_SendBuff("ip", 3);
|
||||||
|
|
||||||
|
ip_str[0] = '\0';
|
||||||
|
|
||||||
|
if (HC25_ReceiveBuffUntil(ip_str, '\n', 1000) && strcmp(ip_str, "OK") == 0)
|
||||||
|
if (HC25_ReceiveBuffUntil(ip_str, '\n', 1000))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t WLAN_GetIPAddr(uint8_t *ipaddr_str)
|
||||||
|
{
|
||||||
|
HC25_ClearReceive;
|
||||||
|
HC25_SendBuff("ipaddr", 7);
|
||||||
|
|
||||||
|
ipaddr_str[0] = '\0';
|
||||||
|
|
||||||
|
if (HC25_ReceiveBuffUntil(ipaddr_str, '\n', 1000) && strcmp(ipaddr_str, "OK") == 0)
|
||||||
|
if (HC25_ReceiveBuffUntil(ipaddr_str, '\n', 1000))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t WLAN_GetNetClockTime(uint8_t *clock_time_str)
|
||||||
|
{
|
||||||
|
HC25_ClearReceive;
|
||||||
|
HC25_SendBuff("time", 5);
|
||||||
|
|
||||||
|
clock_time_str[0] = '\0';
|
||||||
|
|
||||||
|
if (HC25_ReceiveBuffUntil(clock_time_str, '\n', 1000) && strcmp(clock_time_str, "OK") == 0)
|
||||||
|
if (HC25_ReceiveBuffUntil(clock_time_str, '\n', 1000))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t WLAN_GetWeather(uint8_t *weather_str, uint8_t *city_str)
|
||||||
|
{
|
||||||
|
uint8_t temp_str[15] = "weather=";
|
||||||
|
|
||||||
|
HC25_ClearReceive;
|
||||||
|
strcat(temp_str, city_str);
|
||||||
|
HC25_SendBuff(temp_str, strlen(temp_str) + 1);
|
||||||
|
|
||||||
|
weather_str[0] = '\0';
|
||||||
|
|
||||||
|
if (HC25_ReceiveBuffUntil(weather_str, '\n', 1000) && strcmp(weather_str, "OK") == 0)
|
||||||
|
if (HC25_ReceiveBuffUntil(weather_str, '\n', 1000))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
16
User/WLAN/WLAN.h
Normal file
16
User/WLAN/WLAN.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//WLAN ¿â
|
||||||
|
|
||||||
|
#ifndef __WLAN_H
|
||||||
|
#define __WLAN_H
|
||||||
|
|
||||||
|
#include "sys.h"
|
||||||
|
|
||||||
|
#include "Clock.h"
|
||||||
|
|
||||||
|
uint8_t WLAN_CheckNet(void);
|
||||||
|
uint8_t WLAN_GetIP(uint8_t *ip_str);
|
||||||
|
uint8_t WLAN_GetIPAddr(uint8_t *ipaddr_str);
|
||||||
|
uint8_t WLAN_GetNetClockTime(uint8_t *clock_time_str);
|
||||||
|
uint8_t WLAN_GetWeather(uint8_t *weather_str, uint8_t *city_str);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user