This is a pretty challenging question! I'm trying to get a filename from this keypad:
I want to filename to only contain capital letters or a space. It can only be 8 chars long max for the SD filename to work (according to the SD library) I'm off to a good start with the below code, but I came to a screeching halt when I don't know how to add letters to the filename, or how to tell if the filename is more than 8 chars long.
To understand how to input letters, I'll have this notice printed on the panel next to the keypad:
ADDING PARTS
When entering the part name, use the keypad as arrow keys to select letters. Up/Down scrolls through letters, Left/Right moves to the previous or next letter. Part names can have a maximum of 8 characters.
Press * when finished, or # to cancel.
Here is the code I've got so far. (The disp.lcd.print is basically the same as LCD.print, etc)
void Add_Part() {
char newName[13]; //holder for new part name
//ascii characters A-Z are 65 - 90 space is 32
int currentLetter = 65; //holder for the letter they're working on
disp.lcd_cls(); //clear display
disp.lcd_print(F("ENTER NEW PART NAME"));
disp.lcd_rowcol(1, 3); //row, col
disp.lcd_print(F("8 LETTERS MAX"));
disp.lcd_rowcol(3, 0); //row, col
disp.lcd_print(F("1:OK 2:CANCEL"));
while (1) { //wait for keypress
byte k = checkKeyBuffer(); //get a keypress from the user
if (k == 1) break; //move on
if (k == 2 || k == keyTimeout) {
cancelMsg();
return;
}
} //end of waiting for go ahead
boolean nameComplete = false;
while (nameComplete) { //loop until the name is complete
disp.lcd_cls(); //clear display
disp.lcd_print(F("NEW PART NAME:")); //print what ever part of the name they made so far
disp.lcd_rowcol(1, 6); //row, col
disp.lcd_print(newName); //print what ever part of the name they made so far
disp.lcd_print(char(currentLetter)); //print the current letter, starts at A
disp.lcd_print(F("DONE-* CANCEL-#"));
while (1) { //get letters
byte k = checkKeyBuffer(); //get a keypress from the user
if (k == keyPound) {
cancelMsg();
return; //user canceled
}
else if (k == keyAsterisk) { //user finished
nameComplete = true;
break;
}
else if (k == 2) { // = up arrow; letter step increase
currentLetter += 1;
if (currentLetter > 90) currentLetter = 90; //Z is the max
if (currentLetter == 33) currentLetter = 65; //jump from space back up to A
break; //exit to refresh screen
}
else if (k == 8) { // = down arrow; letter step decrease
currentLetter -= 1;
if (currentLetter < 65 ) currentLetter = 32; //anything below A will be a space
break; //exit to refresh screen
}
else if (k == 6) { // = right arrow; advance to the next letter
//HOW DO I GET THE CURRENT NUMBER OF LETTERS IN newName
//ADD THIS LETTER TO newName
}
}
}
}