Need help on cursor movement

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

Post Reply
MDeer
LCD?
Posts: 3
Joined: Wed May 08, 2002 6:00 pm

Post by MDeer »

Hello,

I have problem about reading the input without move the cursor to next position.
So when "Enter", it should read in the data without move the cursor.

The program sends "Enter a Key( )" to the LCD screen,
then places the dark cursor in the ( ), then waits for 5 seconds so
you can see the cursor in the correct position, then sends the
read key codes. The cursor should then drop to the next line,
not where we need, which is between the ( ).

Help!

MDeer

=====================================================================

#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <time.h>
#define FALSE 0

int main()
{
int ch,res,fd;
char key[300];
char out[4];
time_t time1,time2;
volatile int STOP=FALSE;

extern char *optarg;
extern int optind;
extern int opterr;

char device[256] = "/dev/ttyS1";
speed_t speed = B2400;
struct termios portset, portset_save;

system("stty ispeed 2400 < /dev/ttyS1");
system("stty raw < /dev/ttyS1");

fd = open(device, O_RDWR | O_NOCTTY );
if (fd == -1)
{
fprintf(stderr, "Device open: Failedn");
printf("Device open: Failedn");
}
tcgetattr(fd, &portset_save);
portset = portset_save;
cfsetospeed(&portset, speed);
cfsetispeed(&portset, speed);
tcsetattr(fd, TCSANOW, &portset);

sprintf(out, "%c%c", 254,12); //blank the cursor
write(fd, out, 2);

sprintf(out, "%c%c", 254,1); // clear the display
write(fd, out, 2);

sprintf(out, "%c%c", 254,13); // turn on block cursor
write(fd, out, 2);

sprintf(out, "%c%c", 254,128); // position the cursor and print
write(fd, out, 2);
write(fd, "Enter A Key( )", 14);

sprintf(out, "%c%c", 254,140); // position cursor between ( )
write(fd, out, 2);

sleep(5); //Wait here so you can see the cursor in the right place
//Once the read setup codes are sent, the cursor jumps to
//the bottom left of the screen.

while (STOP==FALSE)
{

sprintf(out, "%c%c",254,64); //Code to read keys
write(fd, out, 2);

sprintf(out, "%c%c",254,6); //More codes to read keys
write(fd, out, 2);

res = read(fd,key,255);
switch(key[1]) /* Switch the Read command */
{
case 0x4D :
printf("up was pressedn");
return(3); // up
break;

case 0x47 :
printf("down was pressedn");
return(4); // down
break;

case 0x4B :
printf("esc was pressedn");
return(2); // esc
break;

case 0x4E :
printf("enter was pressedn");
return(1); // enter
break;
}
}
}

Post Reply