Skip to content

Commit 8c2f3d8

Browse files
authored
Merge pull request #13 from tobozo/1.2.9
1.2.9
2 parents d1a8ad8 + 8904cbe commit 8c2f3d8

File tree

11 files changed

+659
-151
lines changed

11 files changed

+659
-151
lines changed

.github/workflows/ArduinoBuild.yml

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: ArduinoBuild
2+
3+
env:
4+
SKETCH_NAME: test.ino
5+
6+
on:
7+
push: # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request
8+
paths:
9+
- '**.ino'
10+
- '**.cpp'
11+
- '**.hpp'
12+
- '**.h'
13+
- '**.c'
14+
- '**ArduinoBuild.yml'
15+
pull_request:
16+
17+
jobs:
18+
19+
set_env:
20+
name: "Set matrix env vars"
21+
runs-on: ubuntu-latest
22+
env:
23+
esp32_board_url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
24+
esp8266_board_url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
25+
Seeeduino_board_url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
26+
rp2040_board_url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
27+
rp2040_cli_args: "--build-property compiler.cpp.extra_flags=-DSKIP_I2C_TEST"
28+
d1_mini_fbqn_extra: ":eesz=4M3M,xtal=80"
29+
30+
outputs:
31+
env: ${{steps.set-env.outputs.env}}
32+
steps:
33+
# export at output variables, flatten as JSON
34+
- id: set-env
35+
run: |
36+
content='${{ toJson(env) }}' # convert env vars to json
37+
content="${content//'%'/'%25'}" # escape percent entities
38+
content="${content//$'\n'/''}" # remove lf
39+
content="${content//$'\r'/''}" # remove cr
40+
echo "env=${content}" >> $GITHUB_OUTPUT
41+
42+
build:
43+
name: ${{matrix.board}}@${{matrix.platform-version}}
44+
runs-on: ubuntu-latest
45+
needs: set_env
46+
env: ${{fromJSON(needs.set_env.outputs.env)}}
47+
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
52+
board:
53+
# ESP32 devices for multidimensional matrix
54+
- esp32
55+
- esp32s2
56+
- esp32s3
57+
- esp32c3
58+
59+
platform-version:
60+
# ESP32 Core versions for multidimensional matrix
61+
- 1.0.6
62+
- 2.0.0
63+
- 2.0.1
64+
- 2.0.2
65+
- 2.0.3
66+
- 2.0.4
67+
- latest
68+
69+
include:
70+
# multidimensional matrix doesn't apply to these profiles, so they are explicitely populated
71+
72+
- { board: d1_mini, platform: esp8266, arch: esp8266, platform-version: 3.0.1, ... }
73+
- { board: d1_mini, platform: esp8266, arch: esp8266, platform-version: latest, ... }
74+
75+
- { board: seeed_wio_terminal, platform: Seeeduino, arch: samd, platform-version: 1.8.2, ... }
76+
- { board: seeed_wio_terminal, platform: Seeeduino, arch: samd, platform-version: latest, ... }
77+
78+
- { board: rpipico, platform: rp2040, arch: rp2040, platform-version: 2.3.3, ... }
79+
- { board: rpipico, platform: rp2040, arch: rp2040, platform-version: latest, ... }
80+
81+
# multidimensional matrix applies to these:
82+
- { board: esp32, platform: esp32, arch: esp32, ... }
83+
- { board: esp32s2, platform: esp32, arch: esp32, ... }
84+
- { board: esp32s3, platform: esp32, arch: esp32, ... }
85+
- { board: esp32c3, platform: esp32, arch: esp32, ... }
86+
87+
exclude:
88+
# multidimensional matrix excludes (no support or unstable):
89+
90+
- { board: esp32s2, platform-version: 1.0.6 }
91+
- { board: esp32s2, platform-version: 2.0.0 }
92+
93+
- { board: esp32s3, platform-version: 1.0.6 }
94+
- { board: esp32s3, platform-version: 2.0.0 }
95+
- { board: esp32s3, platform-version: 2.0.1 }
96+
- { board: esp32s3, platform-version: 2.0.2 }
97+
- { board: esp32s3, platform-version: 2.0.4 }
98+
99+
- { board: esp32c3, platform-version: 1.0.6 }
100+
- { board: esp32c3, platform-version: 2.0.0 }
101+
102+
103+
104+
105+
steps:
106+
- name: Checkout
107+
uses: actions/checkout@v3
108+
with:
109+
ref: ${{ github.event.pull_request.head.sha }}
110+
111+
- name: Prepare variables for arduino-test-compile
112+
run: |
113+
# prepare some associative arrays to receive matrix-specific env vars
114+
declare -A board_urls
115+
declare -A cli_args
116+
declare -A fbqn_extras
117+
118+
# assign package URLs (per platform)
119+
board_urls[esp32]=${{env.esp32_board_url}}
120+
board_urls[esp8266]=${{env.esp8266_board_url}}
121+
board_urls[Seeeduino]=${{env.Seeeduino_board_url}}
122+
board_urls[rp2040]=${{env.rp2040_board_url}}
123+
124+
# assign optional cli args (per platform)
125+
cli_args[rp2040]="${{env.rp2040_cli_args}}"
126+
127+
# assign optional extra FQBN info (per board)
128+
fbqn_extras[d1_mini]="${{env.d1_mini_fbqn_extra}}"
129+
130+
# collect the index names that will be used to populate the associative array
131+
board_name=${{matrix.board}}
132+
platform_name=${{matrix.platform}}
133+
134+
# populate values for the next step
135+
arduino_platform_url=${board_urls[$platform_name]}
136+
arduino_cli_args=${cli_args[$platform_name]}
137+
arduino_board_fqbn=${{matrix.platform}}:${{matrix.arch}}:${{matrix.board}}${fbqn_extras[$board_name]}
138+
arduino_platform=${{matrix.platform}}:${{matrix.arch}}@${{matrix.platform-version}}
139+
140+
# export to env
141+
echo "ARDUINO_PLATFORM=$arduino_platform" >> $GITHUB_ENV
142+
echo "ARDUINO_PLATFORM_URL=$arduino_platform_url" >> $GITHUB_ENV
143+
echo "ARDUINO_CLI_ARGS=$arduino_cli_args" >> $GITHUB_ENV
144+
echo "ARDUINO_BOARD_FQBN=$arduino_board_fqbn" >> $GITHUB_ENV
145+
146+
147+
- name: Compile example
148+
uses: ArminJo/arduino-test-compile@master
149+
with:
150+
arduino-board-fqbn: ${{env.ARDUINO_BOARD_FQBN}}
151+
arduino-platform: ${{env.ARDUINO_PLATFORM}}
152+
platform-url: ${{env.ARDUINO_PLATFORM_URL}}
153+
required-libraries: ArduinoJson
154+
extra-arduino-cli-args: ${{env.ARDUINO_CLI_ARGS}}
155+
#build-properties: ${{ toJson(matrix.build-properties) }}
156+
sketch-names: ${{ env.SKETCH_NAME }}
157+
#sketches-exclude: ${{ matrix.sketches-exclude }}
158+
159+

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
lint:
2323
runs-on: ubuntu-latest
2424
steps:
25-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v3
2626
- uses: arduino/arduino-lint-action@v1
2727
with:
2828
project-type: library

