#include #include #include "esp_err.h" #include "esp_system.h" #include "esp_log.h" #include "esp_console.h" #include "esp_vfs_dev.h" #include "linenoise/linenoise.h" #include "esp_vfs_usb_serial_jtag.h" #include "driver/usb_serial_jtag.h" #include "cmd_system.h" #include "can.h" #include "fs.h" #include "console_task.h" static void initialize_console(void) { /* Disable buffering on stdin */ setvbuf(stdin, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); /* Enable non-blocking mode on stdin and stdout */ fcntl(fileno(stdout), F_SETFL, 0); fcntl(fileno(stdin), F_SETFL, 0); usb_serial_jtag_driver_config_t usb_serial_jtag_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT(); /* Install USB-SERIAL-JTAG driver for interrupt-driven reads and writes */ ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_jtag_config)); /* Tell vfs to use usb-serial-jtag driver */ esp_vfs_usb_serial_jtag_use_driver(); /* Initialize the console */ esp_console_config_t console_config = { .max_cmdline_args = 8, .max_cmdline_length = 256, #if CONFIG_LOG_COLORS .hint_color = atoi(LOG_COLOR_CYAN) #endif }; ESP_ERROR_CHECK(esp_console_init(&console_config)); /* Configure linenoise line completion library */ /* Enable multiline editing. If not set, long commands will scroll within * single line. */ linenoiseSetMultiLine(1); /* Tell linenoise where to get command completions and hints */ // linenoiseSetCompletionCallback(&esp_console_get_completion); linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint); /* Set command history size */ linenoiseHistorySetMaxLen(100); /* Set command maximum length */ linenoiseSetMaxLineLen(console_config.max_cmdline_length); /* Allow empty lines */ linenoiseAllowEmpty(true); /* Load command history from filesystem */ linenoiseHistoryLoad(HISTORY_PATH); } void app_main(void) { can_init(); xTaskCreate(can_task, "can task", 4096, NULL, CONFIG_CAN_TASK_PRIORITY, NULL); initialize_filesystem(); initialize_console(); /* Register commands */ esp_console_register_help_command(); register_system(); xTaskCreate(console_task, "console task", 4096, NULL, CONFIG_CONSOLE_TASK_PRIORITY, NULL); }