I'm having a bit of a go around trying to format a serial command in the serial monitor to be sent to Command Handler.
The response from the sketch indicates: "I don't understand" in the serial monitor, so I am not formatting correctly.
!ListAll
with both NL and CR on yields a good result
!SetOnTime 40
returns: "I don't understand"
Can anyone come up with a good command?
#include "CommandHandler.h"
CommandHandler<> SerialCommandHandler;
long LastBlink = 0; // Time we last blinked the LED
int OnTime = 10; // Amount of time the LED remains on [milliseconds]
int OffTime = 100; // Amount of time the LED remains off [milliseconds]
const int LEDPin = 13; // Pin the LED is attached to
void setup()
{
Serial.begin(9600);
Serial.println(F("Blink 2.0"));
Serial.println(F("=========="));
// Setup the serial commands we can repond to
SerialCommandHandler.AddCommand(F("OnTime"), Cmd_SetOnTime);
SerialCommandHandler.AddCommand(F("OffTime"), Cmd_SetOffTime);
SerialCommandHandler.AddCommand(F("ListAll"), Cmd_ListAll);
SerialCommandHandler.SetDefaultHandler(Cmd_Unknown);
pinMode(LEDPin, OUTPUT);
}
void loop()
{
// Check for serial commands and dispatch them.
SerialCommandHandler.Process();
// Update the LED
uint32_t uNow = millis();
if (uNow - LastBlink < OnTime)
{
digitalWrite(LEDPin, HIGH);
}
else
{
digitalWrite(LEDPin, LOW);
}
if (uNow - LastBlink > OnTime + OffTime)
{
LastBlink = uNow;
}
}
void Cmd_ListAll(CommandParameter &Parameters)
{
Serial.print(F("OnTime [ms]="));
Serial.println(OnTime);
Serial.print(F("OffTime [ms]="));
Serial.println(OffTime);
}
void Cmd_SetOnTime(CommandParameter &Parameters)
{
OnTime = Parameters.NextParameterAsInteger(OnTime);
}
void Cmd_SetOffTime(CommandParameter &Parameters)
{
OffTime = Parameters.NextParameterAsInteger(OffTime);
}
void Cmd_Unknown()
{
Serial.println(F("I don't understand"));
}