ReadMe.md

+70-50
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,34 @@ or
4949
YAML is a superset of JSON, so native conversion from/to JSON is possible without any additional JSON library.
5050

5151
```cpp
52-
// JSON <=> YAML stream to stream conversion (both ways!), accepts valid JSON or YAML as the input
53-
// Available values for output format:
54-
// YAMLParser::OUTPUT_YAML
55-
// YAMLParser::OUTPUT_JSON
56-
// YAMLParser::OUTPUT_JSON_PRETTY
57-
size_t serializeYml( Stream &source, Stream &destination, OutputFormat_t format );
52+
// JSON <=> YAML stream to stream conversion (both ways!).
53+
// Accepts valid JSON or YAML as the input.
54+
// Available values for output format:
55+
// YAMLParser::OUTPUT_YAML
56+
// YAMLParser::OUTPUT_JSON
57+
// YAMLParser::OUTPUT_JSON_PRETTY
58+
size_t serializeYml( Stream &source, Stream &destination, OutputFormat_t format );
5859

5960
```
6061
6162
6263
**Convert YAML to JSON**
6364
```cpp
65+
String yaml_str = "hello: world\nboolean: true\nfloat: 1.2345";
66+
StringStream yaml_stream( yaml_str );
6467
65-
String yaml_str = "hello: world\nboolean: true\nfloat: 1.2345";
66-
StringStream yaml_stream( yaml_str );
67-
68-
serializeYml( yaml_stream, Serial, YAMLParser::OUTPUT_JSON_PRETTY );
68+
serializeYml( yaml_stream, Serial, YAMLParser::OUTPUT_JSON_PRETTY );
6969
7070
```
7171

