/** * @file CommandHandler.cpp * @author Jens True (jens.chr.true@gmail.com) * @brief CommandHandler implementation * @version 0.1 * @date 2021-11-10 * * @copyright Copyright (c) 2021 * */ #include "CommandHandler.h" #include "Arduino.h" #include "ArduinoJson.h" CommandHandler::CommandHandler(DisplayProxy *display) { this->display = display; } bool CommandHandler::parseJSON(const char *cmd) { debugSerial("parseJSON", cmd); StaticJsonDocument<32> json; DeserializationError error = deserializeJson(json, cmd); // Test if parsing succeeds. if (error) { Serial.print(F("deserializeJson() failed: ")); Serial.println(error.c_str()); return false; } const char *command = json["cmd"]; if (strcmp("write", command) == 0 && json["text"].is() && json["x"].is() && json["y"].is()) { const char *text = json["text"]; int x = json["x"]; int y = json["y"]; this->debugSerial(command, text); this->display->write(x, y, text); return true; } if (strcmp("clear", command) == 0) { this->display->clear(); return true; } if (strcmp("offset", command) == 0) { int x = json["x"]; int y = json["y"]; debugSerial("offset unhandled"); //this->display->setOffset(x, y); return true; } return false; } void CommandHandler::debugSerial(const char *text) { 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); }