新增 APP_Ball 通讯测试应用
This commit is contained in:
parent
f677bbecc8
commit
47cee72ffa
162
User/APP_Ball/APP_Ball.c
Normal file
162
User/APP_Ball/APP_Ball.c
Normal file
@ -0,0 +1,162 @@
|
||||
//移动球应用
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
#include "sys.h"
|
||||
#include "systick.h"
|
||||
|
||||
#include "key.h"
|
||||
#include "lcd.h"
|
||||
#include "hc12.h"
|
||||
|
||||
#include "GameEngine.h"
|
||||
|
||||
#include "APP_Ball.h"
|
||||
|
||||
/**************************************** 私有定义 ****************************************/
|
||||
|
||||
#define START_BYTE '&'
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
} Ball;
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/**************************************** 全局变量 ****************************************/
|
||||
|
||||
Ball ball;
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/**************************************** 私有函数 ****************************************/
|
||||
|
||||
void APP_Ball_DispBall(void);
|
||||
void APP_Ball_Send(void);
|
||||
void APP_Ball_Receive(uint8_t byte);
|
||||
void WriteMem(void *pdata, uint32_t len, uint8_t *list);
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief 启动移动球
|
||||
*/
|
||||
void APP_Ball_Launcher(void)
|
||||
{
|
||||
HC12_BindReceiveHandle(APP_Ball_Receive);
|
||||
|
||||
ball.x = 0;
|
||||
ball.y = 0;
|
||||
|
||||
APP_Ball_DispBall();
|
||||
|
||||
while (1)
|
||||
{
|
||||
switch (KEY_GetKeyWait())
|
||||
{
|
||||
case JOY_U_DOWN:
|
||||
{
|
||||
if (ball.y - 2 >= 0)
|
||||
{
|
||||
ball.y -= 2;
|
||||
APP_Ball_DispBall();
|
||||
|
||||
APP_Ball_Send();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case JOY_D_DOWN:
|
||||
{
|
||||
if (ball.y + 2 <= LCD_HEIGHT)
|
||||
{
|
||||
ball.y += 2;
|
||||
APP_Ball_DispBall();
|
||||
|
||||
APP_Ball_Send();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case JOY_L_DOWN:
|
||||
{
|
||||
if (ball.x - 2 >= 0)
|
||||
{
|
||||
ball.x -= 2;
|
||||
APP_Ball_DispBall();
|
||||
|
||||
APP_Ball_Send();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case JOY_R_DOWN:
|
||||
{
|
||||
if (ball.x + 2 <= LCD_WIDTH)
|
||||
{
|
||||
ball.x += 2;
|
||||
APP_Ball_DispBall();
|
||||
|
||||
APP_Ball_Send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void APP_Ball_DispBall(void)
|
||||
{
|
||||
GE_Draw_ClrAll(WHITE);
|
||||
GE_Draw_FillCircle(ball.x, ball.y, 10, BLUE);
|
||||
GE_Draw_Disp();
|
||||
}
|
||||
|
||||
void APP_Ball_Send(void)
|
||||
{
|
||||
Ball pack;
|
||||
pack.x = ball.x;
|
||||
pack.y = ball.y;
|
||||
|
||||
char start_byte = START_BYTE;
|
||||
HC12_SendBuff(&start_byte, sizeof(start_byte));
|
||||
HC12_SendBuff(&pack, sizeof(Ball));
|
||||
}
|
||||
|
||||
void APP_Ball_Receive(uint8_t byte)
|
||||
{
|
||||
static uint8_t is_receiving = FALSE;
|
||||
static uint8_t list[4];
|
||||
static uint8_t list_i = 0;
|
||||
|
||||
if (is_receiving == FALSE && byte == START_BYTE)
|
||||
{
|
||||
is_receiving = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_receiving == TRUE)
|
||||
{
|
||||
list[list_i] = byte;
|
||||
list_i++;
|
||||
|
||||
if (list_i == 4)
|
||||
{
|
||||
WriteMem(&ball, sizeof(Ball), list);
|
||||
APP_Ball_DispBall();
|
||||
list_i = 0;
|
||||
is_receiving = FALSE;
|
||||
|
||||
printf("收到小球位置:x=%d y=%d\n", ball.x, ball.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WriteMem(void *pdata, uint32_t len, uint8_t *list)
|
||||
{
|
||||
uint8_t *p = (uint8_t *)pdata;
|
||||
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
p[i] = list[i];
|
||||
}
|
||||
8
User/APP_Ball/APP_Ball.h
Normal file
8
User/APP_Ball/APP_Ball.h
Normal file
@ -0,0 +1,8 @@
|
||||
//移动球应用
|
||||
|
||||
#ifndef __APP_BALL
|
||||
#define __APP_BALL
|
||||
|
||||
void APP_Ball_Launcher(void);
|
||||
|
||||
#endif
|
||||
@ -9,6 +9,7 @@
|
||||
#include "uart.h"
|
||||
#include "adc.h"
|
||||
#include "hc25.h"
|
||||
#include "hc12.h"
|
||||
|
||||
#include "GameEngine.h"
|
||||
#include "SD.h"
|
||||
@ -20,6 +21,7 @@
|
||||
#include "APP_Plane.h"
|
||||
#include "APP_Setting.h"
|
||||
#include "APP_Weather.h"
|
||||
#include "APP_Ball.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@ -41,7 +43,6 @@ int main(void)
|
||||
|
||||
//初始化模块
|
||||
GE_Init();
|
||||
SD_Init();
|
||||
|
||||
GE_Draw_ClrAll(WHITE);
|
||||
GE_Draw_Disp();
|
||||
@ -51,6 +52,10 @@ int main(void)
|
||||
printf("完成系统初始化\n");
|
||||
|
||||
HC25_Init();
|
||||
HC12_Init();
|
||||
|
||||
APP_Ball_Launcher();
|
||||
while (1);
|
||||
|
||||
Clock_Init();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user