I found a solution that seems to fit:
#include <stdio.h>
#include <string.h>
#include "esp_system.h"
#include "esp_console.h"
#include "esp_vfs_dev.h"
#include "esp_vfs_fat.h"
#include "driver/uart.h"
void app_main(void)
{
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
char chr[10];
while(1){
printf("Enter Data : ");
scanf("%9s\n", chr);
printf("\nData entered : %s.\n", chr);
}
}
The above program works well, I enter a string in the console (10 maximum), and when I press "Enter" the code displays the previously entered string. However, some problem persists:
- Sometimes there is a bug that appears randomly:
I think it's a display bug but I'm not sure.
- The characters are not displayed as I type them on the keyboard. They only appear once I press "Enter".
- Last problem, once I type the string and press "Enter" the string does not appear. It only appears once I start writing the new string.
I would like to know if there are any solutions to solve these problems.