ESP-IDF |从键盘输入任务

发布于 2025-01-23 12:23:49 字数 1014 浏览 4 评论 0原文

如何从ESP-IDF中的任务中的键盘中获取输入,

我尝试过的代码是

void xTask1(void *params)
{
    while (true)
    {
        
        char c = 0;
        char str[4];
        memset(str, 0, sizeof(str));
        while (c != '\n')
        {
            printf("Enter the value:\n");
            c = getchar();
            if (c != 0xff)
            {
                str[strlen(str)] = c;
                printf("%c", c);
            }
            vTaskDelay(100 / portTICK_PERIOD_MS);
        }

        int d = atoi(str);

        printf("you have typed : %d\n", d);

        
    }
}

void app_main(void)
{

    xTaskCreate(xTask1, "task1", 2048, NULL, 1, NULL);
}

,我要获得的输出

I (309) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:

不是输入输入,

  • 我在这里犯的错误是什么?

How to take input from keyboard inside a task in ESP-IDF ,

The code I have tried is

void xTask1(void *params)
{
    while (true)
    {
        
        char c = 0;
        char str[4];
        memset(str, 0, sizeof(str));
        while (c != '\n')
        {
            printf("Enter the value:\n");
            c = getchar();
            if (c != 0xff)
            {
                str[strlen(str)] = c;
                printf("%c", c);
            }
            vTaskDelay(100 / portTICK_PERIOD_MS);
        }

        int d = atoi(str);

        printf("you have typed : %d\n", d);

        
    }
}

void app_main(void)
{

    xTaskCreate(xTask1, "task1", 2048, NULL, 1, NULL);
}

and the output I am getting is

I (309) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:
Enter the value:

Its not holding in to enter the input,

  • What is the mistake I am making here.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文