Converting Terminal code to button code
Jon Keinath
Posts: 146
I'm having a difficult time trying to convert my terminal based program into a "button" based program.
Here is a code snipet of what I am using in terminal code.(Simplified version)
at this point, it repeats the while(ud != 'c') code but changes a different variable.
I am trying to convert this to use in a system that uses 3 buttons, 1 for each 'c','q', and 'a'.
I can't figure out how to make a button react in the same way as a "key" or char would.
Would a SX and Uart make this task simpler?
Any help would be appreciated!
Post Edited (Jon Keinath) : 8/9/2005 1:41:14 AM GMT
Here is a code snipet of what I am using in terminal code.(Simplified version)
if (Terminal.byteAvailable()); { ud = Terminal.getChar(); if ud = 'c'; { //send message to lcd ud = 'o'; while (ud != 'c') { ud = Terminal.getChar(); if (ud == 'q') { variable ++; } if (ud == 'a') { variable --; } } ud = 'o';
at this point, it repeats the while(ud != 'c') code but changes a different variable.
I am trying to convert this to use in a system that uses 3 buttons, 1 for each 'c','q', and 'a'.
I can't figure out how to make a button react in the same way as a "key" or char would.
Would a SX and Uart make this task simpler?
Any help would be appreciated!
Post Edited (Jon Keinath) : 8/9/2005 1:41:14 AM GMT
Comments
You could do it this way. (Also attached for convenience)
import stamp.core.*;
public class menutest3key {
· static final char keySET = 'c';
· static final char keyDOWN = 'a';
· static final char keyUP = 'q';
· static final int PARAMS = 5; //number of parameters
· static String[noparse]/noparse paramName = new String[noparse]/noparse{"param1 ","param2 ","param3 ","param4 ","param5 "}; //parameter descriptions
· static int[noparse]/noparse paramValue = new int[noparse]/noparse{0,0,0,0,0}; //parameter initial values
· static int paramIndex = -1;
· static void printParam() {
··· System.out.print(paramName[noparse][[/noparse]paramIndex]);
··· System.out.println(paramValue[noparse][[/noparse]paramIndex]);
· }
· static void doSetup() {
··· char key;
··· if (Terminal.byteAvailable()) { //if no keypress return
····· key = Terminal.getChar();
····· if (key == keySET) { //only enter Setup mode if key is keySET
······· paramIndex++;
······· printParam();
······· while (true) { //do not leave setup mode ...
········· key = Terminal.getChar();
········· switch (key) {
··········· case keySET:· paramIndex++;
························· if (paramIndex == PARAMS) { // ...until cycled through all parameters
··························· paramIndex = -1;
··························· return;
························· }
························· printParam();
························· break;
··········· case keyDOWN: paramValue[noparse][[/noparse]paramIndex] = paramValue[noparse][[/noparse]paramIndex] - 1;
························· printParam();
························· break;
··········· case keyUP:·· paramValue[noparse][[/noparse]paramIndex] = paramValue[noparse][[/noparse]paramIndex] + 1;
························· printParam();
························· break;
··········· default:
········· }
······· }
····· }
··· }
· }
· static void main() {
··· while (true) {
····· doSetup();
····· //other tasks
··· }
· }
}
regards peter
My original code works (not as elegantly as yours) with "keys" on the keyboard. I'll try and refine my question.
I'm am trying to move from a device that relies on the Terminal (thus a connection to a computer) to a device that has it's own buttons (SET, UP and DOWN) (they are normaly open, and I can pull them high or low whichever is easyier). In my original plan the buttons were to be connected to 3 seperate pins, but now that I have researched a little more it may be easier to use the matrix keyboard connector on my Matrix Orbital LCD and an UART instead of a direct connection to the Javelin.
Is there an easy way to do the same idea as posted with buttons or should I do more investigating with regards to the LCD and matrix keyboard connector (is it possible to use ordinary buttons with a matrix keyboard connector?)?
I guess I should have been more clear in my original question, Sorry for the confusion.
-Jon
---EDIT----
I'm going to try to use a homemade "keypad" (3 buttons) and connect them to the LCD's Matrix Keypad Connector, it looks like this coupled with a receving UART will work great. I'll let you know what I find out.
Post Edited (Jon Keinath) : 8/9/2005 4:45:51 PM GMT
That's easy to do.
See the attachement.
I only changed how to retrieve a key. In this case, I assume the MO lcd sends a keycode the
moment a key is pressed. You should adapt 'q', 'c' and 'a' to the actual codes sent by the MO lcd
keyboard (see MO documentation)
Now you probably also want to change the output device to be the LCD display.
All you need to do is rewrite printParam.
regards peter
This will also help me on future projects!
Thanks again!
-Jon