Skip to content

Commit

Permalink
Merge pull request #13 from tobozo/1.2.9
Browse files Browse the repository at this point in the history
1.2.9
  • Loading branch information
tobozo authored Oct 26, 2022
2 parents d1a8ad8 + 8904cbe commit 8c2f3d8
Show file tree
Hide file tree
Showing 11 changed files with 659 additions and 151 deletions.
159 changes: 159 additions & 0 deletions .github/workflows/ArduinoBuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: ArduinoBuild

env:
SKETCH_NAME: test.ino

on:
push: # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request
paths:
- '**.ino'
- '**.cpp'
- '**.hpp'
- '**.h'
- '**.c'
- '**ArduinoBuild.yml'
pull_request:

jobs:

set_env:
name: "Set matrix env vars"
runs-on: ubuntu-latest
env:
esp32_board_url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
esp8266_board_url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
Seeeduino_board_url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
rp2040_board_url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
rp2040_cli_args: "--build-property compiler.cpp.extra_flags=-DSKIP_I2C_TEST"
d1_mini_fbqn_extra: ":eesz=4M3M,xtal=80"

outputs:
env: ${{steps.set-env.outputs.env}}
steps:
# export at output variables, flatten as JSON
- id: set-env
run: |
content='${{ toJson(env) }}' # convert env vars to json
content="${content//'%'/'%25'}" # escape percent entities
content="${content//$'\n'/''}" # remove lf
content="${content//$'\r'/''}" # remove cr
echo "env=${content}" >> $GITHUB_OUTPUT
build:
name: ${{matrix.board}}@${{matrix.platform-version}}
runs-on: ubuntu-latest
needs: set_env
env: ${{fromJSON(needs.set_env.outputs.env)}}

strategy:
fail-fast: false
matrix:

board:
# ESP32 devices for multidimensional matrix
- esp32
- esp32s2
- esp32s3
- esp32c3

platform-version:
# ESP32 Core versions for multidimensional matrix
- 1.0.6
- 2.0.0
- 2.0.1
- 2.0.2
- 2.0.3
- 2.0.4
- latest

include:
# multidimensional matrix doesn't apply to these profiles, so they are explicitely populated

- { board: d1_mini, platform: esp8266, arch: esp8266, platform-version: 3.0.1, ... }
- { board: d1_mini, platform: esp8266, arch: esp8266, platform-version: latest, ... }

- { board: seeed_wio_terminal, platform: Seeeduino, arch: samd, platform-version: 1.8.2, ... }
- { board: seeed_wio_terminal, platform: Seeeduino, arch: samd, platform-version: latest, ... }

- { board: rpipico, platform: rp2040, arch: rp2040, platform-version: 2.3.3, ... }
- { board: rpipico, platform: rp2040, arch: rp2040, platform-version: latest, ... }

# multidimensional matrix applies to these:
- { board: esp32, platform: esp32, arch: esp32, ... }
- { board: esp32s2, platform: esp32, arch: esp32, ... }
- { board: esp32s3, platform: esp32, arch: esp32, ... }
- { board: esp32c3, platform: esp32, arch: esp32, ... }

exclude:
# multidimensional matrix excludes (no support or unstable):

- { board: esp32s2, platform-version: 1.0.6 }
- { board: esp32s2, platform-version: 2.0.0 }

- { board: esp32s3, platform-version: 1.0.6 }
- { board: esp32s3, platform-version: 2.0.0 }
- { board: esp32s3, platform-version: 2.0.1 }
- { board: esp32s3, platform-version: 2.0.2 }
- { board: esp32s3, platform-version: 2.0.4 }

- { board: esp32c3, platform-version: 1.0.6 }
- { board: esp32c3, platform-version: 2.0.0 }




steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Prepare variables for arduino-test-compile
run: |
# prepare some associative arrays to receive matrix-specific env vars
declare -A board_urls
declare -A cli_args
declare -A fbqn_extras
# assign package URLs (per platform)
board_urls[esp32]=${{env.esp32_board_url}}
board_urls[esp8266]=${{env.esp8266_board_url}}
board_urls[Seeeduino]=${{env.Seeeduino_board_url}}
board_urls[rp2040]=${{env.rp2040_board_url}}
# assign optional cli args (per platform)
cli_args[rp2040]="${{env.rp2040_cli_args}}"
# assign optional extra FQBN info (per board)
fbqn_extras[d1_mini]="${{env.d1_mini_fbqn_extra}}"
# collect the index names that will be used to populate the associative array
board_name=${{matrix.board}}
platform_name=${{matrix.platform}}
# populate values for the next step
arduino_platform_url=${board_urls[$platform_name]}
arduino_cli_args=${cli_args[$platform_name]}
arduino_board_fqbn=${{matrix.platform}}:${{matrix.arch}}:${{matrix.board}}${fbqn_extras[$board_name]}
arduino_platform=${{matrix.platform}}:${{matrix.arch}}@${{matrix.platform-version}}
# export to env
echo "ARDUINO_PLATFORM=$arduino_platform" >> $GITHUB_ENV
echo "ARDUINO_PLATFORM_URL=$arduino_platform_url" >> $GITHUB_ENV
echo "ARDUINO_CLI_ARGS=$arduino_cli_args" >> $GITHUB_ENV
echo "ARDUINO_BOARD_FQBN=$arduino_board_fqbn" >> $GITHUB_ENV
- name: Compile example
uses: ArminJo/arduino-test-compile@master
with:
arduino-board-fqbn: ${{env.ARDUINO_BOARD_FQBN}}
arduino-platform: ${{env.ARDUINO_PLATFORM}}
platform-url: ${{env.ARDUINO_PLATFORM_URL}}
required-libraries: ArduinoJson
extra-arduino-cli-args: ${{env.ARDUINO_CLI_ARGS}}
#build-properties: ${{ toJson(matrix.build-properties) }}
sketch-names: ${{ env.SKETCH_NAME }}
#sketches-exclude: ${{ matrix.sketches-exclude }}


