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