2019-09-04 13:28:38 +00:00
|
|
|
#include "CommandHandler.h"
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "ArduinoJson.h"
|
|
|
|
|
|
|
|
CommandHandler::CommandHandler(DisplayProxy *display)
|
|
|
|
{
|
|
|
|
this->display = display;
|
|
|
|
}
|
|
|
|
|
2021-11-03 10:13:25 +00:00
|
|
|
bool CommandHandler::parseJSON(const char *cmd)
|
2019-09-04 13:28:38 +00:00
|
|
|
{
|
|
|
|
Serial.print("Handling: ");
|
|
|
|
Serial.println(cmd);
|
2021-11-03 12:00:05 +00:00
|
|
|
StaticJsonDocument<32> json;
|
|
|
|
DeserializationError error = deserializeJson(json, cmd);
|
2019-09-04 13:28:38 +00:00
|
|
|
|
|
|
|
// Test if parsing succeeds.
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
Serial.print(F("deserializeJson() failed: "));
|
|
|
|
Serial.println(error.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-11-03 12:00:05 +00:00
|
|
|
const char *command = json["cmd"];
|
|
|
|
if (strcmp("write", command) == 0 && json["text"].is<const char*>() && json["x"].is<int>() && json["y"].is<int>())
|
2019-09-04 13:28:38 +00:00
|
|
|
{
|
2021-11-03 12:00:05 +00:00
|
|
|
const char *text = json["text"];
|
|
|
|
int x = json["x"];
|
|
|
|
int y = json["y"];
|
2019-09-04 13:28:38 +00:00
|
|
|
|
|
|
|
this->debugWrite(x, y, text);
|
|
|
|
this->display->write(x, y, text);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp("clear", command) == 0)
|
|
|
|
{
|
|
|
|
this->display->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp("offset", command) == 0)
|
|
|
|
{
|
2021-11-03 12:00:05 +00:00
|
|
|
int x = json["x"];
|
|
|
|
int y = json["y"];
|
|
|
|
debugWrite(x,y,"offset unhandled");
|
2021-10-28 14:44:20 +00:00
|
|
|
//this->display->setOffset(x, y);
|
2019-09-04 13:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandHandler::debugWrite(int x, int y, const char *text)
|
|
|
|
{
|
|
|
|
Serial.print(F("Writing ("));
|
|
|
|
Serial.print(x);
|
|
|
|
Serial.print(",");
|
|
|
|
Serial.print(y);
|
|
|
|
Serial.print("): ");
|
|
|
|
Serial.println(text);
|
|
|
|
}
|