Built on the Eventually library, this provides a listener which reads commands from any Serial device.
This works alongside any other listener you might already have in your sketch.
Commands can be sent from a laptop through the serial monitor or Bluetooth-connected phone.
Commands must start with '>' and end with '!', eg:
>set!
// or
>update!
Commands can optionally include an integer data element, separated by a colon:
>set:123!
The data element will be passed into your registered EvtCommandAction callback.
EvtManager mgr;
EvtCommandListener commandListener(&Serial);
void setup()
{
Serial.begin(115200);
// register other listeners as normal
mgr.addListener(new EvtPinListener(...));
// register the command and the action to trigger
commandListener.when("update", (EvtCommandAction)update);
commandListener.when("set", (EvtCommandAction)set);
mgr.addListener(&commandListener);
}
At the top of your main.h (before the other headers), define EVENTUALLY_MAX_COMMANDS:
#define EVENTUALLY_MAX_COMMANDS 20
#include <EventuallyCommand.h>
At the top of your main.h (before the other headers), define the following:
#define EVENTUALLY_COMMAND_BUFFER_LENGTH 20
#define EVENTUALLY_DATA_BUFFER_LENGTH 20
#include <EventuallyCommand.h>
Install command line tools by following the installation instructions for Windows
Deploy code to your Arduino and run the following command in a terminal:
pio device monitor --eol=CRLF --echo --filter=send_on_enter
Run the following command after installing Platform IO:
pio test -e native