1
0

OO redesign
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jens Christian True
2019-09-04 15:28:38 +02:00
parent 96fd2967b3
commit 3815d2ed5f
7 changed files with 140 additions and 42 deletions

View File

@ -2,49 +2,12 @@
#include <SPI.h>
#include "config.h"
#include "ArduinoJson.h"
#include "CommandHandler.h"
#include "DisplayProxyMAX7456.h"
#include "max7456.h"
Max7456 osd;
void handleRPC(char *cmd)
{
Serial.print("Handling: ");
Serial.println(cmd);
StaticJsonDocument<200> doc;
DeserializationError error = deserializeJson(doc, cmd);
// Test if parsing succeeds.
if (error)
{
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
const char *command = doc["command"]; // "write"
if (strcmp("write", command) == 0)
{
const char *text = doc["text"]; // "1351824120"
int x = doc["x"]; // 13
int y = doc["y"]; // 10
osd.print(text, x, y);
return;
}
if (strcmp("clear", command) == 0)
{
osd.clearScreen();
return;
}
if (strcmp("offset", command) == 0)
{
int x = doc["x"]; // 13
int y = doc["y"]; // 10
osd.setDisplayOffsets(x, y);
return;
}
}
DisplayProxyMAX7456 proxy(&osd);
CommandHandler cmd_handler(&proxy);
void processSerial()
{
@ -72,7 +35,7 @@ void processSerial()
{
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
handleRPC(receivedChars);
cmd_handler.parse(receivedChars);
}
}
}