Skip to content

Commit 26496d2

Browse files
committed
environment variable prototype
parameters can be accesed like envirnoment variables on linux. I think it is cooool.
1 parent 7fcb992 commit 26496d2

File tree

63 files changed

+3632
-1017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3632
-1017
lines changed

CMakeLists.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ include_directories(
3232
)
3333

3434
set( SOURCES
35-
src/Commander-API-Commands.cpp
36-
src/Commander-API-Digital-IO-Commands.cpp
35+
src/Commands/Commander-API-Commands.cpp
36+
src/Commands/Commander-API-Digital-IO-Commands.cpp
37+
src/Commands/Commander-API-Analog-IO-Commands.cpp
38+
src/Commands/Commander-API-System-Commands.cpp
39+
src/Commands/Commander-API-Neofetch-Command.cpp
3740
src/Commander-API-Commands.hpp
3841
src/Commander-API.cpp
3942
src/Commander-API.hpp
@@ -74,7 +77,6 @@ if( BUILD_EXAMPLES )
7477

7578
set( CUSTOM_COMMANDS
7679
extras/simulator/CustomCommands.cpp
77-
extras/simulator/CustomCommands.hpp
7880
)
7981

8082
endif()
@@ -114,8 +116,11 @@ if( BUILD_EXAMPLES )
114116
add_executable( Basic ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Basic/Basic.cpp )
115117
add_executable( Blink ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Blink/Blink.cpp )
116118
add_executable( Description ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Description/Description.cpp )
119+
add_executable( Echo ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Echo/Echo.cpp )
120+
add_executable( Fullsystem ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Fullsystem/Fullsystem.cpp )
117121
add_executable( Help ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Help/Help.cpp )
118122
add_executable( Interactive ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Interactive/Interactive.cpp )
123+
add_executable( Neofetch ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Neofetch/Neofetch.cpp )
119124
add_executable( Systemvariables ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_desktop/Desktop/Systemvariables/Systemvariables.cpp )
120125
endif()
121126
if( BUILD_WEBASSEMBLY )
@@ -134,12 +139,21 @@ if( BUILD_WEBASSEMBLY )
134139
add_executable( Description ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_emscripten/Emscripten/Description/Description.cpp )
135140
target_link_options( Description PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
136141

142+
add_executable( Echo ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_emscripten/Emscripten/Echo/Echo.cpp )
143+
target_link_options( Echo PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
144+
145+
add_executable( Fullsystem ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_emscripten/Emscripten/Fullsystem/Fullsystem.cpp )
146+
target_link_options( Fullsystem PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
147+
137148
add_executable( Help ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_emscripten/Emscripten/Help/Help.cpp )
138149
target_link_options( Help PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
139150

140151
add_executable( Interactive ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_emscripten/Emscripten/Interactive/Interactive.cpp )
141152
target_link_options( Interactive PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
142153

154+
add_executable( Neofetch ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_emscripten/Emscripten/Neofetch/Neofetch.cpp )
155+
target_link_options( Neofetch PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
156+
143157
add_executable( Systemvariables ${SOURCES} ${CUSTOM_COMMANDS} extras/examples_emscripten/Emscripten/Systemvariables/Systemvariables.cpp )
144158
target_link_options( Systemvariables PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
145159

examples/Arduino UNO/Argumentadvanced/Argumentadvanced.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2023 - Daniel Hajnal
66
77
* This file is part of the Commander-API project.
8-
* Modified 2023.Aug.04
8+
* Modified 2023.Aug.07
99
*
1010
* This is a simple example, that demonstrates how
1111
* to use the base functionality of th Commander-API.

examples/Arduino UNO/Argumentbasic/Argumentbasic.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2023 - Daniel Hajnal
66
77
* This file is part of the Commander-API project.
8-
* Modified 2023.Aug.04
8+
* Modified 2023.Aug.07
99
*
1010
* This is a simple example, that demonstrates how
1111
* to use the base functionality of th Commander-API.

examples/Arduino UNO/Basic/Basic.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2023 - Daniel Hajnal
66
77
* This file is part of the Commander-API project.
8-
* Modified 2023.Aug.04
8+
* Modified 2023.Aug.07
99
*
1010
* This is a simple example, that demonstrates how
1111
* to use the base functionality of th Commander-API.

examples/Arduino UNO/Description/Description.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2023 - Daniel Hajnal
66
77
* This file is part of the Commander-API project.
8-
* Modified 2023.Aug.04
8+
* Modified 2023.Aug.07
99
*
1010
* This is a simple example, that demonstrates how
1111
* to use the base functionality of th Commander-API.

examples/Arduino UNO/Echo/Echo.ino

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
2+
/*
3+
* Created on 2023.Jun.25
4+
*
5+
* Copyright (c) 2023 - Daniel Hajnal
6+
7+
* This file is part of the Commander-API project.
8+
* Modified 2023.Aug.07
9+
*
10+
* This is a simple example, that demonstrates how
11+
* to use the base functionality of th Commander-API.
12+
*/
13+
14+
15+
// Necessary includes
16+
#include "Commander-API.hpp"
17+
#include "Commander-IO.hpp"
18+
#include "Commander-API-Commands.hpp"
19+
#include <math.h>
20+
21+
22+
// We have to create an object from Commander class.
23+
Commander commander;
24+
25+
// Add echo and env commands to the API tree.
26+
Commander::API_t API_tree[] = {
27+
API_ELEMENT_ECHO,
28+
API_ELEMENT_ENV
29+
};
30+
31+
// Global system variables.
32+
float constPI = M_PI;
33+
int adcValue = 532;
34+
char boardID[] = "This is a very special board.";
35+
char swVersion[] = "V0.0.1";
36+
37+
// System Variable array. This array will store the
38+
// name and the instance of the system variables.
39+
Commander::SystemVariable_t systemVariables[] = {
40+
systemVariableFloat( constPI ),
41+
systemVariableInt( adcValue ),
42+
systemVariableString( boardID ),
43+
systemVariableString( swVersion )
44+
};
45+
46+
// This is a buffer to hold the incoming command.
47+
char commandFromSerial[ 30 ];
48+
49+
// This variable tracks the location of the next free
50+
// space in the commandFromSerial buffer.
51+
uint8_t commandIndex = 0;
52+
53+
54+
55+
56+
// System init section.
57+
void setup(){
58+
59+
Serial.begin(115200);
60+
61+
// There is an option to attach a debug channel to Commander.
62+
// It can be handy to find any problems during the initialization
63+
// phase. In this example, we will use Serial for this.
64+
commander.attachDebugChannel( &Serial );
65+
66+
// At start, Commander does not know anything about our commands.
67+
// We have to attach the API_tree array from the previous steps
68+
// to Commander to work properly.
69+
commander.attachTree( API_tree );
70+
71+
// Attach the system variable array to the command parser.
72+
Commander::attachVariables( systemVariables );
73+
74+
// After we attached the API_tree, Commander has to initialize
75+
// itself for the fastest runtime possible. It creates a balanced
76+
// binary tree from the API_tree to boost the search speed.
77+
// This part uses some recursion, to make the code space small.
78+
// But recursion is a bit stack hungry, so please initialize
79+
// Commander at the beginning of your code to prevent stack-overlow.
80+
commander.init();
81+
82+
Serial.println();
83+
Serial.println( "---- Init Finished ----" );
84+
Serial.println();
85+
86+
Serial.println( "Type something" );
87+
Serial.print( "$: " );
88+
89+
90+
}
91+
92+
// Infinite loop.
93+
void loop(){
94+
95+
// Check if there is any data incoming.
96+
while( Serial.available() ){
97+
98+
// Read the next incoming character.
99+
char c = Serial.read();
100+
101+
// Every command from Serial is terminated with a new-line
102+
// character. If a new-line character arrives, we have to
103+
// terminate the string in the commandFromSerial buffer,
104+
// and execute it. After execution, we have to reset the
105+
// commandIndex counter to zero.
106+
if( c == '\r' ){
107+
commandFromSerial[ commandIndex ] = '\0';
108+
Serial.println();
109+
commander.execute( commandFromSerial, &Serial );
110+
commandIndex = 0;
111+
Serial.print( "$: " );
112+
}
113+
114+
// If we have a carriage-return character we simply
115+
// ignore it.
116+
else if( c == '\n' ){
117+
continue;
118+
}
119+
120+
// Handle backspace events.
121+
else if( ( c == '\b' ) || ( c == 127 ) ){
122+
if( commandIndex > 0 ){
123+
commandIndex--;
124+
Serial.print( "\b \b" );
125+
}
126+
}
127+
128+
// Every other case we just put the data to the next
129+
// free space in the commandFromSerial buffer, increment
130+
// the commandIndex, and check if it wants to overflow.
131+
else{
132+
commandFromSerial[ commandIndex ] = c;
133+
commandIndex++;
134+
if( commandIndex >= sizeof( commandFromSerial ) ){
135+
commandIndex = sizeof( commandFromSerial ) - 1;
136+
}
137+
else{
138+
Serial.print( c );
139+
}
140+
}
141+
142+
}
143+
144+
145+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2+
/*
3+
* Created on 2023.Jun.25
4+
*
5+
* Copyright (c) 2023 - Daniel Hajnal
6+
7+
* This file is part of the Commander-API project.
8+
* Modified 2023.Aug.07
9+
*
10+
* This is a simple example, that demonstrates how
11+
* to use the base functionality of th Commander-API.
12+
*/
13+
14+
15+
// Necessary includes
16+
#include "Commander-API.hpp"
17+
#include "Commander-IO.hpp"
18+
#include "Commander-API-Commands.hpp"
19+
#include <math.h>
20+
21+
22+
// We have to create an object from Commander class.
23+
Commander commander;
24+
25+
// Add echo and env commands to the API tree.
26+
Commander::API_t API_tree[] = {
27+
API_ELEMENT_REBOOT,
28+
API_ELEMENT_ECHO,
29+
API_ELEMENT_ENV,
30+
API_ELEMENT_MICROS,
31+
API_ELEMENT_MILLIS,
32+
API_ELEMENT_UPTIME,
33+
API_ELEMENT_NEOFETCH,
34+
API_ELEMENT_PINMODE,
35+
API_ELEMENT_DIGITALWRITE,
36+
API_ELEMENT_DIGITALREAD,
37+
API_ELEMENT_ANALOGREAD,
38+
API_ELEMENT_ANALOGWRITE,
39+
API_ELEMENT_SIN,
40+
API_ELEMENT_COS,
41+
API_ELEMENT_ABS,
42+
API_ELEMENT_RANDOM,
43+
API_ELEMENT_NOT
44+
};
45+
46+
// This is a buffer to hold the incoming command.
47+
char commandFromSerial[ 30 ];
48+
49+
// This variable tracks the location of the next free
50+
// space in the commandFromSerial buffer.
51+
uint8_t commandIndex = 0;
52+
53+
54+
55+
56+
// System init section.
57+
void setup(){
58+
59+
Serial.begin(115200);
60+
61+
// There is an option to attach a debug channel to Commander.
62+
// It can be handy to find any problems during the initialization
63+
// phase. In this example, we will use Serial for this.
64+
commander.attachDebugChannel( &Serial );
65+
66+
// At start, Commander does not know anything about our commands.
67+
// We have to attach the API_tree array from the previous steps
68+
// to Commander to work properly.
69+
commander.attachTree( API_tree );
70+
71+
// After we attached the API_tree, Commander has to initialize
72+
// itself for the fastest runtime possible. It creates a balanced
73+
// binary tree from the API_tree to boost the search speed.
74+
// This part uses some recursion, to make the code space small.
75+
// But recursion is a bit stack hungry, so please initialize
76+
// Commander at the beginning of your code to prevent stack-overlow.
77+
commander.init();
78+
79+
Serial.println();
80+
Serial.println( "---- Init Finished ----" );
81+
Serial.println();
82+
83+
Serial.println( "Type something" );
84+
Serial.print( "$: " );
85+
86+
87+
}
88+
89+
// Infinite loop.
90+
void loop(){
91+
92+
// Check if there is any data incoming.
93+
while( Serial.available() ){
94+
95+
// Read the next incoming character.
96+
char c = Serial.read();
97+
98+
// Every command from Serial is terminated with a new-line
99+
// character. If a new-line character arrives, we have to
100+
// terminate the string in the commandFromSerial buffer,
101+
// and execute it. After execution, we have to reset the
102+
// commandIndex counter to zero.
103+
if( c == '\r' ){
104+
commandFromSerial[ commandIndex ] = '\0';
105+
Serial.println();
106+
commander.execute( commandFromSerial, &Serial );
107+
commandIndex = 0;
108+
Serial.print( "$: " );
109+
}
110+
111+
// If we have a carriage-return character we simply
112+
// ignore it.
113+
else if( c == '\n' ){
114+
continue;
115+
}
116+
117+
// Handle backspace events.
118+
else if( ( c == '\b' ) || ( c == 127 ) ){
119+
if( commandIndex > 0 ){
120+
commandIndex--;
121+
Serial.print( "\b \b" );
122+
}
123+
}
124+
125+
// Every other case we just put the data to the next
126+
// free space in the commandFromSerial buffer, increment
127+
// the commandIndex, and check if it wants to overflow.
128+
else{
129+
commandFromSerial[ commandIndex ] = c;
130+
commandIndex++;
131+
if( commandIndex >= sizeof( commandFromSerial ) ){
132+
commandIndex = sizeof( commandFromSerial ) - 1;
133+
}
134+
else{
135+
Serial.print( c );
136+
}
137+
}
138+
139+
}
140+
141+
142+
}

examples/Arduino UNO/Help/Help.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2023 - Daniel Hajnal
66
77
* This file is part of the Commander-API project.
8-
* Modified 2023.Aug.04
8+
* Modified 2023.Aug.07
99
*
1010
* This is a simple example, that demonstrates how
1111
* to use the base functionality of th Commander-API.

examples/Arduino UNO/Interactive/Interactive.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2023 - Daniel Hajnal
66
77
* This file is part of the Commander-API project.
8-
* Modified 2023.Aug.04
8+
* Modified 2023.Aug.07
99
*
1010
* This is a simple example, that demonstrates how
1111
* to use the base functionality of th Commander-API.

0 commit comments

Comments
 (0)