diff --git a/.drone.yml b/.drone.yml index bf7203a..981614c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,6 +7,7 @@ steps: commands: - pip install platformio - pio run + - pio check --skip-packages - name: release image: plugins/gitea-release settings: diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 272828b..0f0d740 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,7 +1,7 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} \ No newline at end of file +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/include/config.h b/include/config.h index 78413b6..3989213 100644 --- a/include/config.h +++ b/include/config.h @@ -10,11 +10,11 @@ #define VERSION_BUILD 1 -#define VERSION_STRING STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_BUILD) -#define VERSION_DATE __DATE__ +#define VERSION_STRING STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." STR(VERSION_BUILD) +#define VERSION_DATE __DATE__ -#define BAUDRATE 115200 -#define DISP_OFFSET_X 49 -#define DISP_OFFSET_Y 27 +#define BAUDRATE 115200 +#define DISP_OFFSET_X 49 +#define DISP_OFFSET_Y 27 #endif /* CONFIG_H */ diff --git a/lib/CommandHandler/CommandHandler.cpp b/lib/CommandHandler/CommandHandler.cpp index ff4b08f..02f6e54 100644 --- a/lib/CommandHandler/CommandHandler.cpp +++ b/lib/CommandHandler/CommandHandler.cpp @@ -8,7 +8,7 @@ CommandHandler::CommandHandler(DisplayProxy *display) this->display = display; } -bool CommandHandler::parse(char *cmd) +bool CommandHandler::parse(const char *cmd) { Serial.print("Handling: "); Serial.println(cmd); diff --git a/lib/CommandHandler/CommandHandler.h b/lib/CommandHandler/CommandHandler.h index 6a80813..c5d6ab4 100644 --- a/lib/CommandHandler/CommandHandler.h +++ b/lib/CommandHandler/CommandHandler.h @@ -5,8 +5,8 @@ class CommandHandler { public: - CommandHandler(DisplayProxy *display); - bool parse(char *cmd); + explicit CommandHandler(DisplayProxy *display); + bool parse(const char *cmd); private: void debugWrite(int x, int y, const char *text); DisplayProxy *display; diff --git a/lib/DisplayProxy/DisplayProxyMAX7456.cpp b/lib/DisplayProxy/DisplayProxyMAX7456.cpp index a7ee5fd..4d869e3 100644 --- a/lib/DisplayProxy/DisplayProxyMAX7456.cpp +++ b/lib/DisplayProxy/DisplayProxyMAX7456.cpp @@ -3,22 +3,54 @@ DisplayProxyMAX7456::DisplayProxyMAX7456(Max7456 *osd) { this->osd = osd; + this->osd->init(6); + clear(); + this->osd->setBlinkParams(_8fields, _BT_3BT); + + externalVideo(false); + onScreenDisplay(true); } +/** + * Write a text string to the display at the given position + * @param x Position along the X axis + * @param y Position along the Y axis + * @param text The string to print + * @return Success or false + */ bool DisplayProxyMAX7456::write(int x, int y, const char *text) { this->osd->print(text, x, y); return true; } +/** + * Clear the entire screen + */ bool DisplayProxyMAX7456::clear() { this->osd->clearScreen(); return true; } +/** + * Adjust the display offset. + * Since the signal is analog the characters might be rendered outside the display area + */ bool DisplayProxyMAX7456::setOffset(int x, int y) { this->osd->setDisplayOffsets(x, y); return true; +} + +bool DisplayProxyMAX7456::externalVideo(bool enabled) +{ + this->osd->activateExternalVideo(enabled); + return true; +} + +bool DisplayProxyMAX7456::onScreenDisplay(bool enabled) +{ + this->osd->activateOSD(enabled); + return true; } \ No newline at end of file diff --git a/lib/DisplayProxy/DisplayProxyMAX7456.h b/lib/DisplayProxy/DisplayProxyMAX7456.h index e56abf8..44c3bff 100644 --- a/lib/DisplayProxy/DisplayProxyMAX7456.h +++ b/lib/DisplayProxy/DisplayProxyMAX7456.h @@ -7,11 +7,14 @@ class DisplayProxyMAX7456 : public DisplayProxy { public: - DisplayProxyMAX7456(Max7456 *osd); + explicit DisplayProxyMAX7456(Max7456 *osd); + + bool write(int x, int y, const char *text) override; + bool clear() override; + bool setOffset(int x, int y) override; + bool externalVideo(bool enabled); + bool onScreenDisplay(bool enabled); - bool write(int x, int y, const char *text); - bool clear() ; - bool setOffset(int x, int y); private: Max7456 *osd; }; diff --git a/src/main.cpp b/src/main.cpp index b4cef01..6eb5c53 100644 --- a/src/main.cpp +++ b/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()); + } } \ No newline at end of file