This commit is contained in:
61
lib/CommandHandler/CommandHandler.cpp
Normal file
61
lib/CommandHandler/CommandHandler.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "CommandHandler.h"
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
CommandHandler::CommandHandler(DisplayProxy *display)
|
||||
{
|
||||
this->display = display;
|
||||
}
|
||||
|
||||
bool CommandHandler::parse(char *cmd)
|
||||
{
|
||||
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"];
|
||||
this->display->setOffset(x, y);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
16
lib/CommandHandler/CommandHandler.h
Normal file
16
lib/CommandHandler/CommandHandler.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef COMMANDHANDLER_H
|
||||
#define COMMANDHANDLER_H
|
||||
#include "DisplayProxy.h"
|
||||
|
||||
class CommandHandler
|
||||
{
|
||||
public:
|
||||
CommandHandler(DisplayProxy *display);
|
||||
bool parse(char *cmd);
|
||||
private:
|
||||
void debugWrite(int x, int y, const char *text);
|
||||
DisplayProxy *display;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
10
lib/DisplayProxy/DisplayProxy.h
Normal file
10
lib/DisplayProxy/DisplayProxy.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef DISPLAYPROXY_H
|
||||
#define DISPLAYPROXY_H
|
||||
class DisplayProxy
|
||||
{
|
||||
public:
|
||||
virtual bool write(int x, int y, const char *text) = 0;
|
||||
virtual bool clear() = 0;
|
||||
virtual bool setOffset(int x, int y) = 0;
|
||||
};
|
||||
#endif
|
24
lib/DisplayProxy/DisplayProxyMAX7456.cpp
Normal file
24
lib/DisplayProxy/DisplayProxyMAX7456.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "DisplayProxyMAX7456.h"
|
||||
|
||||
DisplayProxyMAX7456::DisplayProxyMAX7456(Max7456 *osd)
|
||||
{
|
||||
this->osd = osd;
|
||||
}
|
||||
|
||||
bool DisplayProxyMAX7456::write(int x, int y, const char *text)
|
||||
{
|
||||
this->osd->print(text, x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DisplayProxyMAX7456::clear()
|
||||
{
|
||||
this->osd->clearScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DisplayProxyMAX7456::setOffset(int x, int y)
|
||||
{
|
||||
this->osd->setDisplayOffsets(x, y);
|
||||
return true;
|
||||
}
|
19
lib/DisplayProxy/DisplayProxyMAX7456.h
Normal file
19
lib/DisplayProxy/DisplayProxyMAX7456.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef DISPLAYPROXYMAX7456_H
|
||||
#define DISPLAYPROXYMAX7456_H
|
||||
|
||||
#include "DisplayProxy.h"
|
||||
#include "max7456.h"
|
||||
|
||||
class DisplayProxyMAX7456 : public DisplayProxy
|
||||
{
|
||||
public:
|
||||
DisplayProxyMAX7456(Max7456 *osd);
|
||||
|
||||
bool write(int x, int y, const char *text);
|
||||
bool clear() ;
|
||||
bool setOffset(int x, int y);
|
||||
private:
|
||||
Max7456 *osd;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user