2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
project-type: library
Expand Down
120 changes: 70 additions & 50 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,34 @@ or
YAML is a superset of JSON, so native conversion from/to JSON is possible without any additional JSON library.

```cpp
// JSON <=> YAML stream to stream conversion (both ways!), accepts valid JSON or YAML as the input
// Available values for output format:
// YAMLParser::OUTPUT_YAML
// YAMLParser::OUTPUT_JSON
// YAMLParser::OUTPUT_JSON_PRETTY
size_t serializeYml( Stream &source, Stream &destination, OutputFormat_t format );
// JSON <=> YAML stream to stream conversion (both ways!).
// Accepts valid JSON or YAML as the input.
// Available values for output format:
// YAMLParser::OUTPUT_YAML
// YAMLParser::OUTPUT_JSON
// YAMLParser::OUTPUT_JSON_PRETTY
size_t serializeYml( Stream &source, Stream &destination, OutputFormat_t format );

```
**Convert YAML to JSON**
```cpp
String yaml_str = "hello: world\nboolean: true\nfloat: 1.2345";
StringStream yaml_stream( yaml_str );
String yaml_str = "hello: world\nboolean: true\nfloat: 1.2345";
StringStream yaml_stream( yaml_str );
serializeYml( yaml_stream, Serial, YAMLParser::OUTPUT_JSON_PRETTY );
serializeYml( yaml_stream, Serial, YAMLParser::OUTPUT_JSON_PRETTY );
```



**Convert JSON to YAML**
```cpp
String json_str = "{\"hello\": \"world\", \"boolean\": true, \"float\":1.2345}";
StringStream json_stream( json_str );

String json_str = "{\"hello\": \"world\", \"boolean\": true, \"float\":1.2345}";
StringStream json_stream( json_str );

serializeYml( json_stream, Serial, YAMLParser::OUTPUT_YAML );
serializeYml( json_stream, Serial, YAMLParser::OUTPUT_YAML );

```
Expand All @@ -102,7 +101,7 @@ So all ArduinoJson functions will be disabled unless `#include <ArduinoJson.h>`
On ESP8266/RP2040/SAMD platforms it is assumed that ArduinoJson is already available as a dependency.
In order to save flash space and/or memory, the defaults bindings can be disabled independently by setting one or all of the
In order to save flash space and/or memory, the default bindings can be disabled independently by setting one or all of the
following macros before including ArduinoYaml:
```cpp
Expand All @@ -120,56 +119,59 @@ Note to readers: should ArduinoJson and/or cJSON be implicitely loaded?

## ArduinoJson bindings

The support is implicitely enabled on most platforms.
See the [motivational post](https://github.com/bblanchon/ArduinoJson/issues/1808) for this implementation.

ArduinoJson support is implicitely enabled on most platforms except for ESP32 where dependencies can be detected.


```cpp
#include <ArduinoJson.h> // ESP32 plaforms must include this before ArduinoYaml or functions will be disabled
#include <ArduinoYaml.h>
// ESP32 plaforms must include ArduinoJson before ArduinoYaml or functions will be disabled
#include <ArduinoJson.h>
#include <ArduinoYaml.h>
```

Enabling support will expose the following functions:

```cpp
// ArduinoJSON object to YAML string
size_t serializeYml( JsonVariant src_obj, String &dest_string );
// ArduinoJSON object to YAML stream
size_t serializeYml( JsonVariant src_obj, Stream &dest_stream );
// Deserialize YAML string to ArduinoJSON object
DeserializationError deserializeYml( JsonObject &dest_obj, const char* src_yaml_str );
// Deserialize YAML stream to ArduinoJSON object
DeserializationError deserializeYml( JsonObject &dest_obj, Stream &src_stream );
// Deserialize YAML string to ArduinoJSON document
DeserializationError deserializeYml( JsonDocument &dest_doc, Stream &src_stream );
// Deserialize YAML string to ArduinoJSON document
DeserializationError deserializeYml( JsonDocument &dest_doc, const char *src_yaml_str) ;
// ArduinoJSON object to YAML string
size_t serializeYml( JsonVariant src_obj, String &dest_string );
// ArduinoJSON object to YAML stream
size_t serializeYml( JsonVariant src_obj, Stream &dest_stream );
// Deserialize YAML string to ArduinoJSON object
DeserializationError deserializeYml( JsonObject &dest_obj, const char* src_yaml_str );
// Deserialize YAML stream to ArduinoJSON object
DeserializationError deserializeYml( JsonObject &dest_obj, Stream &src_stream );
// Deserialize YAML string to ArduinoJSON document
DeserializationError deserializeYml( JsonDocument &dest_doc, Stream &src_stream );
// Deserialize YAML string to ArduinoJSON document
DeserializationError deserializeYml( JsonDocument &dest_doc, const char *src_yaml_str) ;

