#include #include "config.h" #include "ArduinoJson.h" #include "max7456.h" Max7456 osd; void setup() { Serial.begin(BAUDRATE); Serial.println("================================================================================"); Serial.println("Firmware: " PROJECT_NAME); Serial.println("Version: " VERSION_STRING); Serial.println("Built: " __DATE__ ", " __TIME__); Serial.println("================================================================================"); Serial.println("Initialize..."); SPI.begin(); osd.init(6); osd.clearScreen(); osd.setDisplayOffsets(DISP_OFFSET_X, DISP_OFFSET_Y); osd.setBlinkParams(_8fields, _BT_3BT); osd.activateOSD(); osd.activateExternalVideo(false); osd.print("==========================", 0, 0); osd.print("Firmware: " PROJECT_NAME, 0, 1); osd.print("Version: " VERSION_STRING, 0, 2); osd.print("Built: " __DATE__ ", " __TIME__, 0, 3); osd.print("==========================", 0, 4); delay(3000); osd.clearScreen(); Serial.println("Ready!"); } void loop() { processSerial(); } void handleRPC(char *cmd) { Serial.print("Handling: "); Serial.println(cmd); const size_t capacity = JSON_OBJECT_SIZE(4) + 50; DynamicJsonBuffer jsonBuffer(capacity); JsonObject &root = jsonBuffer.parseObject(cmd); const char *command = root["command"]; // "write" if (strcmp("write", command) == 0) { const char *text = root["text"]; // "1351824120" int x = root["x"]; // 13 int y = root["y"]; // 10 osd.print(text, x, y); return; } if (strcmp("clear", command) == 0) { osd.clearScreen(); return; } if (strcmp("offset", command) == 0) { int x = root["x"]; // 13 int y = root["y"]; // 10 osd.setDisplayOffsets(x, y); } } void processSerial() { static byte ndx = 0; char endMarker = '\n'; char rc; const byte numChars = 128; char receivedChars[numChars]; // an array to store the received data while (Serial.available() > 0) { rc = Serial.read(); if (rc != endMarker) { receivedChars[ndx] = rc; ndx++; if (ndx >= numChars) { ndx = numChars - 1; } } else { receivedChars[ndx] = '\0'; // terminate the string ndx = 0; handleRPC(receivedChars); } } }