Skip to content

Gregwar/esp32-shell

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 

Repository files navigation

Rhoban Shell for mbed

This package provides a shell that can be used with mbed and USB Serial emulator.

Setting up

Add the following to your platformio.ini:

lib_deps =
    https://github.com/rhoban/mbed-shell.git

Initialize the shell

You can simply include:

#include "shell.h"

And then initialize it in your main():

shell_init_usb();

The shell will then run on a background task with lowest priority.

Using commands

You can declare commands:

SHELL_COMMAND(hello, "Say hello")
{
    if (argc == 0) {
        shell_println("Hello!");
    } else {
        shell_print("Hello ");
        shell_print(argv[0]);
        shell_println("!");
    }
}

Using parameters

You can declare parameters with following macros:

SHELL_PARAMETER_INT(i, "An int", 5);
SHELL_PARAMETER_FLOAT(f, "A float", 12.5);
SHELL_PARAMETER_INT(b, "A bool", false);

Those parameters can be used as regular read/write variables in the code, and read or assigned in the terminal.

Endless command

It is possible to create an endless command by checking for availability of data with shell_available():

SHELL_COMMAND(count, "Count")
{
    int k = 0;
    while (!shell_available()) {
        k += 1;
        shell_println(k);
        ThisThread::sleep_for(1000);
    }
}

This will display numbers until you press any key.

Printing

You can use shell_printf(), but it is known to be a very slow function, and floats are not supported.

Alternatively, you can also call shell_print() and shell_println() functions. It is possible to print floats with a provided precision (default=2 decimals):

float x = 0.123456;
shell_print("x=");
shell_println(x, 6);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 69.7%
  • C 30.3%