Skip to content

Commit 7c5214a

Browse files
committed
Minor updates for 1.0.0 release
1 parent 54e3e01 commit 7c5214a

File tree

5 files changed

+799
-18
lines changed

5 files changed

+799
-18
lines changed

README.md

Lines changed: 119 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The programs (functions) that implement the functionality of each command should
3535
int command_func(int argc, char ** argv);
3636
```
3737
38-
## Basic library example using arduino
38+
## Basic library example using arduino ##
3939
4040
```cpp
4141
/**
@@ -156,13 +156,13 @@ The library is meant to work in other CPU architectures where a C compiler is av
156156

157157

158158

159-
#Librería de linea de comandos para Arduino y otros microcontroladores.#
159+
# Librería Shell de GeekFactory #
160160

161-
Esta librería permite **controlar nuestros programas y dispositivos con simples comandos de texto** de manera similar a la terminal en Mac OSX o linux y la linea de comandos de Windows. Los comandos pueden transmitirse al microcontrolador mediante un puerto serie, un socket TCP/IP o una conexión USB CDC.
161+
Esta librería permite **controlar nuestros programas y dispositivos con simples comandos de texto** de manera similar a la terminal en Mac OSX o linux y la linea de comandos de Windows. Los comandos pueden transmitirse al microcontrolador mediante un puerto serie, un socket TCP/IP o una conexión USB CDC. **Esta librería está escrita en C puro para permitir que funcione en microcontroladores/compiladores que no soportan C++**.
162162

163-
### Uso básico de la librería
163+
## Uso básico de la librería ##
164164

165-
Para utilizar la librería debemos llamar a la función de inicialización que le dice a la librería que funciones debe usar para leer y escribir sobre el medio (serial, TCP/IP, etc.)
165+
Para utilizar la librería debemos llamar a la función de inicialización que le dice a la librería que funciones debe usar para leer y escribir sobre el medio (serial, TCP/IP, etc.). El siguiente código preparará la librería para su uso y le indica que use las funciones shell_reader() para leer bytes desde el puerto serie y la función shell_writter() para escribir bytes al serial.
166166

167167
```c
168168
// Initialize command line interface (CLI)
@@ -186,22 +186,127 @@ Finalmente, dentro del ciclo principal de cada aplicación, el programador debe
186186
shell_task();
187187
```
188188

189-
Los programas (funciones) que implementan cada uno de los comandos se deben escribir con el prototipo estándar de C y reciben los parámetros para realizar su función de manera similar a una utilidad de linea de comandos.
189+
Los programas (funciones) que implementan cada uno de los comandos se deben escribir con el prototipo estándar de C y reciben los parámetros para realizar su función de manera similar a una utilidad de linea de comandos programada para una PC.
190190

191191
```c
192192
int command_func(int argc, char ** argv);
193193
```
194194
195-
### Objetivos de este proyecto
195+
## Ejemplo básico de la librería utilizando arduino ##
196196
197-
Buscamos que la librería cumpla con los siguientes puntos:
197+
```cpp
198+
/**
199+
* GeekFactory - "Construye tu propia tecnologia"
200+
* Distribucion de materiales para el desarrollo e innovacion tecnologica
201+
* www.geekfactory.mx
202+
*
203+
* Ejemplo de libreria Shell. Este ejemplo representa la configuracion minima
204+
* requerida para implementar la funcionalidad de interfaz de comandos. En esta
205+
* ocasion registramos 2 comandos y enviamos texto como respuesta a cada uno.
206+
*
207+
* Example for Shell library. This example shows the minimum setup needed to
208+
* implement a command line interface. This time we register 2 commands and we
209+
* send text as response for each command.
210+
*/
211+
212+
#include <Shell.h>
213+
214+
void setup()
215+
{
216+
// Prepare serial communication
217+
Serial.begin(9600);
218+
// Wait after reset or power on...
219+
delay(1000);
220+
221+
// Initialize command line interface (CLI)
222+
// We pass the function pointers to the read and write functions that we implement below
223+
// We can also pass a char pointer to display a custom start message
224+
shell_init(shell_reader, shell_writer, 0);
198225
199-
* El código debe ser portable a otras plataformas
200-
* la librería debe ser compacta
201-
* Debe facilitar para agregar comandos
226+
// Add commands to the shell
227+
shell_register(command_mycommand, "mycommand");
228+
shell_register(command_othercommand, "othercommand");
229+
}
202230
203-
###Dispositivos Soportados
231+
void loop()
232+
{
233+
// This should always be called to process user input
234+
shell_task();
235+
}
236+
237+
/**
238+
* Test commands: The commands should always use this function prototype.
239+
* They receive 2 parameters: The total count of arguments (argc) and a pointer
240+
* to the begining of each one of the null-terminated argument strings.
241+
*
242+
* In this example we ignore the parameters passed to the functions
243+
*/
244+
int command_mycommand(int argc, char** argv)
245+
{
246+
shell_println("Running \"mycommand\" now");
247+
shell_println("Exit...");
248+
return SHELL_RET_SUCCESS;
249+
}
250+
251+
int command_othercommand(int argc, char** argv)
252+
{
253+
shell_println("Running \"othercommand\" now");
254+
shell_println("Exit...");
255+
return SHELL_RET_SUCCESS;
256+
}
257+
258+
/**
259+
* Function to read data from serial port
260+
* Functions to read from physical media should use this prototype:
261+
* int my_reader_function(char * data)
262+
*/
263+
int shell_reader(char * data)
264+
{
265+
// Wrapper for Serial.read() method
266+
if (Serial.available()) {
267+
*data = Serial.read();
268+
return 1;
269+
}
270+
return 0;
271+
}
272+
273+
/**
274+
* Function to write data to serial port
275+
* Functions to write to physical media should use this prototype:
276+
* void my_writer_function(char data)
277+
*/
278+
void shell_writer(char data)
279+
{
280+
// Wrapper for Serial.write() method
281+
Serial.write(data);
282+
}
283+
```
284+
285+
## Objetivos del proyecto ##
286+
287+
Nuestra librería debe cumplir los siguientes objetivos:
288+
289+
* El código debe ser fácilmente portable a otras plataformas
290+
* La liobrería debe ser compacta
291+
* Debe ser fácil agregar nuevos comandos
292+
293+
294+
## Dispositivos soportados ##
295+
296+
La librería fue desarrollada/probada en las siguientes tarjetas:
204297

205-
* Microcontroladores PIC (PIC16F, PIC18F, PIC24F, dsPIC)
206298
* Arduino UNO R3
207-
* Prácticamente cualquier dispositivo que tenga un compilador de C respetable
299+
* Arduino Mega 2560 R3
300+
* Pruebas básicas en tarjetas con ESP8266
301+
302+
La librería fue probada en los siguientes microcontroladores PIC usando MPLAB X:
303+
304+
* PIC24FJ64GA002
305+
* PIC24HJ128GA504
306+
307+
La librería GeekFactory Shell esta diseñada para trabajar en otras arquitecturas de CPU donde exista un compilador de C, por favor comentanos sobre tu experiencia si la pruebas en otras plataformas.
308+
309+
## Contáctame ##
310+
311+
* Contacto para cualquier tema referente a esta librería: ruben en geekfactory.mx
312+
* Revisa nuestro sitio web: https://www.geekfactory.mx

Shell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ bool shell_init(shell_reader_t reader, shell_writer_t writer, char * msg)
9393
shell_println(msg);
9494
else
9595
#ifdef ARDUINO
96-
shell_println_pm(PSTR("uShell 1.0"));
96+
shell_println_pm(PSTR(SHELL_VERSION_STRING));
9797
#else
98-
shell_println((const char *) "uShell 1.0");
98+
shell_println((const char *) SHELL_VERSION_STRING);
9999
#endif
100100
shell_prompt();
101101
return true;

Shell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
#define SHELL_RET_FAILURE 1
8888
#define SHELL_RET_IOPENDING -1
8989

90+
#define SHELL_VERSION_STRING "uShell 1.0.0"
91+
9092
/*-------------------------------------------------------------*/
9193
/* Typedefs enums & structs */
9294
/*-------------------------------------------------------------*/

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name=GeekFactory Shell Library
22
version=1.0.0
33
author=www.geekfactory.mx
44
maintainer=Jesus Ruben Santa Anna Zamudio
5-
sentence=Library to create a simple Command Line Interface (CLI)
6-
paragraph=This library allows the user to control the device using simple text commands
5+
sentence=Library to create a simple Command Line Interface (CLI).
6+
paragraph=This library allows the user to control the device using simple text commands, the library is written in pure C so it can be easily ported to other microcontrollers.
77
category=Communication
88
url=https://github.com/geekfactory/Shell
99
architectures=*

0 commit comments

Comments
 (0)