funbiscuit / embedded-cli

Single-header CLI with history and autocompletion for embedded systems (like Arduino or STM32)
MIT License
242 stars 38 forks source link

Add access to raw input inside command binding #16

Open funbiscuit opened 1 year ago

funbiscuit commented 1 year ago

Example:

void onAdc(EmbeddedCli *cli, char *args, void *context) {
    // somehow get input
   while (embeddedCliBytesAvailable(cli) > 0) {
       uint8_t b = embeddedCliReadByte(cli);
   }
}

If you input is read from cli, it will not be then processed as command. For example suppose command binding for get-adc and following input is given:

get-adc
get-adc
get-adc

If in binding get-adc 3 bytes are read, then cli will see following:

get-adc // call binding get-adc
-adc // call unknown command "-adc" ("get" was read by user inside binding)
get-adc // call binding get-adc

Another important thing is that this will work correctly only if raw input is provided to cli only inside ISR. Otherwise new input will not be added while command binding is executing (unless it is added it manually, but that's a bad design)

Initial request by @windsunsjtu in https://github.com/funbiscuit/embedded-cli/discussions/15

windsunsjtu commented 1 year ago

I think this is already good enough for me. Take get-adc as an example, the get-adc could output the ADC reading continuously, what I want is to press any key to stop the loop. I like your suggestion for its simplicity.