# SimpleCLI
<p align="center"><img alt="SimpleCLI Logo" src="img/simplecli.gif" width="150"></p>
<p align="center">
<b>A Command Line Interface Library for Arduino!</b><br>
Add commands to your project without hassle.<br>
<br>
<a href="https://www.ardu-badge.com/SimpleCLI" target="_blank"><img alt="Ardu Badge for SimpleCLI Library" src="https://www.ardu-badge.com/badge/SimpleCLI.svg"></a><br>
<br>
馃惁 <a href="https://twitter.com/spacehuhn">Twitter</a>
| 馃摵 <a href="https://www.youtube.com/spacehuhn">YouTube</a>
| 馃實 <a href="https://spacehuhn.io">spacehuhn.io</a><br>
<br>
Support this project and become a patron on <a href="https://patreon.com/spacehuhn">patreon.com/spacehuhn</a>.<br>
Also available: <a href="https://www.tindie.com/products/Spacehuhn/spacehuhn-stickers/">Stickers</a></b>!
</p>
![Cowsay command example](img/cowsay.gif)
## Projects
A list of projects that make use of this library:
- [The Chicken Man Game](https://github.com/skickar/ChickenManGame)
- [Control ESP32 with Command Line Interface Over the Internet](https://www.hackster.io/donowak/control-esp32-with-command-line-interface-over-the-internet-fa9634)
- [WiFiDuck](https://github.com/spacehuhn/WiFiDuck)
- [ESP8266 Deauther V3](https://github.com/SpacehuhnTech/esp8266_deauther/tree/v3)
## Overview
- [About](#about)
- [Supported Devices](#supported-devices)
- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Include Library](#include-library)
- [Create SimpleCLI instance](#create-simplecli-instance)
- [Adding Commands](#adding-commands)
- [Adding Commands with callback](#adding-commands-with-callback)
- [Adding Arguments](#adding-arguments)
- [Templates](#templates)
- [Parsing Input](#parsing-input)
- [Reacting on Commands](#reacting-on-commands)
- [Reacting on Errors](#reacting-on-errors)
- [Classes & Methods](#classes--methods)
- [SimpleCLI](#simplecli)
- [CommandType](#commandtype)
- [Command](#command)
- [CommandErrorType](#commanderrortype)
- [CommandError](#commanderror)
- [ArgumentType](#argumenttype)
- [Argument](#argument)
- [License](#license)
## About
The goal of this library is to control your Arduino projects using commands similar to the Linux CLI.
Because parsing and validating strings in C/C++ can be quite a pain, this library aims to simplify the process as much as possible.
## Supported Devices
Strings take up a good amount of memory, so **it's strongly recommended to chose a development board with at least 32 KB RAM**.
It doesn't make much sense to run this library on an Uno or Nano, because it will quickly take up a most of the resources.
Here's a list of tested hardware (feel free to contribute by making a Pull-Request):
| Chipset | Board(s) | Flash | RAM | Support |
| ------- | -------- | ----- | --- | ------- |
| ATtiny85 | Digispark | 8 KB | 512 Byte | No! (Does not compile C++11) |
| ATmega328P | Arduino Nano, Arduino Uno | 32 KB | 2 KB | Works for small projects |
| ATmega32u4 | Arduino Leonardo, Pro Micro | 32 KB | 2,560 Byte | Works for small projects |
| ATSAMD21G18 | Arduino MKR WiFi 1010 | 256 KB | 32 KB | Yes! |
| ATSAMD51G19 | Adafruit ItsyBitsy M4 Express | 512 KB | 192 KB | Yes! |
| ESP8266 | NodeMCU, D1 Mini | 512 KB - 16 MB | 80 KB | Yes! |
| ESP32 | DSTIKE D-duino-32 | 1 MB - 16 MB |520 KB | Yes! |
*Some flash and RAM values depend on the development board or module being used.*
## Installation
1) Click [Download Zip](https://github.com/spacehuhn/SimpleCLI/archive/master.zip) to download the source code from GitHub.
2) Unzip and rename the Folder name to "SimpleCLI".
3) Paste it in your library folder (usually located somewhere at documents/Arduino/libraries).
4) Restart the Arduino IDE.
## Usage
[![SimpleCLI YouTube Tutorial](https://img.youtube.com/vi/UyW-wICdnKo/0.jpg)](https://www.youtube.com/watch?v=UyW-wICdnKo)
### Examples
Please check out the [example sketches](https://github.com/spacehuhn/SimpleCLI/tree/master/examples/), it's the quickest way to understand how this library works.
The following sections are for reference.
![Ping with arguments command example](img/ping.gif)
### Include Library
```c++
#include <SimpleCLI.h>
```
### Create SimpleCLI instance
```c++
SimpleCLI cli;
SimpleCLI cli(COMMAND_QUEUE_SIZE, ERROR_QUEUE_SIZE);
```
`COMMAND_QUEUE_SIZE` and `ERROR_QUEUE_SIZE` are `int`s set to 10 commands and 10 errors by default.
The oldest command or error will be deleted automatically if the queue gets full.
You can most likely ignore the queue sizes, as those are just a safety mechanism and won't be important for most use cases.
### Adding Commands
Command names should only contain upper-, lowercase letters and numbers!
Recommended are names with only lowercase letters and no numbers.
```c++
// Normal command with a defined number of arguments
// For example: echo -str "Hello" -n 3
Command myCommand = cli.addCommand("myCommandName");
Command myCommand = cli.addCmd("myCmdName");
// Single-Argument-Command that saves everything after the command name in the first argument
// For example: echo this will be a single string -even with hyphen and in "quotes"
// => "this will be a single string -even with hyphen and in "quotes\"" will be the argument value
Command mySingleArgumentCommand = cli.addSingleArgumentCommand("mySingleArgumentCommandName");
Command mySingleArgCmd = cli.addSingleArgCmd("mySingleArgCmdName");
// Boundless-Command that accepts any amount of arguments separated by spaces
// For example: sum 1 2 3
// => "1", "2", "3" will the argument values
Command myBoundlessCommand = cli.addBoundlessCommand("myBoundlessCommandName");
Command myBoundlessCmd = cli.addBoundlessCmd("myBoundlessCmdName");
```
### Adding Commands with callback
Sometimes it's useful to give the command a callback function that will be executed automatically when the command was entered.
You must define these callback functions as a global void function with a `cmd` pointer as shown here:
```c++
void myCallback(cmd* commandPointer) {
Command cmd(commandPointer); // Create wrapper class instance for the pointer
// ..
}
```
Now you can create a command and pass it the function pointer:
```c++
Command myCommand = cli.addCommand("myCommandName", myCallback);
Command myCommand = cli.addBoundlessCommand("myCommandName", myCallback);
Command myCommand = cli.addSingleArgumentCommand("myCommandName", myCallback);
Command myCommand = cli.addCmd("myCommandName", myCallback);
Command myCommand = cli.addBoundlessCmd("myCommandName", myCallback);
Command myCommand = cli.addSingleArgCmd("myCommandName", myCallback);
```
### Adding Arguments
Keep in mind that you can only add arguments to `Command`s and **not** to `SingleArgumentCommand`s and `BoundlessCommand`s.
```c++
// myCommandName -argumentName "argumentValue"
Argument myArg = myCommand.addArgument("argumentName");
Argument myArg = myCommand.addArg("argumentName");
// Giving the argument a default value, means that the user does not have to specify the argument
// myCommandName
// myCommandName -argumentName "argumentValue"
Argument myArg = myCommand.addArgument("argumentName", "DefaultValue");
Argument myArg = myCommand.addArg("argumentName", "DefaultValue");
// Positional arguments have a certain position and do not have to be named
// myCommandName "argumentValue"
// myCommandName -argumentName "argumentValue"
Argument myArg = myCommand.addPositionalArgument("argumentName");
Argument myArg = myCommand.addPosArg("argumentName");
// Those can also have default values
// myCommandName
// myCommandName "argumentValue"
// myCommandName -argumentName "argumentValue"
Argument myArg = myCommand.addPositionalArgument("argumentName", "DefaultValue");
Argument myArg = myCommand.addPosArg("argumentName", "DefaultValue");
// Flag arguments can either be specified (set) or not, but they don't accept any value
// myCommandName
// myCommandName -argumentName
Argument myAr
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
嵌入式优质项目,资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目。 本人单片机开发经验充足,深耕嵌入式领域,有任何使用问题欢迎随时与我联系,我会及时为你解惑,提供帮助。 【资源内容】:包含完整工程文件+说明,项目具体内容可查看下方的资源详情。 【附带帮助】: 若还需要嵌入式物联网单片机相关领域开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步。 【本人专注嵌入式领域】: 有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为你提供帮助,CSDN博客端可私信,为你解惑,欢迎交流。 【适合场景】: 相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可以基于此项目进行扩展来开发出更多功能
资源推荐
资源详情
资源评论
收起资源包目录
基于esp32-pico-d4设计的迷你开发板.zip(皆可应用在毕设/课设/大作业/实训/竞赛/项目开发) (236个子文件)
u8g2_fonts.c 28.58MB
u8x8_fonts.c 1.53MB
u8g2_d_setup.c 278KB
u8x8_d_st75256.c 57KB
u8x8_d_st7565.c 47KB
u8x8_d_ssd1327.c 33KB
u8g2_font.c 33KB
u8x8_d_st7567.c 32KB
u8x8_d_uc1611.c 26KB
u8g2_d_memory.c 26KB
u8x8_d_ssd1607_200x200.c 21KB
u8x8_cad.c 21KB
u8x8_d_t6963.c 19KB
u8x8_d_uc1608.c 19KB
u8x8_d_ssd1320.c 19KB
u8x8_d_sh1107.c 18KB
u8x8_d_ssd1306_128x64_noname.c 18KB
u8x8_byte.c 17KB
u8x8_d_ssd1322.c 17KB
u8x8_d_il3820_296x128.c 17KB
u8x8_d_max7219.c 16KB
u8x8_d_ssd1325.c 16KB
u8x8_d_ssd1305.c 16KB
u8x8_d_lc7981.c 16KB
u8x8_d_st7528.c 14KB
u8x8_d_ssd1606_172x72.c 13KB
u8x8_d_sed1330.c 13KB
u8x8_8x8.c 12KB
u8x8_d_ssd1306_128x32.c 12KB
u8x8_d_ld7032_60x32.c 11KB
u8g2_setup.c 11KB
u8x8_d_ks0108.c 11KB
u8x8_d_ssd1318.c 11KB
u8g2_circle.c 10KB
u8x8_d_ssd1309.c 10KB
u8x8_d_ssd1306_64x32.c 10KB
u8x8_d_ssd1329.c 10KB
u8x8_d_uc1617.c 10KB
u8x8_d_ssd1306_72x40.c 9KB
u8x8_d_ssd1326.c 9KB
u8x8_d_st75320.c 9KB
u8x8_d_ssd1306_128x80_noname.c 9KB
u8g2_ll_hvline.c 9KB
u8x8_d_s1d15e06.c 9KB
u8x8_d_st7586s_erc240160.c 9KB
u8x8_d_uc1610.c 9KB
u8x8_d_sh1122.c 9KB
u8x8_d_st7586s_s028hn118a.c 9KB
u8x8_d_st7920.c 8KB
u8x8_d_ssd1317.c 8KB
u8x8_d_s1d15721.c 8KB
u8x8_d_sh1106_72x40.c 8KB
u8x8_d_sh1106_64x32.c 8KB
u8x8_d_st7588.c 8KB
u8x8_d_ssd1316.c 8KB
u8x8_d_st7571.c 8KB
u8x8_d_uc1604.c 8KB
u8x8_d_st7586s_ymc240160.c 8KB
u8x8_d_ssd1306_64x48.c 8KB
u8x8_d_ls013b7dh03.c 8KB
u8x8_d_ssd1306_96x16.c 8KB
u8x8_d_ssd1306_48x64.c 8KB
u8x8_d_sh1108.c 8KB
u8x8_d_ssd1306_2040x16.c 8KB
u8g2_selection_list.c 7KB
u8x8_d_uc1638.c 7KB
u8x8_d_uc1701_dogs102.c 7KB
u8x8_d_uc1701_mini12864.c 7KB
u8x8_d_ist3020.c 7KB
cmd.c 7KB
u8x8_d_st7511.c 7KB
u8g2_polygon.c 7KB
u8x8_d_ist7920.c 7KB
u8g2_hvline.c 7KB
u8x8_d_sbn1661.c 7KB
u8x8_d_uc1601.c 7KB
u8g2_buffer.c 7KB
u8x8_d_pcf8814_hx1230.c 7KB
u8x8_d_pcf8812.c 6KB
u8log.c 6KB
u8x8_d_a2printer.c 6KB
u8x8_capture.c 6KB
u8x8_d_pcd8544_84x48.c 6KB
u8x8_debounce.c 5KB
u8g2_message.c 5KB
u8g2_bitmap.c 5KB
u8x8_display.c 5KB
parser.c 5KB
u8x8_selection_list.c 5KB
u8x8_setup.c 5KB
arg.c 5KB
u8g2_box.c 5KB
u8x8_message.c 4KB
u8g2_intersection.c 4KB
u8g2_input_value.c 4KB
u8x8_string.c 4KB
u8x8_input_value.c 4KB
u8log_u8g2.c 3KB
cmd_error.c 3KB
comparator.c 3KB
共 236 条
- 1
- 2
- 3
资源评论
阿齐Archie
- 粉丝: 1w+
- 资源: 2303
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功