Modernizing code. Bit more OO design than previously.
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
61
src/main.cpp
61
src/main.cpp
@ -5,40 +5,10 @@
|
||||
#include "CommandHandler.h"
|
||||
#include "DisplayProxyMAX7456.h"
|
||||
#include "max7456.h"
|
||||
|
||||
Max7456 osd;
|
||||
DisplayProxyMAX7456 proxy(&osd);
|
||||
CommandHandler cmd_handler(&proxy);
|
||||
|
||||
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;
|
||||
cmd_handler.parse(receivedChars);
|
||||
}
|
||||
}
|
||||
}
|
||||
DisplayProxyMAX7456 display(&osd);
|
||||
CommandHandler cmd_handler(&display);
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -51,25 +21,24 @@ void setup()
|
||||
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);
|
||||
display.setOffset(DISP_OFFSET_X, DISP_OFFSET_Y);
|
||||
|
||||
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);
|
||||
display.write(0, 0, "==========================");
|
||||
display.write(0, 1, "Firmware: " PROJECT_NAME);
|
||||
display.write(0, 2, "Version: " VERSION_STRING);
|
||||
display.write(0, 3, "Built: " __DATE__ ", " __TIME__);
|
||||
display.write(0, 4, "==========================");
|
||||
|
||||
delay(3000);
|
||||
osd.clearScreen();
|
||||
display.clear();
|
||||
Serial.println("Ready!");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
processSerial();
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
String input = Serial.readStringUntil('\n');
|
||||
cmd_handler.parse(input.c_str());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user