Advertisement
xathrya

Ponpon

May 23rd, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.83 KB | None | 0 0
  1. int inInputText2(int loc, char *str, int len, BYTE fmt)
  2. {
  3.     int i, inTempLen, idx = 0;
  4.     int lenStr, letterInd = 0;
  5.     int ind, inPosLoc;    
  6. //    int ind, inPosLoc = 6;    
  7.     BOOL fHex=FALSE, fFirst,isKey;
  8.     BYTE key, preKey = 0x7D;    
  9.     char szDisplay[MAX_CHAR_PER_LINE+1];
  10.     char *buf; //contains the current result
  11.     char letGroup[26] = "";
  12.     int inCheckPos = 0;
  13.     int j = 0;
  14.     int inLastPost = 0;
  15.    
  16.     const char *letterGrb[] = {
  17.         "0 {}/\\'\":;<>|+-[]",
  18.         "1QZqz",
  19.         "2ABCabc",
  20.         "3DEFdef",
  21.         "4GHIghi",
  22.         "5JKLjkl",
  23.         "6MNOmno",
  24.         "7PRSprs",
  25.         "8TUVtuv",
  26.         "9WXYZwxyz",
  27.         ".,!?@#$%^&*;",
  28.         "",
  29.         "",
  30.         "",
  31.     };
  32.  
  33.     const char *letterHex[] = {
  34.         "0",
  35.         "1",
  36.         "2ABC",
  37.         "3DEF",
  38.         "4",
  39.         "5",
  40.         "6",
  41.         "7",
  42.         "8",
  43.         "9",
  44.         "",
  45.         "",
  46.         "",
  47.         "",
  48.     };
  49.    
  50.     if(strlen(str)>len){
  51.         return d_NO;
  52.     }
  53.    
  54.     buf=malloc(len+1);
  55.     memset(buf, 0x00, len+1);
  56.        
  57.     strcpy(buf, str); //the initial string will be modified only in case of ENTER is pressed
  58.     if (buf[0] != 0) {
  59.         idx = strlen(buf);
  60.     }
  61.     while (1) {
  62.         idx = strlen(buf);
  63.         inCheckPos = loc + inPosLoc;
  64.         if (inCheckPos > 8) {
  65.             j += MAX_CHAR_PER_LINE;
  66.             //                                clearLine(8);
  67.         }
  68.         //display string
  69.         memset(szDisplay, 0x00, sizeof (szDisplay));
  70. //        for (i = 0, inPosLoc = 0; i < idx; i += MAX_CHAR_PER_LINE, inPosLoc++) {
  71.             for (i = j, inPosLoc = 0; i < idx; i += MAX_CHAR_PER_LINE, inPosLoc++) {
  72.             memset(szDisplay, ' ', MAX_CHAR_PER_LINE);
  73.            
  74.             inTempLen=idx-i>MAX_CHAR_PER_LINE?MAX_CHAR_PER_LINE:idx-i;
  75.             switch (fmt) {
  76.                 case '*': //password entering                    
  77.                     memset(szDisplay, '*', inTempLen);
  78.                     break;
  79.                 case 'X':
  80.                     fHex = TRUE;
  81.                     break;
  82.                 case ' ': //get the last dspW characters  
  83.                 default:
  84.                     memcpy(szDisplay, buf+i, inTempLen);
  85.                     break;
  86.             }
  87.             setLCDPrint(loc + inPosLoc, DISPLAY_POSITION_LEFT, szDisplay);
  88.         }
  89.        
  90.         if(inCheckPos > 8){
  91.             clearLine(8);
  92.         }
  93.         if (i > 0) //because of loop running
  94.         {
  95.             inPosLoc--;
  96.         }
  97.            
  98.  
  99.         letterInd = 0;
  100.         CTOS_KBDBufFlush();
  101.         //wait for user input
  102.         key = 0;
  103.         isKey = FALSE;
  104.  
  105.         CTOS_TimeOutSet(TIMER_ID_2, 60 * 100);
  106.         do {
  107.             CTOS_KBDInKey(&isKey);
  108.  
  109.             if (CTOS_TimeOutCheck(TIMER_ID_2) == d_YES) {
  110.                 free(buf);
  111.                 return d_NO;
  112.             }
  113.         } while (!isKey);
  114.  
  115.         preKey = 0;
  116.         CTOS_TimeOutSet(TIMER_ID_1, 12 * 10);
  117.         //the current position is always at the end of the string      
  118.         fFirst=TRUE;
  119.         while (CTOS_TimeOutCheck(TIMER_ID_1) != d_YES) {
  120.             if (fFirst == FALSE) {
  121.                 key = 0;
  122.                 isKey = FALSE;
  123.                 CTOS_KBDBufFlush();
  124.                 CTOS_TimeOutSet(TIMER_ID_1, 12 * 10);
  125.                 do {
  126.                     CTOS_KBDInKey(&isKey);
  127.  
  128.                     if (CTOS_TimeOutCheck(TIMER_ID_1) == d_YES)
  129.                         break;
  130.                 } while (!isKey);                
  131.             }
  132.             fFirst = FALSE;
  133.  
  134.             if (isKey == TRUE) {
  135.                 CTOS_KBDGet(&key);
  136.  
  137.                 if (key != d_KBD_DOT && key != '.')
  138.                     ind = key - '0';
  139.                 else if (key == d_KBD_DOT || key == '.') {
  140.                     key = '.';
  141.                     ind = 10;
  142.                 }
  143.             }
  144.  
  145.             switch (key) {
  146.                 case 0: // if no charachter pressed in 1.2 seconds ,start a timer for next character
  147.                     //timeout; the initial string is not modified
  148.                     CTOS_TimeOutSet(TIMER_ID_1, 0);
  149.                     break;
  150.                 case d_KBD_CANCEL:
  151.                     free(buf);
  152.                     return key; //aborted; the initial string is not modified
  153.                 case d_KBD_ENTER: //the entering is finished
  154.                     strcpy(str, buf); //now we can change the initial string                
  155.                     free(buf);
  156.                     return key;
  157.                 case d_KBD_CLEAR: //backspace, remove the last character entered    
  158.                     idx=strlen(buf);
  159.                     if (!idx) {
  160.                         CTOS_Beep();
  161.                     } else {
  162. //                        if (strlen(buf + (inPosLoc * MAX_CHAR_PER_LINE))==1)
  163. //                            clearLine(loc + inPosLoc);
  164.                        
  165.                         if (strlen(buf + (inLastPost * MAX_CHAR_PER_LINE))==1)
  166. //                            vduiClearBelow(loc+inPosLoc);
  167.                             clearLine(loc + inPosLoc);
  168.                        
  169.                         buf[idx - 1] = 0;
  170.                     }
  171.                     CTOS_TimeOutSet(TIMER_ID_1, 0);
  172.                     break;
  173.                 case d_KBD_1:
  174.                 case d_KBD_2:
  175.                 case d_KBD_3:
  176.                 case d_KBD_4:
  177.                 case d_KBD_5: //a valid key typed
  178.                 case d_KBD_6:
  179.                 case d_KBD_7:
  180.                 case d_KBD_8:
  181.                 case d_KBD_9:
  182.                 case d_KBD_0:
  183.                 case d_KBD_DOT:
  184.                 case '.':
  185.                     if (idx >= len - 1)
  186.                         CTOS_Beep();
  187.                     else {
  188.                         memset(letGroup, 0, sizeof (letGroup));
  189.  
  190.                         if (fHex == TRUE) {
  191.                             lenStr = strlen(&letterHex[ind][0]);
  192.                             memcpy(letGroup, &letterHex[ind][0], lenStr);
  193.                         } else {
  194.                             lenStr = strlen(&letterGrb[ind][0]);
  195.                             memcpy(letGroup, &letterGrb[ind][0], lenStr);
  196.                         }
  197.                        
  198.                         if(lenStr==0){
  199.                             CTOS_TimeOutSet(TIMER_ID_2, 60 * 10);
  200.                             break;
  201.                         }
  202.  
  203.                         inFmtPad(letGroup, 15, ' ');
  204.                         if (key == preKey) {
  205.                             if ((letterInd) >= (lenStr - 1)) {
  206.                                 letterInd = 0;
  207.                             } else
  208.                                 letterInd++;                          
  209.                         } else {
  210.                             if (preKey != 0){
  211.                                 letterInd = 0; //@@IBR 23052016 to make sure if changing key, go back to first array of letter
  212.                                 idx++;
  213.                             }
  214.                                
  215.                         }
  216.                         buf[idx] = letGroup[letterInd];
  217.  
  218. //                        inTempLen = strlen(buf + (inPosLoc * MAX_CHAR_PER_LINE));
  219.                         inTempLen = strlen(buf + (inLastPost * MAX_CHAR_PER_LINE));
  220.                        
  221.                         vdDebug_LogPrintf("@@IBR inTempLen = %d, inLastPost = %d", inTempLen, inLastPost);
  222.                        
  223.                         if (inTempLen > MAX_CHAR_PER_LINE) {
  224.                             inPosLoc++;
  225.                             inLastPost++;
  226.                            
  227.                         }
  228.                        
  229.                         memset(szDisplay, 0x00, sizeof(szDisplay));
  230.                         if (fmt == '*') {                            
  231.                             inFmtPad(szDisplay, strlen(buf + (inPosLoc * MAX_CHAR_PER_LINE)), '*');
  232.                             szDisplay[strlen(szDisplay) - 1] = buf[idx];
  233.                         } else {
  234. //                            strcpy(szDisplay, buf + (inPosLoc * MAX_CHAR_PER_LINE));
  235.                             strcpy(szDisplay, buf + (inLastPost * MAX_CHAR_PER_LINE));
  236.                         }
  237.                        
  238.                         vdDebug_LogPrintf("@@IBR szDisplay [%s]", szDisplay);
  239.                         setLCDPrint(loc+inPosLoc, DISPLAY_POSITION_LEFT, szDisplay);
  240.  
  241.                         preKey = key;
  242.                     }
  243.  
  244.                     CTOS_TimeOutSet(TIMER_ID_2, 60 * 10);
  245.                     break;
  246.                 default:
  247.                     CTOS_Beep();
  248.                     CTOS_TimeOutSet(TIMER_ID_1, 0);
  249.                     break; //invalid key pressed
  250.             } //end switch                      
  251.         } //while
  252.     } //while
  253.  
  254. lblKO:
  255.     free(buf);
  256.     return d_NO;
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement