1
0

Documentation cleanup
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-11-03 10:13:25 +00:00
parent d4df2225b5
commit b8eccbe162
6 changed files with 44 additions and 9 deletions

View File

@ -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"];

View File

@ -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;