Skip to content

Commit e00b8ed

Browse files
committed
Added sources.
1 parent a21e61b commit e00b8ed

8 files changed

Lines changed: 853 additions & 1 deletion

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
1-
# minbasecli
1+
# MinBaseCLI
2+
23
A minimal Command Line Interface C++ library implementation with HAL emphasis to be used in different kind of devices and frameworks.
4+
5+
## Supported Devices & Frameworks
6+
7+
Currently, just Arduino devices are compatible, however is simply to add support to other devices and frameworks.
8+
9+
## Adding new Device Support
10+
11+
To add a new device or framework support to library, yo just need to write the low level functionalities to control interface of the CLI in the **hal_*()** private methods (*hal_iface_available(), hal_iface_read(), hal_iface_print(), etc.*).
12+
13+
```cpp
14+
15+
// ...
16+
17+
// Device/Framework Libraries
18+
#if defined(ARDUINO)
19+
#include <Arduino.h>
20+
#elif defined(ESP_IDF)
21+
// Unimplemented
22+
#elif defined(SAM_ASF)
23+
// Unimplemented
24+
#elif defined(__AVR__)
25+
// Unimplemented
26+
#endif
27+
28+
// ...
29+
30+
uint8_t MINBASECLI::hal_iface_read(void)
31+
{
32+
// Do nothing if interface has not been initialized
33+
if(iface_is_not_initialized())
34+
return 0;
35+
36+
#if defined(ARDUINO)
37+
#if defined(USBCON) // Arduinos: Leonardo, Micro, MKR, etc
38+
Serial_* _Serial = (Serial_*)this->iface;
39+
#else // Arduinos: UNO, MEGA, Nano, etc
40+
HardwareSerial* _Serial = (HardwareSerial*)this->iface;
41+
#endif
42+
return _Serial->read();
43+
#elif defined(ESP_IDF)
44+
// Unimplemented
45+
#elif defined(SAM_ASF)
46+
// Unimplemented
47+
#elif defined(__AVR__)
48+
// Unimplemented
49+
#endif
50+
51+
return 0;
52+
}
53+
```
54+
55+
## Donation
56+
57+
[![paypal](https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif)](https://paypal.me/josrios)
58+
59+
Do you like this project?
60+
61+
Please, considere making a donation.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/**************************************************************************************************/
2+
// File: basic_usage.ino
3+
// Description: MINBASECLI library basic usage example
4+
// Date: 06 jan. 2021
5+
// Version: 1.0.0
6+
/**************************************************************************************************/
7+
/**
8+
* @file basic_usage.ino
9+
* @author Jose Miguel Rios Rubio <jrios.github@gmail.com>
10+
* @date 17-01-2021
11+
* @version 1.0.0
12+
*
13+
* @section DESCRIPTION
14+
*
15+
* SIMPLECLI library basic usage example.
16+
*
17+
* @section LICENSE
18+
*
19+
* Copyright (c) 2021 Jose Miguel Rios Rubio. All right reserved.
20+
*
21+
* This library is free software; you can redistribute it and/or
22+
* modify it under the terms of the GNU Lesser General Public
23+
* License as published by the Free Software Foundation; either
24+
* version 2.1 of the License, or (at your option) any later version.
25+
*
26+
* This library is distributed in the hope that it will be useful,
27+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
28+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29+
* Lesser General Public License for more details.
30+
*
31+
* You should have received a copy of the GNU Lesser General Public
32+
* License along with this library; if not, write to the Free Software
33+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34+
*/
35+
36+
/*****************************************************************************/
37+
38+
/* Libraries */
39+
40+
// Device Framework libraries
41+
#include <Arduino.h>
42+
43+
// Custom libraries
44+
#include <minbasecli.h>
45+
46+
/*****************************************************************************/
47+
48+
/* Defines, Macros, Constants and Types */
49+
50+
// Serial Speed
51+
#define SERIAL_BAUDS 115200
52+
53+
// LED to be controlled thorugh CLI command
54+
#define COMMAND_LED 13
55+
56+
// Current Firmware Version
57+
#define FW_VER "1.0.0"
58+
59+
/*****************************************************************************/
60+
61+
/* Global Elements */
62+
63+
// Command Line Interface
64+
MINBASECLI Cli;
65+
66+
/*****************************************************************************/
67+
68+
/* Setup & Loop */
69+
70+
void setup()
71+
{
72+
// Serial Init
73+
Serial.begin(SERIAL_BAUDS);
74+
75+
// LED Init
76+
digitalWrite(COMMAND_LED, LOW);
77+
pinMode(COMMAND_LED, OUTPUT);
78+
79+
// CLI init to use Serial as interface
80+
Cli.setup(&Serial);
81+
}
82+
83+
void loop()
84+
{
85+
t_cli_result cli_read;
86+
87+
// If any command was received
88+
if(Cli.manage(&cli_read))
89+
{
90+
// Show read result element
91+
Serial.print("Command received: "); Serial.println(cli_read.cmd);
92+
Serial.print("Number of arguments: "); Serial.println(cli_read.argc);
93+
for(uint8_t i = 0; i < cli_read.argc; i++)
94+
{
95+
Serial.print(" Argument "); Serial.print(i);
96+
Serial.print(":"); Serial.println(cli_read.argv[i]);
97+
}
98+
Serial.println();
99+
100+
// Handle Commands
101+
if(strcmp(cli_read.cmd, "help") == 0)
102+
{
103+
Serial.println("Available Commands:");
104+
Serial.println(" help - Current info.");
105+
Serial.println(" led [on/off] - Turn LED ON or OFF");
106+
Serial.println(" version - Shows current firmware version");
107+
}
108+
else if(strcmp(cli_read.cmd, "led") == 0)
109+
{
110+
bool invalid_argv = false;
111+
char* led_mode = NULL;
112+
113+
// Check for argument
114+
if(cli_read.argc == 0)
115+
invalid_argv = true;
116+
else
117+
{
118+
led_mode = cli_read.argv[0];
119+
if(strcmp(led_mode, "on") == 0)
120+
{
121+
Serial.println("Turning LED ON.");
122+
digitalWrite(COMMAND_LED, HIGH);
123+
}
124+
else if(strcmp(led_mode, "off") == 0)
125+
{
126+
Serial.println("Turning LED OFF.");
127+
digitalWrite(COMMAND_LED, LOW);
128+
}
129+
else
130+
invalid_argv = true;
131+
}
132+
133+
if(invalid_argv)
134+
Serial.println("led command needs \"on\" or \"off\" arg.");
135+
}
136+
else if(strcmp(cli_read.cmd, "version") == 0)
137+
{
138+
Serial.print("Fw Version: ");
139+
Serial.println(FW_VER);
140+
}
141+
// ...
142+
else
143+
Serial.println("Unkown command.");
144+
Serial.println();
145+
}
146+
}

keywords.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
###########################################
2+
# Arduino Syntax Coloring Map
3+
###########################################
4+
5+
###########################################
6+
# Datatypes (KEYWORD1)
7+
###########################################
8+
9+
MINBASECLI KEYWORD1
10+
11+
###########################################
12+
# Methods and Functions (KEYWORD2)
13+
###########################################
14+
15+
setup KEYWORD2
16+
manage KEYWORD2
17+
get_received_bytes KEYWORD2

library.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "minbasecli",
3+
"keywords": "hal, arduino, espidf, avr, sam, microchip, stm, esp8266, esp32",
4+
"description": "A minimal Command Line Interface C++ library implementation with HAL emphasis to be used in different kind of devices and frameworks.",
5+
"authors": {
6+
"name": "JRios",
7+
"url": "https://github.com/J-Rios"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/J-Rios/minbasecli"
12+
},
13+
"version": "1.0.0",
14+
"frameworks": "*",
15+
"platforms": "*"
16+
}

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=minbasecli
2+
version=1.0.0
3+
author=JRios
4+
maintainer=JRios <jrios.github@gmail.com>
5+
sentence=A minimal Command Line Interface C++ library implementation with HAL emphasis to be used in different kind of devices and frameworks.
6+
paragraph=A minimal Command Line Interface C++ library implementation with HAL emphasis to be used in different kind of devices and frameworks.
7+
category=Other
8+
url=https://github.com/J-Rios/minbasecli
9+
architectures=*

0 commit comments

Comments
 (0)