Skip to content

Commit 4f830e6

Browse files
geekfactorygeekfactory
authored andcommitted
Added new examples: RGB Led and Ethernet Shield Example
1 parent d49db60 commit 4f830e6

File tree

6 files changed

+279
-66
lines changed

6 files changed

+279
-66
lines changed

examples/Shell_Basic_Example/Shell_Basic_Example.ino renamed to examples/Shell_Basic/Shell_Basic.ino

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
/**
2-
* SIMPLE EXAMPLE OF COMMAND SHELL LIBRARY
3-
*
4-
* This library implements a command line interface. The experience is similar to the windows
5-
* command prompt. This library can invoke functions when a specific string is received, in this
6-
* example we register 2 commands that can be executed by typing their names on the arduino serial
7-
* monitor (using the hardware UART).
8-
*
9-
* The "shell" library is designed to be independent of the communication channel, this means
10-
* that it can be used with serial, softSerial and even TCP connections. For this reason the
11-
* shell library requires 2 pointers to functions to read and write characters to and from the
12-
* physical transmission media.
13-
*
14-
* Arguments can be passed to the programs that are invoked by the command line and parsed by
15-
* standard string parsing functions, or you can write your own functions. The arguments
16-
* are passed as pointers to characters (null terminated strings) in a similar way that you
17-
* would receive them on any command line tool written in C. Each parameter is separated by
18-
* a "space" character after the command name.
2+
* GeekFactory - "Construye tu propia tecnologia"
3+
* Distribucion de materiales para el desarrollo e innovacion tecnologica
4+
* www.geekfactory.mx
5+
*
6+
* Ejemplo de libreria Shell. Este ejemplo representa la configuracion minima
7+
* requerida para implementar la funcionalidad de interfaz de comandos. En esta
8+
* ocasion registramos 2 comandos y enviamos texto como respuesta a cada uno.
9+
*
10+
* Example for Shell library. This example shows the minimum setup needed to
11+
* implement a command line interface. This time we register 2 commands and we
12+
* send text as response for each command.
1913
*/
2014

