Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int inInputText2(int loc, char *str, int len, BYTE fmt)
- {
- int i, inTempLen, idx = 0;
- int lenStr, letterInd = 0;
- int ind, inPosLoc;
- // int ind, inPosLoc = 6;
- BOOL fHex=FALSE, fFirst,isKey;
- BYTE key, preKey = 0x7D;
- char szDisplay[MAX_CHAR_PER_LINE+1];
- char *buf; //contains the current result
- char letGroup[26] = "";
- int inCheckPos = 0;
- int j = 0;
- int inLastPost = 0;
- const char *letterGrb[] = {
- "0 {}/\\'\":;<>|+-[]",
- "1QZqz",
- "2ABCabc",
- "3DEFdef",
- "4GHIghi",
- "5JKLjkl",
- "6MNOmno",
- "7PRSprs",
- "8TUVtuv",
- "9WXYZwxyz",
- ".,!?@#$%^&*;",
- "",
- "",
- "",
- };
- const char *letterHex[] = {
- "0",
- "1",
- "2ABC",
- "3DEF",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9",
- "",
- "",
- "",
- "",
- };
- if(strlen(str)>len){
- return d_NO;
- }
- buf=malloc(len+1);
- memset(buf, 0x00, len+1);
- strcpy(buf, str); //the initial string will be modified only in case of ENTER is pressed
- if (buf[0] != 0) {
- idx = strlen(buf);
- }
- while (1) {
- idx = strlen(buf);
- inCheckPos = loc + inPosLoc;
- if (inCheckPos > 8) {
- j += MAX_CHAR_PER_LINE;
- // clearLine(8);
- }
- //display string
- memset(szDisplay, 0x00, sizeof (szDisplay));
- // for (i = 0, inPosLoc = 0; i < idx; i += MAX_CHAR_PER_LINE, inPosLoc++) {
- for (i = j, inPosLoc = 0; i < idx; i += MAX_CHAR_PER_LINE, inPosLoc++) {
- memset(szDisplay, ' ', MAX_CHAR_PER_LINE);
- inTempLen=idx-i>MAX_CHAR_PER_LINE?MAX_CHAR_PER_LINE:idx-i;
- switch (fmt) {
- case '*': //password entering
- memset(szDisplay, '*', inTempLen);
- break;
- case 'X':
- fHex = TRUE;
- break;
- case ' ': //get the last dspW characters
- default:
- memcpy(szDisplay, buf+i, inTempLen);
- break;
- }
- setLCDPrint(loc + inPosLoc, DISPLAY_POSITION_LEFT, szDisplay);
- }
- if(inCheckPos > 8){
- clearLine(8);
- }
- if (i > 0) //because of loop running
- {
- inPosLoc--;
- }
- letterInd = 0;
- CTOS_KBDBufFlush();
- //wait for user input
- key = 0;
- isKey = FALSE;
- CTOS_TimeOutSet(TIMER_ID_2, 60 * 100);
- do {
- CTOS_KBDInKey(&isKey);
- if (CTOS_TimeOutCheck(TIMER_ID_2) == d_YES) {
- free(buf);
- return d_NO;
- }
- } while (!isKey);
- preKey = 0;
- CTOS_TimeOutSet(TIMER_ID_1, 12 * 10);
- //the current position is always at the end of the string
- fFirst=TRUE;
- while (CTOS_TimeOutCheck(TIMER_ID_1) != d_YES) {
- if (fFirst == FALSE) {
- key = 0;
- isKey = FALSE;
- CTOS_KBDBufFlush();
- CTOS_TimeOutSet(TIMER_ID_1, 12 * 10);
- do {
- CTOS_KBDInKey(&isKey);
- if (CTOS_TimeOutCheck(TIMER_ID_1) == d_YES)
- break;
- } while (!isKey);
- }
- fFirst = FALSE;
- if (isKey == TRUE) {
- CTOS_KBDGet(&key);
- if (key != d_KBD_DOT && key != '.')
- ind = key - '0';
- else if (key == d_KBD_DOT || key == '.') {
- key = '.';
- ind = 10;
- }
- }
- switch (key) {
- case 0: // if no charachter pressed in 1.2 seconds ,start a timer for next character
- //timeout; the initial string is not modified
- CTOS_TimeOutSet(TIMER_ID_1, 0);
- break;
- case d_KBD_CANCEL:
- free(buf);
- return key; //aborted; the initial string is not modified
- case d_KBD_ENTER: //the entering is finished
- strcpy(str, buf); //now we can change the initial string
- free(buf);
- return key;
- case d_KBD_CLEAR: //backspace, remove the last character entered
- idx=strlen(buf);
- if (!idx) {
- CTOS_Beep();
- } else {
- // if (strlen(buf + (inPosLoc * MAX_CHAR_PER_LINE))==1)
- // clearLine(loc + inPosLoc);
- if (strlen(buf + (inLastPost * MAX_CHAR_PER_LINE))==1)
- // vduiClearBelow(loc+inPosLoc);
- clearLine(loc + inPosLoc);
- buf[idx - 1] = 0;
- }
- CTOS_TimeOutSet(TIMER_ID_1, 0);
- break;
- case d_KBD_1:
- case d_KBD_2:
- case d_KBD_3:
- case d_KBD_4:
- case d_KBD_5: //a valid key typed
- case d_KBD_6:
- case d_KBD_7:
- case d_KBD_8:
- case d_KBD_9:
- case d_KBD_0:
- case d_KBD_DOT:
- case '.':
- if (idx >= len - 1)
- CTOS_Beep();
- else {
- memset(letGroup, 0, sizeof (letGroup));
- if (fHex == TRUE) {
- lenStr = strlen(&letterHex[ind][0]);
- memcpy(letGroup, &letterHex[ind][0], lenStr);
- } else {
- lenStr = strlen(&letterGrb[ind][0]);
- memcpy(letGroup, &letterGrb[ind][0], lenStr);
- }
- if(lenStr==0){
- CTOS_TimeOutSet(TIMER_ID_2, 60 * 10);
- break;
- }
- inFmtPad(letGroup, 15, ' ');
- if (key == preKey) {
- if ((letterInd) >= (lenStr - 1)) {
- letterInd = 0;
- } else
- letterInd++;
- } else {
- if (preKey != 0){
- letterInd = 0; //@@IBR 23052016 to make sure if changing key, go back to first array of letter
- idx++;
- }
- }
- buf[idx] = letGroup[letterInd];
- // inTempLen = strlen(buf + (inPosLoc * MAX_CHAR_PER_LINE));
- inTempLen = strlen(buf + (inLastPost * MAX_CHAR_PER_LINE));
- vdDebug_LogPrintf("@@IBR inTempLen = %d, inLastPost = %d", inTempLen, inLastPost);
- if (inTempLen > MAX_CHAR_PER_LINE) {
- inPosLoc++;
- inLastPost++;
- }
- memset(szDisplay, 0x00, sizeof(szDisplay));
- if (fmt == '*') {
- inFmtPad(szDisplay, strlen(buf + (inPosLoc * MAX_CHAR_PER_LINE)), '*');
- szDisplay[strlen(szDisplay) - 1] = buf[idx];
- } else {
- // strcpy(szDisplay, buf + (inPosLoc * MAX_CHAR_PER_LINE));
- strcpy(szDisplay, buf + (inLastPost * MAX_CHAR_PER_LINE));
- }
- vdDebug_LogPrintf("@@IBR szDisplay [%s]", szDisplay);
- setLCDPrint(loc+inPosLoc, DISPLAY_POSITION_LEFT, szDisplay);
- preKey = key;
- }
- CTOS_TimeOutSet(TIMER_ID_2, 60 * 10);
- break;
- default:
- CTOS_Beep();
- CTOS_TimeOutSet(TIMER_ID_1, 0);
- break; //invalid key pressed
- } //end switch
- } //while
- } //while
- lblKO:
- free(buf);
- return d_NO;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement