📄 comm_drive.c
字号:
/* IAL输入引擎底层驱动。
本驱动程序是用于MagicARM2200实验箱,采用16个按键和触摸屏输入。
*/
#include "common.h"
#include "minigui.h"
#include "ucos_ii.h"
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
// 定义输入消息数据结构
typedef struct TOUCH_KEY
{ uint8 sta; // 状态字,d1位为1时表示按键输入,d0为1时表示触摸屏输入;
// d7为1时表示按键/触摸屏按下,为0时表示放开。
uint8 key; // 按键码(0--15)
// 触摸屏输入的坐标
uint16 x;
uint16 y;
} TouchKey_Sta;
extern OS_EVENT *TouchKeyMbox; // 声明按键/触摸屏消息邮箱
static TouchKey_Sta *event_input;
/* (模拟)鼠标左、中、右按键键值定义 */
#define IAL_MOUSE_LEFTBUTTON 4
#define IAL_MOUSE_MIDDLEBUTTON 2
#define IAL_MOUSE_RIGHTBUTTON 1
/* --------------------- For Common IAL Engine ----------------- */
/* Should be implemented if you use common ial engine in MiniGUI */
#define COMM_MOUSEINPUT 0x01 /* 鼠标或触摸屏事件 */
#define COMM_KBINPUT 0x02 /* 按键事件 */
/* 定义按键功能,16个按键安排如下:
-----------------------------
| 7 | 8 | 9 | / |
-----------------------------
| 4 | 5 | 6 | * |
-----------------------------
| 1 | 2 | 3 | - |
-----------------------------
| 0 | . | + | Enter|
-----------------------------
*/
typedef struct
{ unsigned char event;
unsigned char value;
} KEY_EVENT;
KEY_EVENT EVENT_CHG_TAB[16] =
{ {COMM_KBINPUT, SCANCODE_0},
{COMM_KBINPUT, SCANCODE_1},
{COMM_KBINPUT, SCANCODE_2},
{COMM_KBINPUT, SCANCODE_3},
{COMM_KBINPUT, SCANCODE_4},
{COMM_KBINPUT, SCANCODE_5},
{COMM_KBINPUT, SCANCODE_6},
{COMM_KBINPUT, SCANCODE_7},
{COMM_KBINPUT, SCANCODE_8},
{COMM_KBINPUT, SCANCODE_9},
{COMM_KBINPUT, SCANCODE_PERIOD}, // 小数点
{COMM_KBINPUT, SCANCODE_KEYPADPLUS}, // 加号
{COMM_KBINPUT, SCANCODE_ENTER}, // 回车
{COMM_KBINPUT, SCANCODE_MINUS}, // 减号
{COMM_KBINPUT, SCANCODE_KEYPADMULTIPLY}, // 乘法
{COMM_KBINPUT, SCANCODE_SLASH} // 减号
};
/*
* Waits for input for keyboard and touchpanel.
* If no data, this function should go into sleep;
* when data is available, keyboard or touchpanel driver should wake up
* the task/thread in MiniGUI who call comm_wait_for_input.
*
* Normal implementation make this function sleep on a ucosii semaphore.
* return COMM_MOUSEINPUT or COMM_KBINPUT according to type of the input event.
*/
// 查询键盘或鼠标事件
int comm_wait_for_input (void)
{ unsigned char err;
/* 等待按键/触摸屏消息 */
event_input = (TouchKey_Sta *) OSMboxPend(TouchKeyMbox, 0, &err);
// 判断是什么事件,然后返回相应的值
if(err==OS_NO_ERR)
{ if((event_input->sta&0x01) != 0)
{ return(COMM_MOUSEINPUT);
}
if((event_input->sta&0x02) != 0)
{ return(COMM_KBINPUT);
}
}
return(0);
}
/*
* Gets touchpanel position and button data.
* x, y : position values
* button : Non-zero value means pen is down.
*/
// 该函数的返回值可以是IAL_MOUSE_LEFTBUTTON(表示左键按下)、
// IAL_MOUSE_RIGHTBUTTON(表示右键按下)等值"或"的结果。
// 取得鼠标/触摸屏的参数
int comm_ts_getdata (int *x, int *y, int *button)
{ /* 根据触摸按下或放开进行相应的处理 */
if((event_input->sta&0x80) != 0) // 触摸按下
{ *x = event_input->x;
*y = event_input->y;
*button = IAL_MOUSE_LEFTBUTTON;
}
else // 触摸放开
{ *button = 0;
} // end of if((key&0x80) != 0)...else...
return(0);
}
/*
* Gets keyboard key data.
* key : return MiniGUI scancode of the key.
* key_status : key down or up, non-zero value means down.
*/
// 取得按键的参数
int comm_kb_getdata (short *key, short *key_status)
{ /* 根据按键按下或放开进行相应的处理 */
if((event_input->sta&0x80) != 0) // 按键按下
{ *key = EVENT_CHG_TAB[event_input->key].value;
*key_status = 1;
}
else // 按键放开
{ *key_status = 0;
} // end of if((event_input.sta&0x80) != 0)...else...
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -