Page 1 of 1
getc using shell?
Posted: Tue Jan 21, 2014 5:14 am
by ljfischer
I want to create a monitor that constantly updates my terminal - vt100 style. It should parse individual keystrokes and react to them. Is there any *standard* way to do that using the shell? (Ive got lots of background activity doing ADC, etc)
Re: getc using shell?
Posted: Tue Jan 21, 2014 10:09 am
by Giovanni
Hi,
It is not clear for me, if you use the shell, it is the shell getting keystrokes and updating the terminal. Shell commands can interact with the I/O stream using the interface passed as parameter. What do you need to do exactly?
Giovanni
Re: getc using shell?
Posted: Tue Jan 21, 2014 3:07 pm
by mobyfab
Re: getc using shell?
Posted: Tue Jan 21, 2014 3:19 pm
by ljfischer
Two things Im looking for:
- Im looking for greater understanding of the shell *context*. I know how to output data to the terminal, when I get a shell command callback. I would like to output data, using chprintf, outside of those callbacks. For instance, in my main thread or in a sub thread. Or at least have a shell thread that can process data and output it.
- While using the shell, Im looking for a 'single character typed' notifier - fgetc like. So that when I have a monitor being displayed, single characters, without return, can cause things to happen.
Can these things be done via the "shell?"
Thanks,
larry
- And thank you for the fast reply!!!
Re: getc using shell?
Posted: Tue Jan 21, 2014 3:23 pm
by Giovanni
Hi,
Look at the following example:
Code: Select all
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
static uint8_t buf[] =
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
(void)argv;
if (argc > 0) {
chprintf(chp, "Usage: write\r\n");
return;
}
while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
chSequentialStreamWrite(&SDU2, buf, sizeof buf - 1);
}
chprintf(chp, "\r\n\nstopped\r\n");
}
It is a shell command that runs until a key is pressed (any key). "chp" is the console channel where you can read and write using the channels API.
Giovanni
Re: getc using shell?
Posted: Tue Jan 21, 2014 3:55 pm
by ljfischer
Perfect!
Thank you!
Larry
Re: getc using shell?
Posted: Tue Jan 21, 2014 8:22 pm
by skute
There is a nice, minimal readline-like console @
https://github.com/Helius/microrl. You provide characters to it and a printing function and it will process the escape characters and command completions and such. This would provide you with the vt100 type of interface you are looking for.
Re: getc using shell?
Posted: Sat Jan 25, 2014 2:25 pm
by ljfischer
No worries on the vt100 - thats easy enough.
One more question: Using the mechanism that we described, is it still valid to use chprintf, or do I need to manage my printing via chSequentialStreamWrite?
Re: getc using shell?
Posted: Sat Jan 25, 2014 4:00 pm
by Giovanni
You can use both, chprintf() internally uses chSequentialStreamWrite().
Giovanni