7272

7373

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

77-
String json_str = "{\"hello\": \"world\", \"boolean\": true, \"float\":1.2345}";
78-
StringStream json_stream( json_str );
79-
80-
serializeYml( json_stream, Serial, YAMLParser::OUTPUT_YAML );
79+
serializeYml( json_stream, Serial, YAMLParser::OUTPUT_YAML );
8180

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

121120
## ArduinoJson bindings
122121

123-
The support is implicitely enabled on most platforms.
122+
See the [motivational post](https://github.com/bblanchon/ArduinoJson/issues/1808) for this implementation.
123+
124+
ArduinoJson support is implicitely enabled on most platforms except for ESP32 where dependencies can be detected.
124125

125126

126127
```cpp
127-
#include <ArduinoJson.h> // ESP32 plaforms must include this before ArduinoYaml or functions will be disabled
128-
#include <ArduinoYaml.h>
128+
// ESP32 plaforms must include ArduinoJson before ArduinoYaml or functions will be disabled
129+
#include <ArduinoJson.h>
130+
#include <ArduinoYaml.h>
129131
```
130132

131133
Enabling support will expose the following functions:
132134

133135
```cpp
134-
// ArduinoJSON object to YAML string
135-
size_t serializeYml( JsonVariant src_obj, String &dest_string );
136-
// ArduinoJSON object to YAML stream
137-
size_t serializeYml( JsonVariant src_obj, Stream &dest_stream );
138-
// Deserialize YAML string to ArduinoJSON object
139-
DeserializationError deserializeYml( JsonObject &dest_obj, const char* src_yaml_str );
140-
// Deserialize YAML stream to ArduinoJSON object
141-
DeserializationError deserializeYml( JsonObject &dest_obj, Stream &src_stream );
142-
// Deserialize YAML string to ArduinoJSON document
143-
DeserializationError deserializeYml( JsonDocument &dest_doc, Stream &src_stream );
144-
// Deserialize YAML string to ArduinoJSON document
145-
DeserializationError deserializeYml( JsonDocument &dest_doc, const char *src_yaml_str) ;
136+
// ArduinoJSON object to YAML string
137+
size_t serializeYml( JsonVariant src_obj, String &dest_string );
138+
// ArduinoJSON object to YAML stream
139+
size_t serializeYml( JsonVariant src_obj, Stream &dest_stream );
140+
// Deserialize YAML string to ArduinoJSON object
141+
DeserializationError deserializeYml( JsonObject &dest_obj, const char* src_yaml_str );
142+
// Deserialize YAML stream to ArduinoJSON object
143+
DeserializationError deserializeYml( JsonObject &dest_obj, Stream &src_stream );
144+
// Deserialize YAML string to ArduinoJSON document
145+
DeserializationError deserializeYml( JsonDocument &dest_doc, Stream &src_stream );
146+
// Deserialize YAML string to ArduinoJSON document
147+
DeserializationError deserializeYml( JsonDocument &dest_doc, const char *src_yaml_str) ;
146148

147149
```
148150
149151
----------------------------
150152
151153
## cJSON bindinds
152154
153-
The support is implicitely enabled on most platforms and will use the bundled cJSON version.
154-
ESP32 will use the built-in version.
155+
cJSON support is implicitely enabled on most platforms, and will use the bundled cJSON version unless ESP32 platform is detected.
156+
ESP32 will use the built-in cJSON version from esp-idf instead of the YAMLDuino bundled version.
155157
156158
157-
⚠️ both versions of cJSON have a memory leak with floats, the leak happens only once though, and
159+
⚠️ Both versions of cJSON have a memory leak with floats, the leak happens only once though, and
158160
may be avoided by quoting the float, which won't affect yaml output.
159161
160162
161163
Enabling support will expose the following functions:
162164
163165
```cpp
164166
165-
// cJSON object to YAML string
166-
size_t serializeYml( cJSON* src_obj, String &dest_string );
167-
// cJSON object to YAML stream
168-
size_t serializeYml( cJSON* src_obj, Stream &dest_stream );
169-
// YAML string to cJSON object
170-
int deserializeYml( cJSON* dest_obj, const char* src_yaml_str );
171-
// YAML stream to cJSON object
172-
int deserializeYml( cJSON* dest_obj, Stream &src_stream );
167+
// cJSON object to YAML string
168+
size_t serializeYml( cJSON* src_obj, String &dest_string );
169+
// cJSON object to YAML stream
170+
size_t serializeYml( cJSON* src_obj, Stream &dest_stream );
171+
// YAML string to cJSON object
172+
int deserializeYml( cJSON* dest_obj, const char* src_yaml_str );
173+
// YAML stream to cJSON object
174+
int deserializeYml( cJSON* dest_obj, Stream &src_stream );
173175
174176
```
175177

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

184186
```cpp
185187

186-
String my_json = "{\"blah\":true}";
188+
String my_json = "{\"blah\":true}";
189+
StringStream json_input_stream(my_json);
187190

188-
StringStream json_input_stream(my_json);
189-
190-
String my_output;
191-
StringStream output_stream(my_output);
191+
String my_output;
192+
StringStream output_stream(my_output);
192193

193194
```
194195
@@ -224,16 +225,16 @@ JSON and YAML indentation levels can be customized:
224225

225226

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

230231
```
231232
232233
233234
Set custom JSON indentation and folding depth:
234235
235236
```cpp
236-
// two spaces per indentation level, unfold up to 8 nesting levels
237+
// this set two spaces per indentation level, unfolds up to 8 nesting levels
237238
YAMLParser::setJSONIndent(" ", 8 ); // lame fact: folds on objects, not on arrays
238239
239240
```
@@ -258,7 +259,7 @@ The debug level can be changed at runtime:
258259
259260
260261
```cpp
261-
void YAML::setLogLevel( LogLevel_t level );
262+
void YAML::setLogLevel( LogLevel_t level );
262263
```
263264

264265
Set library debug level:
@@ -275,6 +276,23 @@ Set library debug level:
275276
YAMLParser::setLogLevel( YAML::LogLevelDebug );
276277
```
277278
279+
----------------------------
280+
281+
282+
## Support the Project
283+
284+
There are a few things you can do to support the project:
285+
286+
- Star 🌟 this [repository](https://github.com/tobozo/YAMLDuino) and/or [follow me](https://github.com/tobozo/) on GitHub
287+
- Share and upvote on sites like Twitter, Reddit, and Hacker News
288+
- [Report](https://github.com/tobozo/YAMLDuino/issues) any bugs, glitches, or errors that you find
289+
290+
291+
These things motivate me to to keep sharing what I build, and they provide
292+
validation that my work is appreciated! They also help me improve the
293+
project. Thanks in advance!
294+
295+
278296
----------------------------
279297
280298
## Credits and special thanks to:
@@ -284,6 +302,8 @@ YAMLParser::setLogLevel( YAML::LogLevelDebug );
284302
- [@bblanchon](https://github.com/bblanchon)
285303
- [@vikman90](https://github.com/vikman90/yaml2json)
286304
305+
306+
287307
## Additional resources:
288308
289309
- ArduinoJson : https://github.com/bblanchon/ArduinoJson

0 commit comments

Comments
 (0)