2019-09-04 15:28:38 +02:00
|
|
|
#include "CommandHandler.h"
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "ArduinoJson.h"
|
|
|
|
|
|
|
|
CommandHandler::CommandHandler(DisplayProxy *display)
|
|
|
|
{
|
|
|
|
this->display = display;
|
|
|
|
}
|
|
|
|
|
2021-10-28 11:50:57 +00:00
|
|
|
bool CommandHandler::parse(const char *cmd)
|
2019-09-04 15:28:38 +02:00
|
|
|
{
|
|
|
|
Serial.print("Handling: ");
|
|
|
|
Serial.println(cmd);
|
|
|
|
StaticJsonDocument<32> doc;
|
|
|
|
DeserializationError error = deserializeJson(doc, cmd);
|
|
|
|
|
|
|
|
// Test if parsing succeeds.
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
Serial.print(F("deserializeJson() failed: "));
|
|
|
|
Serial.println(error.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *command = doc["command"];
|
|
|
|
if (strcmp("write", command) == 0 && doc["text"].is<const char*>() && doc["x"].is<int>() && doc["y"].is<int>())
|
|
|
|
{
|
|
|
|
const char *text = doc["text"];
|
|
|
|
int x = doc["x"];
|
|
|
|
int y = doc["y"];
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int x = doc["x"];
|
|
|
|
int y = doc["y"];
|
2021-10-28 14:44:20 +00:00
|
|
|
//this->display->setOffset(x, y);
|
2019-09-04 15:28:38 +02: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);
|
|
|
|
}
|