|
| 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--++ |
0 commit comments