Keypad input problem. Worked before but not now....

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

Moderators: Henry, Mods

Post Reply
Nosleep
LCD?
Posts: 4
Joined: Thu Aug 07, 2003 3:29 pm

Keypad input problem. Worked before but not now....

Post by Nosleep »

Hello. I just got my LK 204-25 serial display in the mail today :D . I sat down and wrote a few functions to clear the screen, turn off the cursor, turn on the cursor, etc. No problems. I then wrote a fuction to read input from my 4x4 keypad and print out the result on my computer screen. Again no problems. 8) The program that I wrote to test the 4x4 keypad worked fine at first. I shut down my computer and came back to it later to do some more coding. The same program to display keypad presses on my computer screen no longer worked. Instead of being displayed on the computer screen they are now displayed on the lcd. :jawdrop: Letters like A, B, C, etc.
What the hell happend. I have tried to figure this out. I can't. It's been hours. I am running mandrake linux 9.1. Here is what the function to read keypad out to the computer screen looks like. Note: this used to work like I intended.

void read_and_dis_input(void)
{
read(fd, &input, 1);
printf("Here is my input ---> %u\n", input)
}

Here is what fd is: fd = open( device, O_RDWR | O_NOCTTY );
input is: int input;

Like I said this used to print out values like 75, 74, 54, etc.. to my computer display. Now it prints letters to my lcd screen. This makes no sense I didn't recompile, or change my code. Henry, if your out there please take a look at this. I would greatly appreciate someones help here.
Nosleep
LCD?
Posts: 4
Joined: Thu Aug 07, 2003 3:29 pm

Post by Nosleep »

Here is the code I am working with now. It is almost the same as what I was using before - a line or two. It is a hacked version of ex1.c on the matrix orbital cd that came with my display. Keep in mind this approach did work for me earlier. It just stoped working for some reason.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>


int main()
{

char device[256] = "/dev/ttyS0";
speed_t speed = B19200;
struct termios portset, portset_save;
unsigned char ch = 254;
unsigned char ic = 65;
unsigned char input;
int fd;

fd = open(device, O_RDWR | O_NOCTTY );

if (fd == -1) {
fprintf(stderr, "Device open: Failed\n");
return -1;
}

tcgetattr(fd, &portset_save);
portset = portset_save;
cfsetospeed(&portset, speed);
cfsetispeed(&portset, speed);

tcsetattr(fd, TCSANOW, &portset);

write(fd, &ch, 1);
write(fd, &ic, 1);

printf("My input ---> %u\n", read(fd, &input, 1);

tcsetattr(fd, TCSAFLUSH, &portset_save);

close(fd);

return 0;

}

This prints a single different letter to the lcd for each key on the keypad.
That would be great if I was trying to do that, but I'm not. I want to read a key press and have the value displayed on my computer screen using printf. I have hacked away and cannot hack much longer. If you know what I am doing wrong please correct me. I am so tired :wall:
Nosleep
LCD?
Posts: 4
Joined: Thu Aug 07, 2003 3:29 pm

Post by Nosleep »

I rewrote my program. I have a fuction that opens up the serial port, sets the baud to 19200, and sets 8N1. If I do a cat /proc/tty/driver/serial
it reports my settings on /dev/ttyS0 which are:

0: uart:16550A port:3F8 irq:4 baud:19200 tx:638 rx:249 RTS|DTR

I know the serial port is recieving key presses because if I run my program hit a key and run cat /proc/tty/driver/serial after program termination rx will increment one digit for each key press. Lets say rx was rx:249 if I run my program and hit 4 keys rx will then be rx:253. I don't get it. I'm beginning to think it's the display. read() no longer works for me. Its like the program IS reading my key presses but echoing them back to the lcd display. ??????? If anyone needs more info I will be happy to post it. :wall:
Nosleep
LCD?
Posts: 4
Joined: Thu Aug 07, 2003 3:29 pm

Post by Nosleep »

YES!!!!!! :rock: Problem solved!! This was my fault. After enabling raw input in my serial init function

options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

The key presses are now printed out to my computers display instead of on the lcd display. :D

Now I can finally get some sleep. :hip:
Miles
Matrix Orbital
Matrix Orbital
Posts: 1105
Joined: Mon Mar 04, 2002 4:00 pm

Post by Miles »

Sleep...very well deserved...!! :D
Miles Y.
Head of Technical Support
Product Manager
Matrix Orbital
Post Reply