Streamline to other arduino projects, upgrade ArduinoJson
This commit is contained in:
		
							
								
								
									
										19
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
 | 
			
		||||
#include "Arduino.h"
 | 
			
		||||
#include <SPI.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
@@ -6,6 +6,77 @@
 | 
			
		||||
#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;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
  Serial.begin(BAUDRATE);
 | 
			
		||||
@@ -39,67 +110,3 @@ 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);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user