OSDN Git Service

[UART][SHELL] Fix correct timeout, 10Sec(temp).
[openi2cradio/OpenI2CRadio.git] / uart_termio.c
index ff912e4..97e3419 100644 (file)
@@ -41,7 +41,7 @@
 #include "menu.h"
 #include "uart_termio.h"
 #include "shell_strutl.h"
-
+#include "power.h"
 
 unsigned char uart_term_putstr(unsigned char *s)
 {
@@ -56,19 +56,45 @@ unsigned char uart_term_putstr(unsigned char *s)
     return 0xff;
 }
 
-void uart_term_getstr(unsigned char *s, unsigned char maxlen, unsigned char echo)
+void uart_term_getstr(unsigned char *s, unsigned int timeout, unsigned char echo)
 {
     unsigned char i = 0;
     unsigned char c = 0x00;
-    while(c != '\n'){
+    unsigned int tim;
+    unsigned char pwr;
+    unsigned char cnt;
+    tim = 0;
+    cnt = 0;
+    while(1){
         ClrWdt();
         c = uart_pullchar();
         if(c != 0x00) {
+           if(cnt > 10) {
+               if(chk_powerbutton() != 0) {
+                   shutdown(0xff);
+               }
+              cnt = 0;
+           }
+           cnt++;
             s[i] = c;
+           if((c == '\i') || (c == '\n')) break;
             if(echo != 0) uart_pushchar(c, 0); // Echoback
             i++;
-            if(i >= maxlen) break;
-        }
+            if(i >= 128) break;
+           tim = 0;
+       } else if(timeout != 0) { // ZAP n * 100mSec.
+           if(chk_powerbutton() != 0) shutdown(0xff); 
+           idle_time_ms(100 - 48); // Poll 0.1Sec
+           tim++;
+           if(tim > timeout) {
+              s[0] = TERM_CHAR_TIMEOUT;
+              i = 1;
+              break;
+           }
+       } else {
+         idle_time_ms(100 - 48); // Wait 100ms if none (and no Timeout).
+         if(chk_powerbutton() != 0) shutdown(0xff); 
+       }
     }
     s[i] = '\0';
 }