This commit is contained in:
@ -10,8 +10,8 @@ CommandHandler::CommandHandler(DisplayProxy *display)
|
||||
|
||||
bool CommandHandler::parseJSON(const char *cmd)
|
||||
{
|
||||
Serial.print("Handling: ");
|
||||
Serial.println(cmd);
|
||||
debugSerial("parseJSON", cmd);
|
||||
|
||||
StaticJsonDocument<32> json;
|
||||
DeserializationError error = deserializeJson(json, cmd);
|
||||
|
||||
@ -30,7 +30,7 @@ bool CommandHandler::parseJSON(const char *cmd)
|
||||
int x = json["x"];
|
||||
int y = json["y"];
|
||||
|
||||
this->debugWrite(x, y, text);
|
||||
this->debugSerial(command, text);
|
||||
this->display->write(x, y, text);
|
||||
return true;
|
||||
}
|
||||
@ -38,25 +38,31 @@ bool CommandHandler::parseJSON(const char *cmd)
|
||||
if (strcmp("clear", command) == 0)
|
||||
{
|
||||
this->display->clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp("offset", command) == 0)
|
||||
{
|
||||
int x = json["x"];
|
||||
int y = json["y"];
|
||||
debugWrite(x,y,"offset unhandled");
|
||||
debugSerial("offset unhandled");
|
||||
//this->display->setOffset(x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CommandHandler::debugWrite(int x, int y, const char *text)
|
||||
void CommandHandler::debugSerial(const char *text)
|
||||
{
|
||||
Serial.print(F("Writing ("));
|
||||
Serial.print(x);
|
||||
Serial.print(",");
|
||||
Serial.print(y);
|
||||
Serial.print("): ");
|
||||
Serial.print(F("CommandHandler: "));
|
||||
Serial.println(text);
|
||||
}
|
||||
}
|
||||
|
||||
void CommandHandler::debugSerial(const char *command, const char *text)
|
||||
{
|
||||
Serial.print(F("CommandHandler: "));
|
||||
Serial.print(command);
|
||||
Serial.print(" > ");
|
||||
Serial.println(text);
|
||||
}
|
||||
|
@ -3,7 +3,9 @@
|
||||
#include "DisplayProxy.h"
|
||||
|
||||
/**
|
||||
* Parse a JSON command and convert it into display command(s)
|
||||
* Parse a JSON command and convert it into display command(s).
|
||||
*
|
||||
*
|
||||
*/
|
||||
class CommandHandler
|
||||
{
|
||||
@ -17,7 +19,13 @@ public:
|
||||
/**
|
||||
* Parse a command in JSON format
|
||||
* @code{.json}
|
||||
* To display a string
|
||||
*
|
||||
* {"cmd":"write","x": 2, "y": 10, "text":"Hello World"}
|
||||
*
|
||||
* or to clear the display
|
||||
*
|
||||
* {"cmd":"clear"}
|
||||
* @endcode
|
||||
*
|
||||
* @param cmd String to parse
|
||||
@ -26,10 +34,10 @@ public:
|
||||
bool parseJSON(const char *cmd);
|
||||
private:
|
||||
/**
|
||||
* Internal helper for printing debug strings
|
||||
* Internal helpers for printing debug strings
|
||||
*/
|
||||
void debugWrite(int x, int y, const char *text);
|
||||
|
||||
void debugSerial(const char *text);
|
||||
void debugSerial(const char *command, const char *text);
|
||||
/**
|
||||
* Display instance
|
||||
*/
|
||||
|
Reference in New Issue
Block a user