From 353f04fba587d4788c4eb0fb693b9ca5f2ace296 Mon Sep 17 00:00:00 2001 From: Jens True Date: Tue, 9 Nov 2021 09:00:30 +0000 Subject: [PATCH] Cleanup --- lib/CommandHandler/CommandHandler.cpp | 30 ++++++++++++++++----------- lib/CommandHandler/CommandHandler.h | 16 ++++++++++---- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/lib/CommandHandler/CommandHandler.cpp b/lib/CommandHandler/CommandHandler.cpp index d362d14..8b687c8 100644 --- a/lib/CommandHandler/CommandHandler.cpp +++ b/lib/CommandHandler/CommandHandler.cpp @@ -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); -} \ No newline at end of file +} + +void CommandHandler::debugSerial(const char *command, const char *text) +{ + Serial.print(F("CommandHandler: ")); + Serial.print(command); + Serial.print(" > "); + Serial.println(text); +} diff --git a/lib/CommandHandler/CommandHandler.h b/lib/CommandHandler/CommandHandler.h index 35b5cb9..8ee1f44 100644 --- a/lib/CommandHandler/CommandHandler.h +++ b/lib/CommandHandler/CommandHandler.h @@ -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 */