Modify the Linux example of XCMD
This commit is contained in:
parent
22dd57e08b
commit
db790b5548
|
@ -9,6 +9,9 @@
|
|||
#include<sys/socket.h>
|
||||
#include <termio.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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<argc; i++)
|
||||
{
|
||||
if(argv[i] != NULL)
|
||||
{
|
||||
printf("%s ", argv[i]);
|
||||
xcmd_print(g_cmder, "%s ", argv[i]);
|
||||
}
|
||||
}
|
||||
printf("\r\n");
|
||||
xcmd_print(g_cmder, "\r\n");
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
|
@ -50,7 +51,7 @@ static void cmd_echo(int argc, char* argv[])
|
|||
{
|
||||
if(param_check(1, argc, argv))
|
||||
{
|
||||
printf("%s\r\n", argv[1]);
|
||||
xcmd_print(g_cmder, "%s\r\n", argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,21 +64,21 @@ static void cmd_example(int argc, char* argv[])
|
|||
{
|
||||
for(i=2; i<argc; i++)
|
||||
{
|
||||
printf("%s\r\n", argv[i]);
|
||||
xcmd_print(g_cmder, "%s\r\n", argv[i]);
|
||||
}
|
||||
}
|
||||
if(strcmp(argv[1], "int") == 0)
|
||||
{
|
||||
for(i=2; i<argc; i++)
|
||||
{
|
||||
printf("%d\r\n", atoi(argv[i]));
|
||||
xcmd_print(g_cmder, "%d\r\n", atoi(argv[i]));
|
||||
}
|
||||
}
|
||||
if(strcmp(argv[1], "float") == 0)
|
||||
{
|
||||
for(i=2; i<argc; i++)
|
||||
{
|
||||
printf("%f\r\n", atof(argv[i]));
|
||||
xcmd_print(g_cmder, "%f\r\n", atof(argv[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue