I need to read input from the user console

User avatar
mzimmers
Posts: 87
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: I need to read input from the user console

Postby mzimmers » Mon Mar 26, 2018 7:00 pm

Hi John -

Thanks for the reply. I did find the source for that routine OK, but I was wondering why the linker isn't finding it in that library, as it does for the example program. I need to know more about the build system, I guess, but if it's in the library, and if my program needs it, why doesn't the linker extract it from that library?

(as a side note: I too am a fan of Notepad++, but IMO there are a couple of other tools that are even better for finding text strings. One is grepWin, a free one-window download that gives you excellent find/replace functionality. The other is the Qt Creator IDE. Even though I can't build for the esp32 with it (yet) I can edit, and it has a "follow symbol under cursor" command that is excellent in this regard.)

Also, I mentioned this elsewhere, but I'm having trouble getting the linker to recognize my app_main in main.cpp. I use the extern "C" around the definition of app_main, but I don't have an explicit declaration of it anywhere. Any ideas here would be very appreciated.

User avatar
mzimmers
Posts: 87
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: I need to read input from the user console

Postby mzimmers » Tue Mar 27, 2018 6:50 pm

I found the cause of those undefined references. It was indeed a C/C++ issue. I'm including a very helpful page for those who will inevitably trip over this in the future:

https://isocpp.org/wiki/faq/mixing-c-and-cpp#call-c

This is especially useful for those who want to program in C++ and also want to incorporate third-party code that is written in C (like linenoise) without modification.

User avatar
mzimmers
Posts: 87
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: I need to read input from the user console

Postby mzimmers » Fri Apr 27, 2018 6:21 pm

Just as an FYI, I got around to trying the scanf and it didn't work - it returned immediately without waiting for input, and returns a (-1). I'll have to try something else.

User avatar
dashxdr
Posts: 1
Joined: Thu Jun 14, 2018 6:20 pm

Re: I need to read input from the user console

Postby dashxdr » Thu Jun 14, 2018 6:26 pm

I added a reduced version of linenoise and glue that accomplishes a command line with history and editing.

I got rid of the completion and hints and file load/save of the history. The code I started from came from
esp-idf/components/console/linenoise/linenoise.c

My fork:
https://github.com/dashxdr/duktape-esp32

nkolban's usually quick to merge pull requests so most likely we'll be in sync again

ESP_igrr
Posts: 1000
Joined: Tue Dec 01, 2015 8:37 am

Re: I need to read input from the user console

Postby ESP_igrr » Fri Jun 15, 2018 6:32 am

mzimmers wrote:Just as an FYI, I got around to trying the scanf and it didn't work - it returned immediately without waiting for input, and returns a (-1). I'll have to try something else.


By default, UART I/O is implemented using simple routines (blocking output, non-blocking input). To use scanf and other functions which depend on blocking input behaviour, you need to tell the UART I/O to use UART driver instead.

(See https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/vfs.html#standard-io-streams-stdin-stdout-stderr)


This is a snippet from the console example:

Code: Select all

    /* Install UART driver for interrupt-driven reads and writes */
    ESP_ERROR_CHECK( uart_driver_install(CONFIG_CONSOLE_UART_NUM,
            256, 0, 0, NULL, 0) );

    /* Tell VFS to use UART driver */
    esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM);


The other two bits which are optional, but probably useful, are to set the desired line ending conversion and disable buffering:

Code: Select all

    /* Disable buffering on stdin and stdout */
    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);

    /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */
    esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
    /* Move the caret to the beginning of the next line on '\n' */
    esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);

Again, that's from "initialize_console" function in console example.

Who is online

Users browsing this forum: Google [Bot] and 1 guest