This commit is contained in:
47
src/main.cpp
47
src/main.cpp
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user