請先看『使用說明』
LCM Module:LCM KeyPad under Linux
From LEXWiKi
Contents |
The Sample code source you can download from
Source file:
<FTP> LCM_Keypad_SDK_v1.0L_Src
About source code. 1.We suggest using Code::Blocks as an IDE in Linux. 2.Or you can just use "make" to compile the source code in the LCMctlv22LSrc/ folder or LCMctlv22LSrc/src/ folder. And you can excute "lcmctlv22l" file in the LCMctlv22LSrc/src/ folder $cd LCM_Keypad_SDK_v1.0L_src $./configure $cd src $make $./lcm_keypad_sdk_v1.0L
Binary file:
<FTP> lcm_keypad_sdk_v1.0L_Bin
KeyPad Define
key recrived value --------------------- key1 50 key2 52 key3 53 key4 55 key5 65 key6 67
How to use the DEMO application
- COM Port selection
- Setting the text which you want to print to LCM from key1~key6
- Setting that print the text to upline or lowline by check the checkbox
- After setting , click OK
- Press the key on the keypad , the text you set will print to LCM
Sample code Introduction
flow chart
Set for /dev/tty
char *get_ptty(pportinfo_t pportinfo)
{
char *ptty;
switch(pportinfo->tty){
case '0':{
ptty = TTY_DEV"0";
}break;
case '1':{
ptty = TTY_DEV"1";
}break;
case '2':{
ptty = TTY_DEV"2";
}break;
case '3':{
ptty = TTY_DEV"3";
}break;
case '4':{
ptty = TTY_DEV"4";
}break;
case '5':{
ptty = TTY_DEV"5";
}break;
}
return(ptty);
}
Setup COM
int PortSet(int fdcom, const pportinfo_t pportinfo)
{
struct termios termios_old, termios_new;
int tmp;
char databit, stopbit, parity, fctl;
bzero(&termios_old, sizeof(termios_old));
bzero(&termios_new, sizeof(termios_new));
cfmakeraw(&termios_new);
tcgetattr(fdcom, &termios_old); //get the serial port attributions
cfsetispeed(&termios_new, baudrate);
cfsetospeed(&termios_new, baudrate);
termios_new.c_cflag |= CLOCAL;
termios_new.c_cflag |= CREAD;
termios_new.c_cflag &= ~CRTSCTS;
termios_new.c_cflag &= ~CSIZE;
termios_new.c_cflag |= CS8;
termios_new.c_cflag &= ~PARENB;
termios_new.c_cflag &= ~CSTOPB; //1 stop bits
termios_new.c_oflag &= ~OPOST;
termios_new.c_cc[VMIN] = 1;
termios_new.c_cc[VTIME] = 1;
tcflush(fdcom, TCIFLUSH);
tmp = tcsetattr(fdcom, TCSANOW, &termios_new);
return(tmp);
}
Open serial port
int PortOpen(pportinfo_t pportinfo)
{
int fdcom;
char *ptty;
ptty = get_ptty(pportinfo);
fdcom = open(ptty, O_RDWR | O_NOCTTY | O_NONBLOCK);
return (fdcom);
}
Close serial port
void PortClose(int fdcom)
{
close(fdcom);
}
send data
int PortSend(int fdcom, char *data, int datalen)
{
int len = 0;
len = write(fdcom, data, datalen);
if(len == datalen){
return (len);
}
else{
tcflush(fdcom, TCOFLUSH);
return -1;
}
}
receive data
int PortRecv(int fdcom, char *data, int datalen)
{
int readlen, fs_sel = 0;
fd_set fs_read;
struct timeval tv_timeout;
FD_ZERO(&fs_read);
FD_SET(fdcom, &fs_read);
tv_timeout.tv_sec = TIMEOUT_SEC(datalen, baudrate);
tv_timeout.tv_usec = TIMEOUT_USEC;
fs_sel = select(fdcom+1, &fs_read, NULL, NULL, &tv_timeout);
if(fs_sel){
readlen = read(fdcom, data, datalen);
return(readlen);
}
else{
return(-1);
}
return (readlen);
}
Set COM Port Device(COM1~COM6)
portinfo_t portinfo ={ '0' , '0' };
portinfo_t portinfo ={ '0' , '1' };
portinfo_t portinfo ={ '0' , '2' };
portinfo_t portinfo ={ '0' , '3' };
portinfo_t portinfo ={ '0' , '4' };
portinfo_t portinfo ={ '0' , '5' };
//Default tty:COM2
Use thread to receive the value of key
if( counter == 1 )
{
g_thread_create(signal_thread, NULL, TRUE, NULL);
}
counter++;
receive the data from keypad in thread
for(;;)
{
PortRecv(fdcom, RecvBuf, 10); //the received data:RevBuf[0]
if ( RecvBuf[0] == 50) //received data:key 1
{
}
if ( RecvBuf[0] == 52) //received data:key 2
{
}
if ( RecvBuf[0] == 53) //received data:key 3
{
}
if ( RecvBuf[0] == 55) //received data:key 4
{
}
if ( RecvBuf[0] == 65) //received data:key 5
{
}
if ( RecvBuf[0] == 67) //received data:key 6
{
}