```
----------------------------
## cJSON bindinds
The support is implicitely enabled on most platforms and will use the bundled cJSON version.
ESP32 will use the built-in version.
cJSON support is implicitely enabled on most platforms, and will use the bundled cJSON version unless ESP32 platform is detected.
ESP32 will use the built-in cJSON version from esp-idf instead of the YAMLDuino bundled version.
⚠️ both versions of cJSON have a memory leak with floats, the leak happens only once though, and
⚠️ Both versions of cJSON have a memory leak with floats, the leak happens only once though, and
may be avoided by quoting the float, which won't affect yaml output.
Enabling support will expose the following functions:
```cpp
// cJSON object to YAML string
size_t serializeYml( cJSON* src_obj, String &dest_string );
// cJSON object to YAML stream
size_t serializeYml( cJSON* src_obj, Stream &dest_stream );
// YAML string to cJSON object
int deserializeYml( cJSON* dest_obj, const char* src_yaml_str );
// YAML stream to cJSON object
int deserializeYml( cJSON* dest_obj, Stream &src_stream );
// cJSON object to YAML string
size_t serializeYml( cJSON* src_obj, String &dest_string );
// cJSON object to YAML stream
size_t serializeYml( cJSON* src_obj, Stream &dest_stream );
// YAML string to cJSON object
int deserializeYml( cJSON* dest_obj, const char* src_yaml_str );
// YAML stream to cJSON object
int deserializeYml( cJSON* dest_obj, Stream &src_stream );
```

Expand All @@ -183,12 +185,11 @@ The `StringStream` class is provided with this library as a helper.

```cpp

String my_json = "{\"blah\":true}";
String my_json = "{\"blah\":true}";
StringStream json_input_stream(my_json);

StringStream json_input_stream(my_json);

String my_output;
StringStream output_stream(my_output);
String my_output;
StringStream output_stream(my_output);

```
Expand Down Expand Up @@ -224,16 +225,16 @@ JSON and YAML indentation levels can be customized:


```cpp
void YAML::setYAMLIndent( int spaces_per_indent=2 ); // min=2, max=16
void YAML::setJSONIndent( const char* spaces_or_tabs=JSON_SCALAR_TAB, int folding_depth=JSON_FOLDING_DEPTH );
void YAML::setYAMLIndent( int spaces_per_indent=2 ); // min=2, max=16
void YAML::setJSONIndent( const char* spaces_or_tabs="\t", int folding_depth=4 );

```
Set custom JSON indentation and folding depth:
```cpp
// two spaces per indentation level, unfold up to 8 nesting levels
// this set two spaces per indentation level, unfolds up to 8 nesting levels
YAMLParser::setJSONIndent(" ", 8 ); // lame fact: folds on objects, not on arrays
```
Expand All @@ -258,7 +259,7 @@ The debug level can be changed at runtime:
```cpp
void YAML::setLogLevel( LogLevel_t level );
void YAML::setLogLevel( LogLevel_t level );
```

Set library debug level:
Expand All @@ -275,6 +276,23 @@ Set library debug level:
YAMLParser::setLogLevel( YAML::LogLevelDebug );
```
----------------------------
## Support the Project
There are a few things you can do to support the project:
- Star 🌟 this [repository](https://github.com/tobozo/YAMLDuino) and/or [follow me](https://github.com/tobozo/) on GitHub
- Share and upvote on sites like Twitter, Reddit, and Hacker News
- [Report](https://github.com/tobozo/YAMLDuino/issues) any bugs, glitches, or errors that you find
These things motivate me to to keep sharing what I build, and they provide
validation that my work is appreciated! They also help me improve the
project. Thanks in advance!
----------------------------
## Credits and special thanks to:
Expand All @@ -284,6 +302,8 @@ YAMLParser::setLogLevel( YAML::LogLevelDebug );
- [@bblanchon](https://github.com/bblanchon)
- [@vikman90](https://github.com/vikman90/yaml2json)
## Additional resources:
- ArduinoJson : https://github.com/bblanchon/ArduinoJson
Expand Down
Loading

0 comments on commit 8c2f3d8

Please sign in to comment.