This commit is contained in:
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -2,5 +2,10 @@
|
||||
"terminal.integrated.env.windows": {
|
||||
"PATH": "C:\\Program Files (x86)\\STMicroelectronics\\st_toolset\\asm;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\STMicroelectronics\\STM32 ST-LINK Utility\\ST-LINK Utility;C:\\Program Files\\doxygen\\bin;C:\\Users\\furyf\\scoop\\apps\\latex\\current\\texmfs\\install\\miktex\\bin;C:\\Users\\furyf\\scoop\\apps\\ruby\\current\\gems\\bin;C:\\Users\\furyf\\scoop\\apps\\ruby\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\nodejs\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\nodejs\\current;C:\\Users\\furyf\\go\\bin;C:\\Users\\furyf\\scoop\\apps\\gcc\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\composer\\current\\home\\vendor\\bin;C:\\Users\\furyf\\scoop\\apps\\nmap\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\python27\\current\\scripts;C:\\Users\\furyf\\AppData\\Local\\Programs\\Python\\Launcher\\;C:\\Users\\furyf\\scoop\\shims;C:\\Users\\furyf\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\furyf\\scoop\\apps\\msys\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\hyper\\2.0.0\\resources\\bin;C:\\Users\\furyf\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files (x86)\\STMicroelectronics\\st_toolset\\asm;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\STMicroelectronics\\STM32 ST-LINK Utility\\ST-LINK Utility;C:\\Program Files\\doxygen\\bin;C:\\Users\\furyf\\scoop\\apps\\latex\\current\\texmfs\\install\\miktex\\bin;C:\\Users\\furyf\\scoop\\apps\\ruby\\current\\gems\\bin;C:\\Users\\furyf\\scoop\\apps\\ruby\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\nodejs\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\nodejs\\current;C:\\Users\\furyf\\go\\bin;C:\\Users\\furyf\\scoop\\apps\\gcc\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\composer\\current\\home\\vendor\\bin;C:\\Users\\furyf\\scoop\\apps\\nmap\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\python27\\current\\scripts;C:\\Users\\furyf\\AppData\\Local\\Programs\\Python\\Launcher\\;C:\\Users\\furyf\\scoop\\shims;C:\\Users\\furyf\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\furyf\\scoop\\apps\\msys\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\hyper\\2.0.0\\resources\\bin;C:\\Users\\furyf\\AppData\\Local\\Programs\\Microsoft VS Code\\bin",
|
||||
"PLATFORMIO_CALLER": "vscode"
|
||||
},
|
||||
"files.associations": {
|
||||
"ios": "cpp",
|
||||
"system_error": "cpp",
|
||||
"xstring": "cpp"
|
||||
}
|
||||
}
|
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
|
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