getc using shell?
Moderators: RoccoMarco, lbednarz, tfAteba
getc using shell?
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)
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: getc using shell?
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
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?
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!!!
- 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!!!
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: getc using shell?
Hi,
Look at the following example:
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
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?
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?
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?
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?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: getc using shell?
You can use both, chprintf() internally uses chSequentialStreamWrite().
Giovanni
Giovanni