This commit is contained in:
@ -8,7 +8,7 @@ CommandHandler::CommandHandler(DisplayProxy *display)
|
||||
this->display = display;
|
||||
}
|
||||
|
||||
bool CommandHandler::parse(const char *cmd)
|
||||
bool CommandHandler::parseJSON(const char *cmd)
|
||||
{
|
||||
Serial.print("Handling: ");
|
||||
Serial.println(cmd);
|
||||
@ -23,7 +23,7 @@ bool CommandHandler::parse(const char *cmd)
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *command = doc["command"];
|
||||
const char *command = doc["cmd"];
|
||||
if (strcmp("write", command) == 0 && doc["text"].is<const char*>() && doc["x"].is<int>() && doc["y"].is<int>())
|
||||
{
|
||||
const char *text = doc["text"];
|
||||
|
@ -3,14 +3,31 @@
|
||||
#include "DisplayProxy.h"
|
||||
|
||||
/**
|
||||
* Parse a JSON command and convert it into a display command
|
||||
* Parse a JSON command and convert it into display command(s)
|
||||
*/
|
||||
class CommandHandler
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param display Takes an implementation of DisplayProxy through polymorphism.
|
||||
*/
|
||||
explicit CommandHandler(DisplayProxy *display);
|
||||
bool parse(const char *cmd);
|
||||
/**
|
||||
* Parse a command in JSON format
|
||||
* @code{.json}
|
||||
* {"cmd":"write","x": 2, "y": 10, "text":"Hello World"}
|
||||
* @endcode
|
||||
*
|
||||
* @param cmd String to parse
|
||||
* @return True if the input was parsed correctly.
|
||||
*/
|
||||
bool parseJSON(const char *cmd);
|
||||
private:
|
||||
/**
|
||||
* Internal helper for printing debug strings
|
||||
*/
|
||||
void debugWrite(int x, int y, const char *text);
|
||||
DisplayProxy *display;
|
||||
|
||||
|
Reference in New Issue
Block a user