Skip to content

Commit 0759886

Browse files
committed
Built in commands are starting to be refactored.
* Digital IO functions are refactored. * An example is added for them. * New argument parser is started to be implemented in internal commands.
1 parent 1779686 commit 0759886

File tree

37 files changed

+764
-214
lines changed

37 files changed

+764
-214
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ include_directories(
3232
)
3333

3434
set( SOURCES
35-
#src/Commander-API-Commands.cpp
36-
#src/Commander-API-Commands.hpp
35+
src/Commander-API-Commands.cpp
36+
src/Commander-API-Digital-IO-Commands.cpp
37+
src/Commander-API-Commands.hpp
3738
src/Commander-API.cpp
3839
src/Commander-API.hpp
3940
src/Commander-IO.cpp
@@ -102,6 +103,7 @@ if( BUILD_EXAMPLES )
102103
add_executable( Argumentadvanced ${SOURCES} extras/examples_desktop/Desktop/Argumentadvanced/Argumentadvanced.cpp )
103104
add_executable( Argumentbasic ${SOURCES} extras/examples_desktop/Desktop/Argumentbasic/Argumentbasic.cpp )
104105
add_executable( Basic ${SOURCES} extras/examples_desktop/Desktop/Basic/Basic.cpp )
106+
add_executable( Blink ${SOURCES} extras/examples_desktop/Desktop/Blink/Blink.cpp )
105107
add_executable( Description ${SOURCES} extras/examples_desktop/Desktop/Description/Description.cpp )
106108
add_executable( Help ${SOURCES} extras/examples_desktop/Desktop/Help/Help.cpp )
107109
add_executable( Interactive ${SOURCES} extras/examples_desktop/Desktop/Interactive/Interactive.cpp )
@@ -116,6 +118,9 @@ if( BUILD_WEBASSEMBLY )
116118
add_executable( Basic ${SOURCES} extras/examples_emscripten/Emscripten/Basic/Basic.cpp )
117119
target_link_options( Basic PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
118120

121+
add_executable( Blink ${SOURCES} extras/examples_emscripten/Emscripten/Blink/Blink.cpp )
122+
target_link_options( Blink PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
123+
119124
add_executable( Description ${SOURCES} extras/examples_emscripten/Emscripten/Description/Description.cpp )
120125
target_link_options( Description PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )
121126

exampleGenerator.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,28 @@ def findLine( lst, data ):
156156
if example.endswith( '.example' ) == False:
157157
continue
158158

159-
print( "\tGenerating example: {:s}".format( example ) )
159+
print( "\tGenerating example: {:s}".format( example ), end = " " )
160160

161161
# Read the next example file line-by-line.
162162
exampleFile = open( rootDirectory + "/extras/example_database/" + example )
163163
exampleData = exampleFile.readlines()
164164

165-
# Store additional example parameters.
166-
excludeData = exampleData[ 0 ]
165+
# Get the list of the excluded boars.
166+
excludeData = exampleData[ 0 ].split( '=' )[ 1 ]
167+
excludeData = excludeData.replace( '\n', '' ).split(',')
168+
169+
# If this flag is true, this example will be ignored for this round.
170+
skipThisExample = False
171+
172+
# Check if this panel is excluded.
173+
for exclude in excludeData:
174+
if exclude == boardInfo:
175+
skipThisExample = True
176+
177+
# Check if skip is needed.
178+
if skipThisExample:
179+
print( "--EXCLUDED-- " )
180+
continue
167181

168182
# Find the index of every section.
169183
headerStartIndex = findLine( exampleData, "++--HEADER--++\n" )
@@ -240,7 +254,7 @@ def findLine( lst, data ):
240254

241255
CMakeContent.append( "\tadd_executable( " + exampleFolderName + " ${SOURCES} " + emscriptenExampleFolder[ 1: ] + "/" + boardInfo + "/" + exampleFolderName + "/" + exampleFolderName + ".cpp )\n" )
242256
CMakeContent.append( "\ttarget_link_options( " + exampleFolderName + " PUBLIC -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1 -sRETAIN_COMPILER_SETTINGS -sASYNCIFY )\n\n" )
243-
#print( secondRunData )
257+
print( "", end="\n" )
244258

245259
# We have to close an if statement at the end.
246260
if environmentInfo == 'Desktop':

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.Jun.30
8+
* Modified 2023.Jul.30
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.Jun.30
8+
* Modified 2023.Jul.30
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.Jun.30
8+
* Modified 2023.Jul.30
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.Jun.30
8+
* Modified 2023.Jul.30
99
*
1010
* This is a simple example, that demonstrates how
1111
* to use the base functionality of th Commander-API.

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.Jun.30
8+
* Modified 2023.Jul.30
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.Jun.30
8+
* Modified 2023.Jul.30
99
*
1010
* This is a simple example, that demonstrates how
1111
* to use the base functionality of th Commander-API.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
EXCLUDE=Arduino UNO
2+
3+
++--HEADER--++
4+
5+
/*
6+
* Created on 2023.July.30
7+
*
8+
* Copyright (c) 2023 - Daniel Hajnal
9+
10+
* This file is part of the Commander-API project.
11+
* Modified {{ YEAR }}.{{ MONTH }}.{{ DAY }}
12+
*
13+
* This is a simple example, that demonstrates how
14+
* to use the base functionality of th Commander-API.
15+
*/
16+
17+
++--INCLUDES--++
18+
19+
// Necessary includes
20+
#include "Commander-API.hpp"
21+
#include "Commander-IO.hpp"
22+
#include "Commander-API-Commands.hpp"
23+
24+
++--GLOBAL_VARIABLES--++
25+
26+
// We have to create an object from Commander class.
27+
Commander commander;
28+
29+
Commander::API_t API_tree[] = {
30+
API_ELEMENT_PINMODE,
31+
API_ELEMENT_DIGITALREAD,
32+
API_ELEMENT_DIGITALWRITE
33+
};
34+
35+
++--FUNCTION_PROTOTYPES--++
36+
37+
++--SETUP--++
38+
39+
// There is an option to attach a debug channel to Commander.
40+
// It can be handy to find any problems during the initialization
41+
// phase. In this example, we will use {{ channel }} for this.
42+
commander.attachDebugChannel( &{{ channel }} );
43+
44+
// At start, Commander does not know anything about our commands.
45+
// We have to attach the API_tree array from the previous steps
46+
// to Commander to work properly.
47+
commander.attachTree( API_tree );
48+
49+
// After we attached the API_tree, Commander has to initialize
50+
// itself for the fastest runtime possible. It creates a balanced
51+
// binary tree from the API_tree to boost the search speed.
52+
// This part uses some recursion, to make the code space small.
53+
// But recursion is a bit stack hungry, so please initialize
54+
// Commander at the beginning of your code to prevent stack-overflow.
55+
commander.init();
56+
57+
Serial.println();
58+
Serial.println( __CONST_TXT__( "---- Init Finished ----" ) );
59+
Serial.println();
60+
61+
// List all the available commands.
62+
Serial.println( __CONST_TXT__( "Executing 'help -d' command:" ) );
63+
commander.execute( "help -d", &Serial );
64+
Serial.println();
65+
66+
// Set pin 13 to output. Usually the LED is on this pin.
67+
Serial.println( __CONST_TXT__( "Executing 'pinMode -p 13 -o' command:" ) );
68+
commander.execute( "pinMode -p 13 -o", &Serial );
69+
Serial.println();
70+
71+
++--LOOP--++
72+
73+
// Set pin 13 to logic high. It will turn on the built in LED on most boards.
74+
Serial.println( __CONST_TXT__( "Executing 'digitalWrite -p 13 -h' command:" ) );
75+
commander.execute( "digitalWrite -p 13 -h", &Serial );
76+
77+
// Read the state of pin 13.
78+
Serial.println( __CONST_TXT__( "Executing 'digitalRead -p 13' command:" ) );
79+
commander.execute( "digitalRead -p 13", &Serial );
80+
81+
// Delay one seconds.
82+
delay( 1000 );
83+
84+
// Set pin 13 to logic low. It will turn off the built in LED on most boards.
85+
Serial.println( __CONST_TXT__( "Executing 'digitalWrite -p 13 -l' command:" ) );
86+
commander.execute( "digitalWrite -p 13 -h", &Serial );
87+
88+
// Read the state of pin 13.
89+
Serial.println( __CONST_TXT__( "Executing 'digitalRead -p 13' command:" ) );
90+
commander.execute( "digitalRead -p 13", &Serial );
91+
92+
// Delay one seconds.
93+
delay( 1000 );
94+
95+
++--FUNCTION_IMPLEMENTATIONS--++

extras/example_database/help.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ EXCLUDE=NONE
55
/*
66
* Created on 2023.Jun.25
77
*
8-
* Copyright (c) {{ YEAR }} - Daniel Hajnal
8+
* Copyright (c) 2023 - Daniel Hajnal
99
1010
* This file is part of the Commander-API project.
1111
* Modified {{ YEAR }}.{{ MONTH }}.{{ DAY }}

0 commit comments

Comments
 (0)