From 96fd2967b38f318cb83080d9a005bb3a26db72bd Mon Sep 17 00:00:00 2001 From: Jens Christian True Date: Wed, 4 Sep 2019 13:00:53 +0200 Subject: [PATCH] Streamline to other arduino projects, upgrade ArduinoJson --- .drone.yml | 19 +++++++ platformio.ini | 2 +- src/{HelloWorld.ino => main.cpp} | 95 +++++++++++++++++--------------- 3 files changed, 71 insertions(+), 45 deletions(-) create mode 100644 .drone.yml rename src/{HelloWorld.ino => main.cpp} (79%) diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..4ad1afd --- /dev/null +++ b/.drone.yml @@ -0,0 +1,19 @@ +kind: pipeline +name: default + +steps: +- name: build + image: python:3 + commands: + - pip install platformio + - pio run +- name: release + image: plugins/gitea-release + settings: + api_key: a7f3afc9f77e721951e48b4af66d7565700b7a2e + base_url: https://code.jcktrue.dk + files: + - .pio/build/max7456board/firmware.hex + - .pio/build/max7456board/firmware.elf + when: + event: tag diff --git a/platformio.ini b/platformio.ini index 9fac8c6..4c06f70 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,7 +8,7 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:pro16MHzatmega328] +[env:max7456board] platform = atmelavr board = pro16MHzatmega328 framework = arduino diff --git a/src/HelloWorld.ino b/src/main.cpp similarity index 79% rename from src/HelloWorld.ino rename to src/main.cpp index c8b1f72..ac83450 100644 --- a/src/HelloWorld.ino +++ b/src/main.cpp @@ -1,4 +1,4 @@ - +#include "Arduino.h" #include #include "config.h" @@ -6,55 +6,27 @@ #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); + StaticJsonDocument<200> doc; + DeserializationError error = deserializeJson(doc, cmd); - JsonObject &root = jsonBuffer.parseObject(cmd); + // Test if parsing succeeds. + if (error) + { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.c_str()); + return; + } - const char *command = root["command"]; // "write" + const char *command = doc["command"]; // "write" if (strcmp("write", command) == 0) { - const char *text = root["text"]; // "1351824120" - int x = root["x"]; // 13 - int y = root["y"]; // 10 + const char *text = doc["text"]; // "1351824120" + int x = doc["x"]; // 13 + int y = doc["y"]; // 10 osd.print(text, x, y); return; } @@ -67,9 +39,10 @@ void handleRPC(char *cmd) if (strcmp("offset", command) == 0) { - int x = root["x"]; // 13 - int y = root["y"]; // 10 + int x = doc["x"]; // 13 + int y = doc["y"]; // 10 osd.setDisplayOffsets(x, y); + return; } } @@ -102,4 +75,38 @@ void processSerial() handleRPC(receivedChars); } } +} + +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(); } \ No newline at end of file