2115
#include <Shell.h>
@@ -48,7 +42,7 @@ void loop()
4842
* They receive 2 parameters: The total count of arguments (argc) and a pointer
4943
* to the begining of each one of the null-terminated argument strings.
5044
*
51-
+ In this example we ignore the parameters passed to the functions
45+
* In this example we ignore the parameters passed to the functions
5246
*/
5347
int command_mycommand(int argc, char** argv)
5448
{
@@ -81,7 +75,7 @@ int shell_reader(char * data)
8175

8276
/**
8377
* Function to write data to serial port
84-
* Functions to write to physical media should use this prototype
78+
* Functions to write to physical media should use this prototype:
8579
* void my_writer_function(char data)
8680
*/
8781
void shell_writer(char data)

examples/Shell_Command_Args/Shell_Command_Args.ino

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
21
/**
3-
* SIMPLE EXAMPLE OF COMMAND SHELL LIBRARY
4-
*
5-
* This library implements a command line interface. The experience is similar to the windows
6-
* command prompt. This library can invoke functions when a specific string is received, in this
7-
* example we register 2 commands that can be executed by typing their names on the arduino serial
8-
* monitor (using the hardware UART).
9-
*
10-
* The "shell" library is designed to be independent of the communication channel, this means
11-
* that it can be used with serial, softSerial and even TCP connections. For this reason the
12-
* shell library requires 2 pointers to functions to read and write characters to and from the
13-
* physical transmission media.
14-
*
15-
* Arguments can be passed to the programs that are invoked by the command line and parsed by
16-
* standard string parsing functions, or you can write your own functions. The arguments
17-
* are passed as pointers to characters (null terminated strings) in a similar way that you
18-
* would receive them on any command line tool written in C. Each parameter is separated by
19-
* a "space" character after the command name.
2+
* GeekFactory - "Construye tu propia tecnologia"
3+
* Distribucion de materiales para el desarrollo e innovacion tecnologica
4+
* www.geekfactory.mx
5+
*
6+
* Ejemplo de libreria Shell. En este ejemplo se ilustra la recepcion y manejo
7+
* de los parametros recibidos por el comando. Se imprimen cada uno de los
8+
* argumentos recibidos así como la longitud de cada una de las cadenas.
9+
*
10+
* Example for Shell library. This example shows the reception and handling of
11+
* arguments received by command programs. The arguments are printed along with
12+
* the string lenghts.
2013
*/
2114

2215
#include <Shell.h>
@@ -80,7 +73,7 @@ int shell_reader(char * data)
8073

8174
/**
8275
* Function to write data to serial port
83-
* Functions to write to physical media should use this prototype
76+
* Functions to write to physical media should use this prototype:
8477
* void my_writer_function(char data)
8578
*/
8679
void shell_writer(char data)

examples/Shell_IO_Control/Shell_IO_Control.ino

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
/**
2-
* SIMPLE EXAMPLE OF COMMAND SHELL LIBRARY
3-
*
4-
* This library implements a command line interface. The experience is similar to the windows
5-
* command prompt. This library can invoke functions when a specific string is received, in this
6-
* example we register 2 commands that can be executed by typing their names on the arduino serial
7-
* monitor (using the hardware UART).
8-
*
9-
* The "shell" library is designed to be independent of the communication channel, this means
10-
* that it can be used with serial, softSerial and even TCP connections. For this reason the
11-
* shell library requires 2 pointers to functions to read and write characters to and from the
12-
* physical transmission media.
13-
*
14-
* Arguments can be passed to the programs that are invoked by the command line and parsed by
15-
* standard string parsing functions, or you can write your own functions. The arguments
16-
* are passed as pointers to characters (null terminated strings) in a similar way that you
17-
* would receive them on any command line tool written in C. Each parameter is separated by
18-
* a "space" character after the command name.
19-
*/
20-
211
#include <Shell.h>
222

233
void setup()
@@ -73,9 +53,9 @@ int command_ioctrl(int argc, char** argv)
7353
shell_println("Arguments in square brackets [ ] are mandatory; arguments in curly brackets { } are optional");
7454
shell_println("");
7555
shell_println("AVAILABLE SWITCHES:");
76-
shell_println(" -p [PIN NUMBER] -> \"Sets\" the pin to perform other operations on the pin");
77-
shell_println(" -m [INPUT / OUTPUT] -> \"Configures\" PIN mode as input or output");
78-
shell_println(" -w [LOW / HIGH] -> \"Writes\" a digital output value: LOW or HIGH state");
56+
shell_println(" -p [PIN_NUMBER] -> \"Sets\" the pin (PIN_NUMBER) to perform other operations on the pin");
57+
shell_println(" -m [INPUT|OUTPUT] -> \"Configures\" PIN mode as INPUT or OUTPUT");
58+
shell_println(" -w [LOW|HIGH] -> \"Writes\" a digital output value LOW or HIGH");
7959
shell_println(" -r -> \"Reads\" the state of a digital input or output");
8060
shell_println(" -help -> Shows this help message");
8161
shell_println("");

examples/Shell_Minimum/Shell_Minimum.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/**
2-
* SIMPLE EXAMPLE OF COMMAND SHELL LIBRARY
3-
*
4-
* Minimal program to setup the library and read / write to serial port
2+
* GeekFactory - "Construye tu propia tecnologia"
3+
* Distribucion de materiales para el desarrollo e innovacion tecnologica
4+
* www.geekfactory.mx
5+
*
6+
* Ejemplo de libreria Shell. Este ejemplo representa la configuracion minima
7+
* requerida para implementar la funcionalidad de interfaz de comandos.
8+
*
9+
* Example for Shell library. This example shows the minimum setup needed to
10+
* implement a command line interface.
511
*/
612

713
#include <Shell.h>
@@ -53,12 +59,11 @@ int shell_reader(char * data)
5359

5460
/**
5561
* Function to write data to serial port
56-
* Functions to write to physical media should use this prototype
62+
* Functions to write to physical media should use this prototype:
5763
* void my_writer_function(char data)
5864
*/
5965
void shell_writer(char data)
6066
{
6167
// Wrapper for Serial.write() method
6268
Serial.write(data);
6369
}
64-
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* GeekFactory - "Construye tu propia tecnologia"
3+
* Distribucion de materiales para el desarrollo e innovacion tecnologica
4+
* www.geekfactory.mx
5+
*
6+
* Ejemplo de libreria Shell. Este ejemplo permite controlar el color mostrado
7+
* en un led RGB conectado a los pines PWM mediante comandos de texto. El programa
8+
* admite 3 parametros de 0 a 255 que representan la intensidad de cada led (RGB).
9+
*
10+
* Example for Shell library. This example controls the color displayed on the RGB
11+
* led connected to PWM pins using text commands. The program accepts 3 parameters
12+
* in a range from 0 to 255 that represent the intensity of each led.
13+
*/
14+
15+
#include <Shell.h>
16+
17+
void setup()
18+
{
19+
// Prepare serial communication
20+
Serial.begin(9600);
21+
// Wait after reset or power on...
22+
delay(1000);
23+
24+
// Pins to connect RGB led (PWM outputs)
25+
pinMode(3,OUTPUT);
26+
pinMode(5,OUTPUT);
27+
pinMode(6,OUTPUT);
28+
29+
// Initialize command line interface (CLI)
30+
// We pass the function pointers to the read and write functions that we implement below
31+
// We can also pass a char pointer to display a custom start message
32+
shell_init(shell_reader, shell_writer, 0);
33+
34+
// Add commands to the shell
35+
shell_register(command_rgbled, "rgbled");
36+
}
37+
38+
void loop()
39+
{
40+
// This should always be called to process user input
41+
shell_task();
42+
}
43+
44+
/**
45+
* This function implements the rgbled command and parses the required args
46+
* Type: rgbled 255 255 255 to set led to maximum brigtness
47+
* Type: rgbled 0 0 0 to set led to minimum brightess
48+
*/
49+
int command_rgbled(int argc, char** argv)
50+
{
51+
// Variables that store parameter values
52+
uint8_t val_R, val_G, val_B;
53+
54+
// Parse RGB values and write to PWM pins
55+
val_R = strtol(argv[1],NULL,0);
56+
analogWrite(3, val_R);
57+
58+
val_G = strtol(argv[2],NULL,0);
59+
analogWrite(5, val_G);
60+
61+
val_B = strtol(argv[3],NULL,0);
62+
analogWrite(6, val_B);
63+
64+
// Print the received falues to the terminal screen
65+
shell_printf("#RGB-COMPONENTS:%d,%d,%d\r\n", val_R, val_G, val_B);
66+
67+
// Return success code
68+
return SHELL_RET_SUCCESS;
69+
}
70+
71+
/**
72+
* Function to read data from serial port
73+
* Functions to read from physical media should use this prototype:
74+
* int my_reader_function(char * data)
75+
*/
76+
int shell_reader(char * data)
77+
{
78+
// Wrapper for Serial.read() method
79+
if (Serial.available()) {
80+
*data = Serial.read();
81+
return 1;
82+
}
83+
return 0;
84+
}
85+
86+
/**
87+
* Function to write data to serial port
88+
* Functions to write to physical media should use this prototype:
89+
* void my_writer_function(char data)
90+
*/
91+
void shell_writer(char data)
92+
{
93+
// Wrapper for Serial.write() method
94+
Serial.write(data);
95+
}
96+
97+

0 commit comments

Comments
 (0)