55 *
66 * Run the sketch, then type 'help' on the serial port. The following
77 * commands are supported:
8- * - `help [command]`
9- * - `list`
10- * - `free`
11- * - `echo [args ...]`
12- * - `delay (on | off) millis`
8+ * - `help [command]` - list the known commands
9+ * - `list` - list the coroutines managed by the CoroutineScheduler
10+ * - `free` - print free memory
11+ * - `echo [args ...]` - echo the arguments
12+ * - `delay (on | off) millis` - set LED blink on or off delay
1313 */
1414
1515#include < Arduino.h>
@@ -130,20 +130,20 @@ void delayCommand(Print& printer, int argc, const char** argv) {
130130 }
131131}
132132
133- // Select C_STRING to use C-strings (const char*)
133+ // Select USE_C_STRING to use C-strings (const char*)
134134//
135- // Select F_STRING to use FlashStrings (const __FlashString*) which
135+ // Select USE_F_STRING to use FlashStrings (const __FlashString*) which
136136// stores the strings in flash memory, saving 48 bytes out of
137137// 457 bytes of statis RAM in this example.
138- #define C_STRING 1
139- #define F_STRING 2
140- #define STRING_MODE F_STRING
138+ #define USE_C_STRING 1
139+ #define USE_F_STRING 2
140+ #define STRING_MODE USE_F_STRING
141141
142- #if STRING_MODE == C_STRING
142+ #if STRING_MODE == USE_C_STRING
143143
144144const DispatchRecordC dispatchTable[] = {
145145 {delayCommand, " delay" , " (on | off) millis" },
146- {listCommand, " ps " , nullptr },
146+ {listCommand, " list " , nullptr },
147147 {freeCommand, " free" , nullptr },
148148 {echoCommand, " echo" , " args ..." },
149149};
@@ -152,11 +152,15 @@ const uint8_t numCommands = sizeof(dispatchTable) / sizeof(DispatchRecordC);
152152
153153#else
154154
155- // F() works only inside methods.
155+ /* *
156+ * The F() macro works only inside methods, so we use this static function
157+ * to create and hold the dispatch table. Returns the pointer to the table
158+ * and sets the *numCommands to the number of entries.
159+ */
156160static const DispatchRecordF* getDispatchTable (uint8_t * numCommands) {
157161 static const DispatchRecordF dispatchTable[] = {
158162 {delayCommand, F (" delay" ), F (" (on | off) millis" )},
159- {listCommand, F (" ps " ), nullptr },
163+ {listCommand, F (" list " ), nullptr },
160164 {freeCommand, F (" free" ), nullptr },
161165 {echoCommand, F (" echo" ), F (" args ..." )},
162166 };
@@ -171,24 +175,24 @@ const DispatchRecordF* dispatchTable = getDispatchTable(&numCommands);
171175
172176#endif
173177
178+ // Create an instance of the StreamReader.
174179const int BUF_SIZE = 64 ;
175180char lineBuffer[BUF_SIZE];
176181StreamReader streamReader (Serial, lineBuffer, BUF_SIZE);
177182
183+
184+ // Create an instance of the CommandDispatcher using either CStrings or
185+ // FStrings.
178186const int8_t ARGV_SIZE = 10 ;
179187const char * argv[ARGV_SIZE];
180-
181- #if STRING_MODE == C_STRING
182-
183- CommandDispatcherC dispatcher (streamReader, Serial,
184- dispatchTable, numCommands, argv, ARGV_SIZE);
185-
188+ #if STRING_MODE == USE_C_STRING
189+ CommandDispatcherC dispatcher (streamReader, Serial,
190+ dispatchTable, numCommands, argv, ARGV_SIZE);
186191#else
187-
188- CommandDispatcherF dispatcher (streamReader, Serial,
189- dispatchTable, numCommands, argv, ARGV_SIZE);
190-
192+ CommandDispatcherF dispatcher (streamReader, Serial,
193+ dispatchTable, numCommands, argv, ARGV_SIZE);
191194#endif
195+
192196// ---------------------------------------------------------------------------
193197
194198void setup () {
0 commit comments