View previous topic :: View next topic |
Author |
Message |
ernest
Joined: 11 Feb 2004 Posts: 51
|
HELP - How to automatically acquire a long number frm keypad |
Posted: Mon Apr 26, 2004 6:51 pm |
|
|
Hi,
The following is a routine for acquiring a 32-BIT number using RS232. Instead of using RS232, I would like to implement it using keypad to key in the value.
The problem is, an ENTER command needs to be entered in order to put the value into the variable for storage. How can I modify the routine either to be able to enter a 6-decimal digits (000000 -- 999999) and storing it into the variable without having to press the ENTER command or create an ENTER command from the keypad.
Thanks...
signed int32 get_long32() {
char s[11];
signed int32 l32;
// able to get max. cca.(32 bits) == 2^32 = 4,294,967,296
get_string(s, 11);
l32=atoi32(s);
return(l32);
} |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Apr 27, 2004 1:34 am |
|
|
To avoid the enter key you can use getc() in a loop, but then you allways need to enter 6 digits.
Code: |
signed int32 get_long32() {
char s[11];
signed int32 l32;
int8 i;
for (i=0; i<6; i++)
getc(s[i]);
l32=atoi32(s);
return(l32);
} |
|
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Tue Apr 27, 2004 2:24 pm |
|
|
wouldn't your keypad have a # or a * that could be used in place of the enter key? |
|
|
valemike Guest
|
|
Posted: Tue Apr 27, 2004 3:54 pm |
|
|
If the guy screws up entering the number, he'll want to correct it. Thus you should allow him to keep punching numbers until it displays what he wants.
If he keeps typing beyond the six digits, you might want to shift the most significant digit out of there, and just look at the most recent 6 digits. (That's how some microwaves work).
Now, to be able to save these without an "enter" button, perhaps you can tell them to hold down two keys for 3 seconds, like the "2" and the "9"
~~~~~~~~~~~~~~
Have the rest of you guys implemented keypad functions in the past? For me, my keypad functions end up being a state machine with states like "Key 1 hit, waiting for a release", "Keypad Idle", "Enter hit", "Key 1 hit for more than 3 seconds".
Without a state machine (and with, too), keypad programming becomes a nightmare!! It takes up a lot of code. |
|
|
ernest
Joined: 11 Feb 2004 Posts: 51
|
|
Posted: Fri Apr 30, 2004 12:04 am |
|
|
Thanks a lot guys...really appreciate it. |
|
|
|