9 years, 3 months ago.

How to set up the terminal program screen (on a mac) so that scant will echo users input:

Hi

I have been playing around with user input to an mbed C program using a kl25z board. It works fine but typing data in response to a scant(..) statement is not echoed to the terminal program screen.

I have looked at the screen reference manual and also a number of web sites via google but cannot see how this had be done.

I see that others have asked this question before but there does not (as yet) appear to be any answers.

It seems as if it should be an easy thing to do like turning echo on.

Peter

2 Answers

9 years, 2 months ago.

Hi Peter,

One solution is to get your mbed to echo the user input. However doing this precludes the use of scanf(). Instead, what you have to do is buffer (and echo) a line of user input and only process it when the user presses return. You can then use sscanf() firstly to split the input line into separate arguments and then to process the arguments.

The program fragment below gives the gist. In all cases the first character of the first argument is the command. Parameters are in subsequent characters of the first argument (e.g. c0 or c1) or in subsequent arguments (e.g. b 50).

Serial pc(USBTX, USBRX);

int main() {
    char buf[120], *cp;
    char arg0[50], arg1[50], arg2[50];
    int argc, i;

    pc.baud(9600);
    pc.printf("\n\nHello World\n");
    pc.printf("Type ? for help\n> ");  

    while (1) {
        pc.printf("> ");
        cp = buf;
        while ( (*cp++ = putchar(getchar())) != '\r') ;   //get a line of input
        *cp = '\0';                                       //terminate buffer
        printf("\n");
        //extract command and arguments
        argc = sscanf(buf, "%s%s%s", arg0, arg1, arg2);
        if (argc < 1)
            continue;
        switch (arg0[0]) {
            case '?':        //print help
                printHelps();
                break;

            case 'b':       //set backlight level as a percentage (0 - 100)
            	if (argc > 1) {
            		sscanf(arg1, "%d", &i);
            		backlight = i / 100.0;
            	}
            	pc.printf("backlight = %4.2f\n", (float) backlight);
                break;

            case 'c':		//cursor operations
                switch (arg0[1]) {
					case '0':
					dog.cursor(false);
					break;

					case '1':
					dog.cursor(true);
					break;
                }
            	break;

            default:
                pc.printf("?? Unknown command\n");
                break;
        }
    }
}

Hope this helps.

Paul

9 years, 2 months ago.

I don't know how to set the "screen" command to have local echo. So I think Paul's idea is good option to implement.
But if you hesitate to write the echoing-back mechanism in mbed program, another option may be to use CoolTerm.
This application supports the local echo :)

/media/uploads/okano/coolterm_localecho0.png