Commander-API  V2.1.0
Simple Command Parser
Loading...
Searching...
No Matches
Commander-API-Commands.hpp
Go to the documentation of this file.
1/*
2 * Created on Oct. 01 2022
3 *
4 * Copyright (c) 2020 - Daniel Hajnal
5 * hajnal.daniel96@gmail.com
6 * This file is part of the Commander-API project.
7 * Modified 2022.10.04
8*/
9
10/*
11MIT License
12
13Copyright (c) 2020 Daniel Hajnal
14
15Permission is hereby granted, free of charge, to any person obtaining a copy
16of this software and associated documentation files (the "Software"), to deal
17in the Software without restriction, including without limitation the rights
18to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19copies of the Software, and to permit persons to whom the Software is
20furnished to do so, subject to the following conditions:
21
22The above copyright notice and this permission notice shall be included in all
23copies or substantial portions of the Software.
24
25THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31SOFTWARE.
32*/
33
35#ifdef ARDUINO
36#include "Arduino.h"
37#include "Wire.h"
38#endif
39
40#include <math.h>
41
42#ifdef __AVR__
43 #include <avr/wdt.h>
44#endif
45
46#ifdef ESP32
47
48 #include "time.h"
49
50#endif
51
52#include "Commander-API.hpp"
53
54//-------- System functions --------//
55
56#define API_ELEMENT_REBOOT apiElement( "reboot", "Reboots the device.", commander_reboot_func )
57#ifdef __AVR__
58 #define API_ELEMENT_P_REBOOT( element ) apiElement_P( element, "reboot", "Reboots the device.", commander_reboot_func )
59#endif
63void commander_reboot_func( char *args, Stream *response );
64
65//-------- Timing functions --------//
66
67#define API_ELEMENT_MICROS apiElement( "micros", "Returns the number of microseconds passed since the program started.", commander_micros_func )
68#ifdef __AVR__
69 #define API_ELEMENT_P_MICROS( element ) apiElement_P( element, "micros", "Returns the number of microseconds passed since the program started.", commander_micros_func )
70#endif
74void commander_micros_func( char *args, Stream *response );
75
76#define API_ELEMENT_MILLIS apiElement( "millis", "Returns the number of milliseconds passed since the program started.", commander_millis_func )
77#ifdef __AVR__
78 #define API_ELEMENT_P_MILLIS( element ) apiElement_P( element, "millis", "Returns the number of milliseconds passed since the program started.", commander_millis_func )
79#endif
83void commander_millis_func( char *args, Stream *response );
84
85#define API_ELEMENT_UPTIME apiElement( "uptime", "Returns the time passed since the program started.", commander_uptime_func )
86#ifdef __AVR__
87 #define API_ELEMENT_P_UPTIME( element ) apiElement_P( element, "uptime", "Returns the time passed since the program started.", commander_uptime_func )
88#endif
92void commander_uptime_func( char *args, Stream *response );
93
94//-------- Pure awesomeness --------//
95
96#define API_ELEMENT_NEOFETCH apiElement( "neofetch", "Nice looking system information.", commander_neofetch_func )
97#ifdef __AVR__
98 #define API_ELEMENT_P_NEOFETCH( element ) apiElement_P( element, "neofetch", "Nice looking system information.", commander_neofetch_func )
99#endif
103void commander_neofetch_func( char *args, Stream *response );
104
105
106
107//-------- Digital I-O functions --------//
108
109#define API_ELEMENT_PINMODE apiElement( "pinMode", "Set the direction of a pin.\r\n\tExample: pinMode [ Pin Number ] [ Direction ]\r\n\t[ Pin Number ] - The number ofthe pin. Typically printed on the board.\r\n\t[ Direction ] - 0 means input, 1 means output.", commander_pinMode_func )
110#ifdef __AVR__
111 #define API_ELEMENT_P_PINMODE( element ) apiElement_P( element, "pinMode", "Set the direction of a pin.\r\n\tExample: pinMode [ Pin Number ] [ Direction ]\r\n\t[ Pin Number ] - The number ofthe pin. Typically printed on the board.\r\n\t[ Direction ] - 0 means input, 1 means output.", commander_pinMode_func )
112#endif
116void commander_pinMode_func( char *args, Stream *response );
117
118#define API_ELEMENT_DIGITALWRITE apiElement( "digitalWrite", "Set the state of an output pin.\r\n\tExample: digitalWrite [ Pin Number ] [ State ]\r\n\t[ Pin Number ] - The number ofthe pin. Typically printed on the board.\r\n\t[ State ] - 0 means low, 1 means high.", commander_digitalWrite_func )
119#ifdef __AVR__
120 #define API_ELEMENT_P_DIGITALWRITE( element ) apiElement_P( element, "digitalWrite", "Set the state of an output pin.\r\n\tExample: digitalWrite [ Pin Number ] [ State ]\r\n\t[ Pin Number ] - The number ofthe pin. Typically printed on the board.\r\n\t[ State ] - 0 means low, 1 means high.", commander_digitalWrite_func )
121#endif
125void commander_digitalWrite_func( char *args, Stream *response );
126
127#define API_ELEMENT_DIGITALREAD apiElement( "digitalRead", "Read the state of a pin.\r\n\tExample: digitalRead [ Pin Number ]\r\n\t[ Pin Number ] - The number ofthe pin. Typically printed on the board.\r\n\t[ Returns ] - 0 means low, 1 means high.", commander_digitalRead_func )
128#ifdef __AVR__
129 #define API_ELEMENT_P_DIGITALREAD( element ) apiElement_P( element, "digitalRead", "Read the state of a pin.\r\n\tExample: digitalRead [ Pin Number ]\r\n\t[ Pin Number ] - The number ofthe pin. Typically printed on the board.\r\n\t[ Returns ] - 0 means low, 1 means high.", commander_digitalRead_func )
130#endif
134void commander_digitalRead_func( char *args, Stream *response );
135
136//-------- Analog I-O functions --------//
137
138#define API_ELEMENT_ANALOGREAD apiElement( "analogRead", "Generate an ADC measurement on a pin.\r\n\tExample: analogRead [ Pin Number ]\r\n\t[ Pin Number ] - The number ofthe pin. Typically printed on the board.\r\n\t[ Returns ] - The raw ADC sample.", commander_analogRead_func )
139#ifdef __AVR__
140 #define API_ELEMENT_P_ANALOGREAD( element ) apiElement_P( element, "analogRead", "Generate an ADC measurement on a pin.\r\n\tExample: analogRead [ Pin Number ]\r\n\t[ Pin Number ] - The number ofthe pin. Typically printed on the board.\r\n\t[ Returns ] - The raw ADC sample.", commander_analogRead_func )
141#endif
145void commander_analogRead_func( char *args, Stream *response );
146
147//-------- WiFi functions --------//
148
149#if defined( ESP32 ) || ( ESP8266 )
150
151#define API_ELEMENT_IPCONFIG apiElement( "ipconfig", "Print network information.", commander_ipconfig_func )
155void commander_ipconfig_func( char *args, Stream *response );
156
157#define API_ELEMENT_WIFISTAT apiElement( "wifiStat", "Print WiFi information.", commander_wifiStat_func )
161void commander_wifiStat_func( char *args, Stream *response );
162
163#define API_ELEMENT_WIFISCAN apiElement( "wifiScan", "Search for available networks around.", commander_wifiScan_func )
167void commander_wifiScan_func( char *args, Stream *response );
168
169#endif
170
171#ifdef ESP32
172
173#define API_ELEMENT_CONFIGTIME apiElement( "configTime", "Configure NTP time settings.\r\n\tExample: configTime [ GMT Offset Sec ] [ DL Offset Sec ] [ Server ]\r\n\t[ GMT Offset Sec ] - UTC offset for your timezone in seconds.\r\n\t[ GMT Offset Sec ] - Daylight offset in sec.\r\n\t[ Server ] - NTP Server Address( optional, default: pool.ntp.org )", commander_configTime_func )
177void commander_configTime_func( char *args, Stream *response );
178
179#define API_ELEMENT_DATETIME apiElement( "dateTime", "Returns the NTP synchronised date and time.", commander_dateTime_func )
183void commander_dateTime_func( char *args, Stream *response );
184
185#endif
186
187//-------- Math functions --------//
188
189#define API_ELEMENT_SIN apiElement( "sin", "Sine function. The input is in radians.", commander_sin_func )
190#ifdef __AVR__
191 #define API_ELEMENT_P_SIN( element ) apiElement_P( element, "sin", "Sine function. The input is in radians.", commander_sin_func )
192#endif
196void commander_sin_func( char *args, Stream *response );
197
198#define API_ELEMENT_COS apiElement( "cos", "Cosine function. The input is in radians.", commander_cos_func )
199#ifdef __AVR__
200 #define API_ELEMENT_P_COS( element ) apiElement_P( element, "cos", "Cosine function. The input is in radians.", commander_cos_func )
201#endif
205void commander_cos_func( char *args, Stream *response );
206
207#define API_ELEMENT_ABS apiElement( "abs", "Calculates the absolute value of a number.", commander_abs_func )
208#ifdef __AVR__
209 #define API_ELEMENT_P_ABS( element ) apiElement_P( element, "abs", "Calculates the absolute value of a number.", commander_abs_func )
210#endif
214void commander_abs_func( char *args, Stream *response );
215
216#define API_ELEMENT_RANDOM apiElement( "random", "Generates a random number between the parameters.\r\n\tExample: random [ min ] [ max ]\r\n\t[ min ] - Lower integer bound\r\n\t[ max ] - Upper integer bound", commander_random_func )
217#ifdef __AVR__
218 #define API_ELEMENT_P_RANDOM( element ) apiElement_P( element, "random", "Generates a random number between the parameters.\r\n\tExample: random [ min ] [ max ]\r\n\t[ min ] - Lower integer bound\r\n\t[ max ] - Upper integer bound", commander_random_func )
219#endif
223void commander_random_func( char *args, Stream *response );
224
225#define API_ELEMENT_NOT apiElement( "not", "Logical not. If the input is 0 returns 1. Any other cases it returns 0.", commander_not_func )
226#ifdef __AVR__
227 #define API_ELEMENT_P_NOT( element ) apiElement_P( element, "not", "Logical not. If the input is 0 returns 1. Any other cases it returns 0.", commander_not_func )
228#endif
232void commander_not_func( char *args, Stream *response );
233
235#define NEOFETCH_LOGO_HEIGHT 12
236
237// Uncomment the unnecessary fields.
238// Modify the required ones to your application.
239#define NEOFETCH_FW_NAME "Firmware-name"
240//#define NEOFETCH_CPU_TYPE "CPU-Type"
241#define NEOFETCH_CPU_TYPE_AUTO
242#define NEOFETCH_COMPILER __VERSION__
243#define NEOFETCH_COMPILE_DATE __DATE__
244#define NEOFETCH_TERMINAL "Shellminator"
245#define NEOFETCH_COMMAND_PARSER "Commander"
246#define NEOFETCH_AUTHOR "Daniel Hajnal"
247#define NEOFETCH_LICENSE "MIT"
void commander_wifiStat_func(char *args, Stream *response)
Premade function for wifiStat command.
void commander_sin_func(char *args, Stream *response)
Premade function for sin command.
void commander_uptime_func(char *args, Stream *response)
Premade function for uptime command.
void commander_digitalWrite_func(char *args, Stream *response)
Premade function for digitalWrite command.
void commander_digitalRead_func(char *args, Stream *response)
Premade function for digitalRead command.
void commander_millis_func(char *args, Stream *response)
Premade function for millis command.
void commander_not_func(char *args, Stream *response)
Premade function for not command.
void commander_dateTime_func(char *args, Stream *response)
Premade function for wifiScan command.
void commander_configTime_func(char *args, Stream *response)
Premade function for wifiScan command.
void commander_wifiScan_func(char *args, Stream *response)
Premade function for wifiScan command.
void commander_neofetch_func(char *args, Stream *response)
Premade function for neofetch command.
void commander_reboot_func(char *args, Stream *response)
Premade function for reboot command.
void commander_cos_func(char *args, Stream *response)
Premade function for cos command.
void commander_abs_func(char *args, Stream *response)
Premade function for abs command.
void commander_pinMode_func(char *args, Stream *response)
Premade function for pinMode command.
void commander_analogRead_func(char *args, Stream *response)
Premade function for analogRead command.
void commander_micros_func(char *args, Stream *response)
Premade function for micros command.
void commander_random_func(char *args, Stream *response)
Premade function for random command.
void commander_ipconfig_func(char *args, Stream *response)
Premade function for ipconfig command.