1
0
MAX7456JSON/lib/CommandHandler/CommandHandler.cpp
Jens True 7a23e39078
All checks were successful
continuous-integration/drone/push Build is passing
Overloading documentation
2021-11-24 15:44:01 +00:00

76 lines
1.6 KiB
C++

/**
* @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<const char*>() && json["x"].is<int>() && json["y"].is<int>())
{
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)
{
debugSerial("offset unhandled");
return false;
}
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);
}