/** ConsolTest.c ÀÌ ¸ðµâÀº DHL_OS_Printf ¿Í DHL_OS_GetChar ¿¡ ´ëÇÑ Å×½ºÆ® ·çƾÀÌ´Ù. */ #include "DHL_OSAL.h" //#include "DHL_APITest.h" //#include #if COMMENT ____Test_1____(){} #endif /* ±âº» ÀÔ/Ãâ·Â µ¿ÀÛ Å×½ºÆ®. ±ÛÀÚ ÇÑÀÚ¸¦ ÀÔ·Â ¹Þ°í ÀÔ·Â ¹ÞÀº ±ÛÀÚÀÇ ASCII Äڵ带 ´Ù½Ã Ãâ·ÂÇÑ´Ù. üũ Æ÷ÀÎÆ®: 1. ÀÔ·ÂÀÌ ¾ø´Â °æ¿ì NULL ÀÌ ¸®ÅϵǴÂÁö ¾Æ´Ï¸é ´ë±âÇÏ´ÂÁö È®ÀÎÇÑ´Ù. */ void Console_EchoTest(void) { UINT32 key, prev_key = 0; int count = 0; DHL_OS_Printf("\n\n%s\n\n", __func__); DHL_OS_Printf("press same key 5 times to exit..\n"); while (1) { key = DHL_OS_GetChar(); if (key >= 0x20 && key < 0x7f) // ASCII DHL_OS_Printf("input char: %02x, '%c'\n", key, key); else DHL_OS_Printf("input char: %08x\n", key); // check exit condition. count = (key == prev_key) ? count+1 : 0; prev_key = key; if (count >= 5) { DHL_OS_Printf("exit test\n"); break; } } } #if COMMENT ____Test_2____(){} #endif /* DHL_EXTKEY_t enum ŸÀÔÀº API header ÆÄÀÏ·Î À̵¿ÇÔ. */ struct DHL_EXTKEY_NAME_t { UINT32 extkey; char *name; }; static struct DHL_EXTKEY_NAME_t extkeytbl[] = { DHL_EXTKEY_TAB, "TAB", DHL_EXTKEY_CR, "CR", DHL_EXTKEY_ESC, "ESC", DHL_EXTKEY_F1, "F1", DHL_EXTKEY_F2, "F2", DHL_EXTKEY_F3, "F3", DHL_EXTKEY_F4, "F4", DHL_EXTKEY_F5, "F5", DHL_EXTKEY_F6, "F6", DHL_EXTKEY_F7, "F7", DHL_EXTKEY_F8, "F8", DHL_EXTKEY_F9, "F9", DHL_EXTKEY_F10, "F10", DHL_EXTKEY_F11, "F11", DHL_EXTKEY_F12, "F12", DHL_EXTKEY_DEL, "DEL", DHL_EXTKEY_UP, "Up", DHL_EXTKEY_DN, "Down", DHL_EXTKEY_RG, "Right", DHL_EXTKEY_LF, "Left", DHL_EXTKEY_PGUP, "PgUp", DHL_EXTKEY_PGDN, "PgDn", DHL_EXTKEY_HOME, "Home", DHL_EXTKEY_END, "End", }; static char *get_key_string(int key) { int i; for (i=0; i= 0x20 && key < 0x7f) // ASCII DHL_OS_Printf("(%04u) input char: %02x, '%c'\n", ms%10000, key, key); else if (key <= 0xff) // 8-bits DHL_OS_Printf("(%04u) input char: %02x, '%s'\n", ms%10000, key, get_key_string(key)); else DHL_OS_Printf("(%04u) input char: %08x, '%s'\n", ms%10000, key, get_key_string(key)); // check exit condition. count = (key == prev_key) ? count+1 : 0; prev_key = key; if (count >= 5) { DHL_OS_Printf("exit test\n"); break; } } } /* press same key 5 times to exit.. (4071) input char: 61, 'a' (4292) input char: 62, 'b' (4544) input char: 63, 'c' (4776) input char: 64, 'd' (7508) input char: 7f31317e, 'F1' (7860) input char: 7f31327e, 'F2' (8130) input char: 7f31337e, 'F3' (9681) input char: 7f000044, 'Left' (0023) input char: 7f000043, 'Right' (0515) input char: 7f000041, 'Up' (0767) input char: 7f000042, 'Down' (4563) input char: 20, ' ' (4743) input char: 20, ' ' (4944) input char: 20, ' ' (5115) input char: 20, ' ' (5305) input char: 20, ' ' (5658) input char: 20, ' ' exit test */ #if COMMENT ____Test_3____(){} #endif /* string.h ÀÇ memmove°¡ Á¦°øµÇÁö ¾Ê´Â systemÀ» À§ÇÑ ¹è·Á. */ #if NEED_MEMMOVE_DEFINE static void memmove(void *dst, void *src, int len) { UINT8 *pd = dst, *ps = src; if (len <= 0) return; // nothing to move. if (dst < src) { // copy from first while (len-- > 0) *pd++ = *ps++; } else if (src < dst) { // copy from last pd += len-1; ps += len-1; while (len-- > 0) *pd-- = *ps--; } else { // we don't need to move. } } #endif /* wait console input, and make up line command and return. @buf is address of buffer where input command is stored. @size is maximum size of @buf. return the number of characters input. return -1 if input is cancelled by ESC (or Ctrl+C). @buf does not contain trailing CR/LF. This does not privode command history function. Use mini shell for more powerful shell feature. */ #define DHL_CONSOLE_FLAG_NOECHO 0x1 static int get_line(char *buf, int size, UINT32 flags) { char *p = buf; UINT32 key; char tmp[10] = {0, }; BOOL cancelled = FALSE; while (1) { key = DHL_OS_GetChar(); if (key == 0) continue; if (key == 0xd || key == 0xa) { *p = 0; // null terminate and exit if (!(flags & DHL_CONSOLE_FLAG_NOECHO)) DHL_OS_Printf("\n"); break; } else if (key == 0x1b) { // ESC key cancelled = TRUE; break; } // process input key // if (key == '\b' || key == 0x7F) { // backspace is treated as special if (p > buf) { // go back ÇÒ ±ÛÀÚ°¡ ÀÖ´Â °æ¿ì¿¡¸¸.. if (!(flags & DHL_CONSOLE_FLAG_NOECHO)) DHL_OS_Printf("\b \b"); *--p = ' '; } continue; } else if ((int)(p - buf) < size-1) { if (!(flags & DHL_CONSOLE_FLAG_NOECHO)) { tmp[0] = key; tmp[1] = 0; // ÇÑ ±ÛÀÚ¸¸ Ãâ·Â. DHL_OS_Printf(tmp); } *p++ = key; } else { // do nothing, just ignore key.. buffer full } } if (cancelled) return -1; // trim trailing spaces p = buf + strlen(buf) - 1; while (p >= buf && (*p == ' ' || *p == '\t')) { *p-- = 0; //n_trim++; } // skip head spaces and tab p = buf; while (*p == ' ' || *p == '\t') p++; // shift strings if (p != buf) memmove(buf, p, strlen(p)+1); return strlen(buf); } void Console_LineTest(void) { int n; char buf[200]; DHL_OS_Printf("\n\n%s\n\n", __func__); DHL_OS_Printf("type 'exit' to exit..\n"); while (1) { DHL_OS_Printf("input: "); // ¿ø·¡ driver¿¡¼­´Â echo¸¦ ÇÏÁö ¾ÊÀ¸¹Ç·Î // DHL¿¡¼­ echo¸¦ ÇØÁÖ´Â °ÍÀÌ ¸Â´Ù. n = get_line(buf, sizeof(buf), 0); if (n < 0) { // cancelled. DHL_OS_Printf(" ESC\n"); continue; } if (n == 0) continue; DHL_OS_Printf("[%s]\n", buf); // check exit condition if (strcmp(buf, "exit") == 0) { DHL_OS_Printf("exit test\n"); break; } } } /* Å×½ºÆ® °á°ú: Console_LineTest type 'exit' to exit.. input: This is test [This is test] input: exit [exit] exit test */ /* end of file */