📄 test_joystick.c
字号:
//====================================================================================
//文 件 名:Test_JoyStick.c
//功能描述: JoyStick测试
//维护记录: V1.0 by wangtao <wangtao@sunnorth.com.cn>
//====================================================================================
#include "SystemHeader.h"
short Test_JoyStick()
{
short x, y;
short Ret = 0x00;
unsigned short KeyCode1, KeyCode2;
unsigned short OldKeyCode1, OldKeyCode2;
STR_IMAGE Pic_JoyStick = {144, 64, RES_JOYSTICK_BIN};
STR_IMAGE Pic_Up = {16, 16, RES_JOYSTICK_UP_BIN};
STR_IMAGE Pic_Down = {16, 16, RES_JOYSTICK_DOWN_BIN};
STR_IMAGE Pic_Left = {16, 16, RES_JOYSTICK_LEFT_BIN};
STR_IMAGE Pic_Right = {16, 16, RES_JOYSTICK_RIGHT_BIN};
STR_IMAGE Pic_Sel = {16, 8, RES_JOYSTICK_SEL_BIN};
STR_IMAGE Pic_Btn = {16, 16, RES_JOYSTICK_BTN_BIN};
TFT_SetBGColor(0x0001);
TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
TFT_SetBGColor(COLOR_WHITE);
TFT_SetWindow(40, 40, 279, 199);
TFT_SetColor(COLOR_RED);
TFT_Rectangle(0, 0, 239, 159, PAINT_HOLLOW);
TFT_SetColor(COLOR_BLUE);
TFT_SetWindow(60, 60, 259, 119);
TFT_SetTextPos(0, 0);
TFT_Print("请连接游戏手柄,测试手柄的每个按键。点击屏幕的任意位置返回。");
TFT_SetWindow(88, 120, 231, 193);
TFT_PutImage(0, 0, &Pic_JoyStick);
JoyStick_Init();
KeyCode1 = KeyCode2 = 0x0000;
OldKeyCode1 = OldKeyCode2 = 0x0000;
while(1)
{
JoyStick_Get(&KeyCode1, &KeyCode2);
if(KeyCode1!=OldKeyCode1)
{
OldKeyCode1 = KeyCode1;
TFT_PutImage(0, 0, &Pic_JoyStick);
if(KeyCode1&0x80) // B
{
TFT_PutImage(120, 24, &Pic_Btn);
Ret |= 0x80;
}
if(KeyCode1&0x40) // A
{
TFT_PutImage(95, 24, &Pic_Btn);
Ret |= 0x40;
}
if(KeyCode1&0x20) // Select
{
TFT_PutImage(55, 45, &Pic_Sel);
Ret |= 0x20;
}
if(KeyCode1&0x10) // Start
{
TFT_PutImage(76, 45, &Pic_Sel);
Ret |= 0x10;
}
if(KeyCode1&0x08) // Up
{
TFT_PutImage(20, 10, &Pic_Up);
Ret |= 0x08;
}
if(KeyCode1&0x04) // Down
{
TFT_PutImage(20, 38, &Pic_Down);
Ret |= 0x04;
}
if(KeyCode1&0x02) // Left
{
TFT_PutImage(6, 24, &Pic_Left);
Ret |= 0x02;
}
if(KeyCode1&0x01) // Right
{
TFT_PutImage(34, 24, &Pic_Right);
Ret |= 0x01;
}
}
Touch_Get(&x, &y);
if(x!=-1) break;
}
TFT_SetBGColor(0x0001);
TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
if(Ret == 0xFF)
Ret = 1;
else
Ret = 0;
return Ret;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -