1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00
arduinolibs/doc/shell-serial.dox
2016-03-13 07:20:03 +10:00

81 lines
3.2 KiB
Plaintext

/*
* Copyright (C) 2016 Southern Storm Software, Pty Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
\file shell-serial.dox
\page shell_serial Serial port Shell example
The Shell class provides a Unix-like shell for issuing commands to
the Arduino. This example shows how to use Shell to provide command-line
access via a serial port. The example has one command "led" for turning
the status LED on D13 on and off.
We start by including the shell library definitions and declaring a
variable of type Shell:
\dontinclude Terminal/examples/SerialShell/SerialShell.ino
\skip #include
\until Shell shell;
Next we need to initialize the serial port and tell the shell object
to use it for communications:
\dontinclude Terminal/examples/SerialShell/SerialShell.ino
\skip void setup()
\until }
The call to \link Shell::setPrompt() shell.setPrompt()\endlink specifies
the prompt to display whenever a new line of input is required. The
default value is "$ " but we have changed it to "Command: " in this example.
The string can be anything and can be changed later if necessary.
The call to \link Shell::begin() shell.begin()\endlink starts the actual
shell. The first argument is the underlying stream to use for
communications, the Serial port in our case. The second argument sets the
size of the history stack so that Shell can remember previous commands
and let the user navigate back to them with the up/down arrow keys.
The shell needs to regularly process input from the serial port and
handle commands. We accomplish this by calling
\link Shell::loop() shell.loop()\endlink from the application's main
loop() function:
\dontinclude Terminal/examples/SerialShell/SerialShell.ino
\skip void loop()
\until }
At this point the application will have two builtin commands, "help" and
"exit". But we also want a command of our own. We do this by declaring a
command handler:
\dontinclude Terminal/examples/SerialShell/SerialShell.ino
\skip int ledPin
\until ShellCommand
The ShellCommand() macro informs the shell of a new command with its name,
help string, and the name of the handler function.
The full source code for the example follows:
\include Terminal/examples/SerialShell/SerialShell.ino
*/