From db790b55489086768f4d44f99641c23e5e93429a Mon Sep 17 00:00:00 2001 From: weidonglin Date: Mon, 13 Sep 2021 20:25:39 +0800 Subject: [PATCH] Modify the Linux example of XCMD --- example/linux/linux_main.c | 28 ++++++++++++++++++---------- example/linux/test_cmds.c | 19 ++++++++++--------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/example/linux/linux_main.c b/example/linux/linux_main.c index 24daf6b..d559974 100755 --- a/example/linux/linux_main.c +++ b/example/linux/linux_main.c @@ -9,6 +9,9 @@ #include #include +static xcmder_t *g_cmder = NULL; + + extern void test_cmd_init(xcmder_t *cmder); int getch(void) @@ -27,7 +30,7 @@ int getch(void) } ch = getchar(); - // printf("%d\n", ch); + //xcmd_print(g_cmder, "%d\n", ch); if (tcsetattr(fd, TCSANOW, &tm_old) < 0) {//更改设置为最初的样子 return -1; } @@ -49,7 +52,7 @@ int cmd_put_char(uint8_t ch) int cmd_ctr_a(void* pv) { - printf("this is ctr+a\n"); + xcmd_print(g_cmder, "this is ctr+a\n"); } int cmd_ctr_c(void* pv) @@ -68,19 +71,24 @@ void user_keys_init(xcmder_t *cmder) xcmd_key_register(cmder, user_keys, sizeof(user_keys)/sizeof(xcmd_key_t)); } +xcmder_t* user_get_cmder(void) +{ + return g_cmder; +} + int main(void) { - xcmder_t* cmder = xcmd_create_default(cmd_get_char, cmd_put_char); - if(cmder) + xcmder_t* g_cmder = xcmd_create_default(cmd_get_char, cmd_put_char); + if(g_cmder) { - test_cmd_init(cmder); - user_keys_init(cmder); - default_keys_init(cmder); - default_cmds_init(cmder); - xcmd_exec(cmder, "logo"); + test_cmd_init(g_cmder); + user_keys_init(g_cmder); + default_keys_init(g_cmder); + default_cmds_init(g_cmder); + xcmd_exec(g_cmder, "logo"); while(1) { - xcmd_task(cmder); + xcmd_task(g_cmder); } } return 1; diff --git a/example/linux/test_cmds.c b/example/linux/test_cmds.c index d25a02a..13cc4fe 100755 --- a/example/linux/test_cmds.c +++ b/example/linux/test_cmds.c @@ -5,7 +5,8 @@ static xcmder_t *g_cmder = NULL; -#define EXIT_MESSAGE() printf("press \"q\" or \"Q\" to exit!\r\n") +#define EXIT_MESSAGE() xcmd_print(g_cmder, "press \"q\" or \"Q\" to exit!\r\n") + #define EXIT_CHECK() \ do \ (toupper(GET_CHAR()) == 'Q') \ @@ -31,16 +32,16 @@ static uint8_t param_check(int need, int argc, char*argv[]) } else { - printf("err need %d but input %d:\r\n", need, argc-1); - printf("input= "); + xcmd_print(g_cmder, "err need %d but input %d:\r\n", need, argc-1); + xcmd_print(g_cmder, "input= "); for(i=0; i